[System]
You are a security patch backporting assistant for SUSE/openSUSE.

Given a CVE description and an upstream fix, adapt the patch to work with
the target SUSE package version. Output the backported patch in unified
diff format. If the upstream fix applies directly, output it unchanged.

[User]
## CVE: CVE-2020-14356, CVE-2020-14331, CVE-2020-16166, CVE-2020-10135, CVE-2020-0305, CVE-2020-15780, CVE-2020-10781

This patch fix a problem that crash cannot open a dumpfile which is

## Package
crash

## Files to modify
- b/symbols.c

## Target Source Code

### symbols.c

#### symname_hash_install() [lines 1131-1160]
```c
 *  Install a single static kernel symbol into the symname_hash.
 */
static void
symname_hash_install(struct syment *spn)
{
	struct syment *sp;
        int index;

        index = SYMNAME_HASH_INDEX(spn->name);
	spn->cnt = 1;

        if ((sp = st->symname_hash[index]) == NULL)
        	st->symname_hash[index] = spn;
	else {
		while (sp) {
	        	if (STREQ(sp->name, spn->name)) {
	                	sp->cnt++;
	                	spn->cnt++;
	        	}
			if (sp->name_hash_next)
				sp = sp->name_hash_next;
			else {
				sp->name_hash_next = spn;
				break;
			}
		}
	}
}

/*
```

### Type definitions

```c
/* from defs.h */
struct syment {
        ulong value;
        char *name;
	struct syment *val_hash_next;
	struct syment *name_hash_next;
	char type;
	unsigned char cnt;
	unsigned char flags;
	unsigned char pad2;
};
```

## Upstream Fix
```diff
This patch fix a problem that crash cannot open a dumpfile which is
captured by sadump in KASLR enabled kernel.

When KASLR feature is enabled, a kernel is placed on the memory randomly
and therefore crash cannot open a dumpfile captured by sadump because
addresses of kernel symbols in System.map or vmlinux are different from
actual addresses.

To solve this problem, we need to calculate kaslr offset(the difference
between original symbol address and actual address) and phys_base, and
adjust symbol table of crash. In the case of dumpfile of kdump, these
information is included in the header, but dumpfile of sadump does not
have such a information.

This patch calculate kaslr offset and phys_base to solve this problem.
Please see the comment in the calc_kaslr_offset() for the detail idea.
The basic idea is getting register (IDTR and CR3) from dump header, and
calculate kaslr_offset/phys_base using them.

Signed-off-by: Takao Indoh <indou.takao@jp.fujitsu.com>
---
 symbols.c |    3 +++
 1 file changed, 3 insertions(+)

Index: b/symbols.c
===================================================================
--- a/symbols.c
+++ b/symbols.c
@@ -1156,6 +1156,9 @@ symname_hash_install(struct syment *spn)
 			}
 		}
 	}
+
+	if (SADUMP_DUMPFILE())
+		kt->flags2 |= KASLR_CHECK;
 }

 /*

```

Generate a backported patch for the SUSE target version.

[Assistant]
This patch fix a problem that crash cannot open a dumpfile which is
captured by sadump in KASLR enabled kernel.

When KASLR feature is enabled, a kernel is placed on the memory randomly
and therefore crash cannot open a dumpfile captured by sadump because
addresses of kernel symbols in System.map or vmlinux are different from
actual addresses.

To solve this problem, we need to calculate kaslr offset(the difference
between original symbol address and actual address) and phys_base, and
adjust symbol table of crash. In the case of dumpfile of kdump, these
information is included in the header, but dumpfile of sadump does not
have such a information.

This patch calculate kaslr offset and phys_base to solve this problem.
Please see the comment in the calc_kaslr_offset() for the detail idea.
The basic idea is getting register (IDTR and CR3) from dump header, and
calculate kaslr_offset/phys_base using them.

Signed-off-by: Takao Indoh <indou.takao@jp.fujitsu.com>
---
 symbols.c |    3 +++
 1 file changed, 3 insertions(+)

Index: b/symbols.c
===================================================================
--- a/symbols.c
+++ b/symbols.c
@@ -1156,6 +1156,9 @@ symname_hash_install(struct syment *spn)
 			}
 		}
 	}
+
+	if (SADUMP_DUMPFILE())
+		kt->flags2 |= KASLR_CHECK;
 }

 /*


[System]
You are a security patch backporting assistant for SUSE/openSUSE.

Given a CVE description and an upstream fix, adapt the patch to work with
the target SUSE package version. Output the backported patch in unified
diff format. If the upstream fix applies directly, output it unchanged.

[User]
## CVE: CVE-2020-14356, CVE-2020-14331, CVE-2020-16166, CVE-2020-10135, CVE-2020-0305, CVE-2020-15780, CVE-2020-10781

From: Petr Tesarik <ptesarik@suse.cz>

## Package
crash

## Files to modify
- symbols.c

## Target Source Code

### symbols.c

#### symtab_init() [lines 161-255]
```c
 *  sorts, and stores, them in a static table for quick reference.
 */
void
symtab_init(void)
{
	char **matching;
  	long symcount;
  	void *minisyms;
  	unsigned int size;
	asymbol *sort_x;
	asymbol *sort_y;

  	if ((st->bfd = bfd_openr(pc->namelist, NULL)) == NULL)
		error(FATAL, "cannot open object file: %s\n", pc->namelist);

  	if (!bfd_check_format_matches(st->bfd, bfd_object, &matching))
		error(FATAL, "cannot determine object file format: %s\n",
			pc->namelist);
	/*
	 *  Check whether the namelist is a kerntypes file built by
	 *  dwarfextract, which places a magic number in e_version.
	 */
	if (file_elf_version(pc->namelist) == EV_DWARFEXTRACT)
		pc->flags |= KERNTYPES;

	if (pc->flags & SYSMAP) {
		bfd_map_over_sections(st->bfd, section_header_info,
			VERIFY_SECTIONS);
		if ((st->flags & (NO_SEC_LOAD|NO_SEC_CONTENTS)) ==
		    (NO_SEC_LOAD|NO_SEC_CONTENTS)) {
			error(INFO, "%s: no text and data contents\n",
				pc->namelist);
			error(FATAL, pc->flags & SYSMAP_ARG ?
				DEBUGINFO_ERROR_MESSAGE1 :
				DEBUGINFO_ERROR_MESSAGE2);
		}
		store_sysmap_symbols();
		return;
	} else if (LKCD_KERNTYPES())
		error(FATAL, "%s: use of kerntypes requires a system map\n",
			pc->namelist);

	/*
	 *  Pull a bait-and-switch on st->bfd if we've got a separate
         *  .gnu_debuglink file that matches the CRC. Not done for kerntypes.
	 */
	if (!(LKCD_KERNTYPES()) &&
	    !(bfd_get_file_flags(st->bfd) & HAS_SYMS)) {
		if (!check_gnu_debuglink(st->bfd))
			no_debugging_data(FATAL);
	}

	/*
	 *  Gather references to the kernel sections.
	 */
        if ((st->sections = (struct sec *)
             malloc(st->bfd->section_count * sizeof(struct sec *))) == NULL)
                error(FATAL, "symbol table section array malloc: %s\n",
                        strerror(errno));
	BZERO(st->sections, st->bfd->section_count * sizeof(struct sec *));
	st->first_section_start = st->last_section_end = 0;

	bfd_map_over_sections(st->bfd, section_header_info, KERNEL_SECTIONS);
	if ((st->flags & (NO_SEC_LOAD|NO_SEC_CONTENTS)) ==
	    (NO_SEC_LOAD|NO_SEC_CONTENTS)) {
		if (!pc->namelist_debug && !pc->debuginfo_file) {
			error(INFO, "%s: no text and data contents\n",
				pc->namelist);
			error(FATAL, DEBUGINFO_ERROR_MESSAGE2);
		}
	}

	symcount = bfd_read_minisymbols(st->bfd, FALSE, &minisyms, &size);

	if (symcount <= 0)
		no_debugging_data(FATAL);

	sort_x = bfd_make_empty_symbol(st->bfd);
	sort_y = bfd_make_empty_symbol(st->bfd);
	if (sort_x == NULL || sort_y == NULL)
		error(FATAL, "bfd_make_empty_symbol() failed\n");

	kaslr_init();

	gnu_qsort(st->bfd, minisyms, symcount, size, sort_x, sort_y);

	store_symbols(st->bfd, FALSE, minisyms, symcount, size);

	free(minisyms);

	symname_hash_init();
	symval_hash_init();
}

/*
```

#### check_gnu_debuglink() [lines 206-232]
```c
	 */
	if (!(LKCD_KERNTYPES()) &&
	    !(bfd_get_file_flags(st->bfd) & HAS_SYMS)) {
		if (!check_gnu_debuglink(st->bfd))
			no_debugging_data(FATAL);
	}

	/*
	 *  Gather references to the kernel sections.
	 */
        if ((st->sections = (struct sec *)
             malloc(st->bfd->section_count * sizeof(struct sec *))) == NULL)
                error(FATAL, "symbol table section array malloc: %s\n",
                        strerror(errno));
	BZERO(st->sections, st->bfd->section_count * sizeof(struct sec *));
	st->first_section_start = st->last_section_end = 0;

	bfd_map_over_sections(st->bfd, section_header_info, KERNEL_SECTIONS);
	if ((st->flags & (NO_SEC_LOAD|NO_SEC_CONTENTS)) ==
	    (NO_SEC_LOAD|NO_SEC_CONTENTS)) {
		if (!pc->namelist_debug && !pc->debuginfo_file) {
			error(INFO, "%s: no text and data contents\n",
				pc->namelist);
			error(FATAL, DEBUGINFO_ERROR_MESSAGE2);
		}
	}

```

## Upstream Fix
```diff
From: Petr Tesarik <ptesarik@suse.cz>
Subject: Search debuginfo files in the original directory
References: bnc#723639

If debuginfo is in a separate file and the kernel image is compressed,
then it should be found in the same directory as the original (compressed)
image, not in the directory with the uncompressed image (TMPDIR).

Signed-off-by: Petr Tesarik <ptesarik@suse.cz>

---
 symbols.c |   17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

Index: crash-7.2.7/symbols.c
===================================================================
--- crash-7.2.7.orig/symbols.c
+++ crash-7.2.7/symbols.c
@@ -203,9 +203,9 @@ symtab_init(void)
 	 *  Pull a bait-and-switch on st->bfd if we've got a separate
          *  .gnu_debuglink file that matches the CRC. Not done for kerntypes.
 	 */
-	if (!(LKCD_KERNTYPES()) &&
-	    !(bfd_get_file_flags(st->bfd) & HAS_SYMS)) {
-		if (!check_gnu_debuglink(st->bfd))
+	if (!(LKCD_KERNTYPES())) {
+		if (!check_gnu_debuglink(st->bfd) &&
+		    !(bfd_get_file_flags(st->bfd) & HAS_SYMS))
 			no_debugging_data(FATAL);
 	}

@@ -267,13 +267,16 @@ check_gnu_debuglink(bfd *bfd)
 	char *contents;
 	int crc_offset;
 	unsigned long crc32;
+	char *namelist;
 	char *dirname;
 	char *namelist_debug;
         char **matching;

+	namelist = pc->namelist_orig ? pc->namelist_orig : pc->namelist;
+
         sect = bfd_get_section_by_name(bfd, ".gnu_debuglink");
 	if (!sect) {
-		error(INFO, "%s: no .gnu_debuglink section\n", pc->namelist);
+		error(INFO, "%s: no .gnu_debuglink section\n", namelist);
 		return FALSE;
 	}

@@ -294,14 +297,14 @@ check_gnu_debuglink(bfd *bfd)
 			contents, crc32);

   	if ((pc->debuginfo_file = (char *)
-	    malloc(((strlen(pc->namelist) + strlen("/.debug/") +
+	    malloc(((strlen(namelist) + strlen("/.debug/") +
 	    + strlen(".debug") + strlen(" /usr/lib/debug/boot/ "))*10)
 	    + strlen(pc->namelist_debug ? pc->namelist_debug : " "))) == NULL)
 		error(FATAL, "debuginfo file name malloc: %s\n",
 			strerror(errno));

-	dirname = GETBUF(strlen(pc->namelist)+1);
-	strcpy(dirname, pc->namelist);
+	dirname = GETBUF(strlen(namelist)+1);
+	strcpy(dirname, namelist);

   	for (i = strlen(dirname)-1; i >= 0; i--)
     	{

```

Generate a backported patch for the SUSE target version.

[Assistant]
From: Petr Tesarik <ptesarik@suse.cz>
Subject: Search debuginfo files in the original directory
References: bnc#723639

If debuginfo is in a separate file and the kernel image is compressed,
then it should be found in the same directory as the original (compressed)
image, not in the directory with the uncompressed image (TMPDIR).

Signed-off-by: Petr Tesarik <ptesarik@suse.cz>

---
 symbols.c |   17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

Index: crash-7.2.7/symbols.c
===================================================================
--- crash-7.2.7.orig/symbols.c
+++ crash-7.2.7/symbols.c
@@ -203,9 +203,9 @@ symtab_init(void)
 	 *  Pull a bait-and-switch on st->bfd if we've got a separate
          *  .gnu_debuglink file that matches the CRC. Not done for kerntypes.
 	 */
-	if (!(LKCD_KERNTYPES()) &&
-	    !(bfd_get_file_flags(st->bfd) & HAS_SYMS)) {
-		if (!check_gnu_debuglink(st->bfd))
+	if (!(LKCD_KERNTYPES())) {
+		if (!check_gnu_debuglink(st->bfd) &&
+		    !(bfd_get_file_flags(st->bfd) & HAS_SYMS))
 			no_debugging_data(FATAL);
 	}

@@ -267,13 +267,16 @@ check_gnu_debuglink(bfd *bfd)
 	char *contents;
 	int crc_offset;
 	unsigned long crc32;
+	char *namelist;
 	char *dirname;
 	char *namelist_debug;
         char **matching;

+	namelist = pc->namelist_orig ? pc->namelist_orig : pc->namelist;
+
         sect = bfd_get_section_by_name(bfd, ".gnu_debuglink");
 	if (!sect) {
-		error(INFO, "%s: no .gnu_debuglink section\n", pc->namelist);
+		error(INFO, "%s: no .gnu_debuglink section\n", namelist);
 		return FALSE;
 	}

@@ -294,14 +297,14 @@ check_gnu_debuglink(bfd *bfd)
 			contents, crc32);

   	if ((pc->debuginfo_file = (char *)
-	    malloc(((strlen(pc->namelist) + strlen("/.debug/") +
+	    malloc(((strlen(namelist) + strlen("/.debug/") +
 	    + strlen(".debug") + strlen(" /usr/lib/debug/boot/ "))*10)
 	    + strlen(pc->namelist_debug ? pc->namelist_debug : " "))) == NULL)
 		error(FATAL, "debuginfo file name malloc: %s\n",
 			strerror(errno));

-	dirname = GETBUF(strlen(pc->namelist)+1);
-	strcpy(dirname, pc->namelist);
+	dirname = GETBUF(strlen(namelist)+1);
+	strcpy(dirname, namelist);

   	for (i = strlen(dirname)-1; i >= 0; i--)
     	{


[System]
You are a security patch backporting assistant for SUSE/openSUSE.

Given a CVE description and an upstream fix, adapt the patch to work with
the target SUSE package version. Output the backported patch in unified
diff format. If the upstream fix applies directly, output it unchanged.

[User]
## CVE: CVE-2020-14356, CVE-2020-14331, CVE-2020-16166, CVE-2020-10135, CVE-2020-0305, CVE-2020-15780, CVE-2020-10781

From: Luc Chouinard <lchouinard@lchouinard-desktop.englab.juniper.net>

## Package
crash

## Files to modify
- extensions/eppic/applications/crash/eppic.c

## Target Source Code

### eppic/applications/crash/eppic.c

#### _init() [lines 984-5]
```c

```

## Upstream Fix
```diff
From: Luc Chouinard <lchouinard@lchouinard-desktop.englab.juniper.net>
Date: Thu Jun 19 12:28:40 2014 -0700
Subject: Support for ARM64
References: FATE#320844
Patch-mainline: yes
Git-commit: 5391d3dd0e6710c22ec5801f99a6788a2e4b132a

Acked-by: Petr Tesarik <ptesarik@suse.com>

---
 extensions/eppic/applications/crash/eppic.c |    4 ++++
 1 file changed, 4 insertions(+)

--- a/extensions/eppic/applications/crash/eppic.c
+++ b/extensions/eppic/applications/crash/eppic.c
@@ -1033,10 +1033,14 @@ _init() /* Register the command set. */
 #ifdef PPC64
 #define EPPIC_ABI  ABI_PPC64
 #else
+#ifdef ARM64
+#define EPPIC_ABI  ABI_ARM64
+#else
 #error eppic: Unkown ABI
 #endif
 #endif
 #endif
+#endif
 #endif
 #endif
 #endif

```

Generate a backported patch for the SUSE target version.

[Assistant]
From: Luc Chouinard <lchouinard@lchouinard-desktop.englab.juniper.net>
Date: Thu Jun 19 12:28:40 2014 -0700
Subject: Support for ARM64
References: FATE#320844
Patch-mainline: yes
Git-commit: 5391d3dd0e6710c22ec5801f99a6788a2e4b132a

Acked-by: Petr Tesarik <ptesarik@suse.com>

---
 extensions/eppic/applications/crash/eppic.c |    4 ++++
 1 file changed, 4 insertions(+)

--- a/extensions/eppic/applications/crash/eppic.c
+++ b/extensions/eppic/applications/crash/eppic.c
@@ -1033,10 +1033,14 @@ _init() /* Register the command set. */
 #ifdef PPC64
 #define EPPIC_ABI  ABI_PPC64
 #else
+#ifdef ARM64
+#define EPPIC_ABI  ABI_ARM64
+#else
 #error eppic: Unkown ABI
 #endif
 #endif
 #endif
+#endif
 #endif
 #endif
 #endif


[System]
You are a security patch backporting assistant for SUSE/openSUSE.

Given a CVE description and an upstream fix, adapt the patch to work with
the target SUSE package version. Output the backported patch in unified
diff format. If the upstream fix applies directly, output it unchanged.

[User]
## CVE: CVE-2020-14356, CVE-2020-14331, CVE-2020-16166, CVE-2020-10135, CVE-2020-0305, CVE-2020-15780, CVE-2020-10781

From: David Mair <dmair@suse.com>

## Package
crash

## Files to modify
- memory.c

## Upstream Fix
```diff
From: David Mair <dmair@suse.com>
Date: 2017-05-25 10:27:21 -0600
Subject: Avoid printing a read error for a failed read that can be retried
References: bnc#1038839
Upstream: tbd

When reading a memory image fails it may not be an error if it is still
possible to switch image and retry the read. Fix the error message output
to only occur if no retries are intended.

---

Index: crash-7.2.8/memory.c
===================================================================
--- crash-7.2.8.orig/memory.c
+++ crash-7.2.8/memory.c
@@ -2320,8 +2320,6 @@ readmem(ulonglong addr, int memtype, voi
                         goto readmem_error;

 		case READ_ERROR:
-			if (PRINT_ERROR_MESSAGE)
-				error(INFO, READ_ERRMSG, memtype_string(memtype, 0), addr, type);
 			if ((pc->flags & DEVMEM) && (kt->flags & PRE_KERNEL_INIT) &&
 			    !(error_handle & NO_DEVMEM_SWITCH) && devmem_is_restricted() &&
 			    switch_to_proc_kcore()) {
@@ -2329,6 +2327,8 @@ readmem(ulonglong addr, int memtype, voi
 				return(readmem(addr, memtype, bufptr, size,
 					type, error_handle));
 			}
+			if (PRINT_ERROR_MESSAGE)
+				error(INFO, READ_ERRMSG, memtype_string(memtype, 0), addr, type);
 			goto readmem_error;

 		case PAGE_EXCLUDED:

```

Generate a backported patch for the SUSE target version.

[Assistant]
From: David Mair <dmair@suse.com>
Date: 2017-05-25 10:27:21 -0600
Subject: Avoid printing a read error for a failed read that can be retried
References: bnc#1038839
Upstream: tbd

When reading a memory image fails it may not be an error if it is still
possible to switch image and retry the read. Fix the error message output
to only occur if no retries are intended.

---

Index: crash-7.2.8/memory.c
===================================================================
--- crash-7.2.8.orig/memory.c
+++ crash-7.2.8/memory.c
@@ -2320,8 +2320,6 @@ readmem(ulonglong addr, int memtype, voi
                         goto readmem_error;

 		case READ_ERROR:
-			if (PRINT_ERROR_MESSAGE)
-				error(INFO, READ_ERRMSG, memtype_string(memtype, 0), addr, type);
 			if ((pc->flags & DEVMEM) && (kt->flags & PRE_KERNEL_INIT) &&
 			    !(error_handle & NO_DEVMEM_SWITCH) && devmem_is_restricted() &&
 			    switch_to_proc_kcore()) {
@@ -2329,6 +2327,8 @@ readmem(ulonglong addr, int memtype, voi
 				return(readmem(addr, memtype, bufptr, size,
 					type, error_handle));
 			}
+			if (PRINT_ERROR_MESSAGE)
+				error(INFO, READ_ERRMSG, memtype_string(memtype, 0), addr, type);
 			goto readmem_error;

 		case PAGE_EXCLUDED:


[System]
You are a security patch backporting assistant for SUSE/openSUSE.

Given a CVE description and an upstream fix, adapt the patch to work with
the target SUSE package version. Output the backported patch in unified
diff format. If the upstream fix applies directly, output it unchanged.

[User]
## CVE: CVE-2020-14356, CVE-2020-14331, CVE-2020-16166, CVE-2020-10135, CVE-2020-0305, CVE-2020-15780, CVE-2020-10781

Fix for reading compressed kdump dumpfiles from systems with

## Package
crash

## Files to modify
- diskdump.c

## Target Source Code

### diskdump.c

#### clean_diskdump_data() [lines 216-235]
```c
}

static void
clean_diskdump_data(void)
{
	int i;

	if (dd_list == NULL)
		return;

	for (i=1; i<num_dumpfiles; i++)
		free(dd_list[i]); /* NOTE: dd_list[0] is static dd */

	free(dd_list);
	dd_list = NULL;
	num_dumpfiles = 0;
	dd = &diskdump_data;
}

static inline int
```

#### region() [lines 645-752]
```c
				error(INFO, "diskdump: cannot lseek dump sub header\n");
				goto err;
			}
			if (read(dd->dfd, sub_header, block_size) < block_size) {
				error(INFO, "diskdump: cannot read dump sub header\n");
				goto err;
			}
		}
		dd->sub_header = sub_header;

		/* the 64bit max_mapnr only exists in sub-header of compressed
		 * kdump file, if it's not a compressed kdump file, we have to
		 * use the old 32bit max_mapnr in dumpfile header.
		 * max_mapnr may be truncated here.
		 */
		dd->max_mapnr = header->max_mapnr;
	} else if (KDUMP_CMPRS_VALID()) {
		if ((sub_header_kdump = malloc(block_size)) == NULL)
			error(FATAL, "compressed kdump: cannot malloc sub_header_kdump buffer\n");

		if (FLAT_FORMAT()) {
			if (!read_flattened_format(dd->dfd, offset, sub_header_kdump, block_size)) {
				error(INFO, "compressed kdump: cannot read dump sub header\n");
				goto err;
			}
		} else {
			if (lseek(dd->dfd, offset, SEEK_SET) == failed) {
				error(INFO, "compressed kdump: cannot lseek dump sub header\n");
				goto err;
			}
			if (read(dd->dfd, sub_header_kdump, block_size) < block_size) {
				error(INFO, "compressed kdump: cannot read dump sub header\n");
				goto err;
			}
		}
		dd->sub_header_kdump = sub_header_kdump;

#if defined(__i386__) && (defined(ARM) || defined(MIPS))
		arm_kdump_header_adjust(header->header_version);
#endif
		/* use 64bit max_mapnr in compressed kdump file sub-header */
		if (header->header_version >= 6)
			dd->max_mapnr = dd->sub_header_kdump->max_mapnr_64;
		else {
			dd->sub_header_kdump->start_pfn_64
				= dd->sub_header_kdump->start_pfn;
			dd->sub_header_kdump->end_pfn_64
				= dd->sub_header_kdump->end_pfn;
		}
	}

	if (header->header_version < 6)
		dd->max_mapnr = header->max_mapnr;

	/* read memory bitmap */
	bitmap_len = (off_t)block_size * header->bitmap_blocks;
	dd->bitmap_len = bitmap_len;

	offset = (off_t)block_size * (1 + header->sub_hdr_size);

	if ((dd->bitmap = malloc(bitmap_len)) == NULL)
		error(FATAL, "%s: cannot malloc bitmap buffer\n",
			DISKDUMP_VALID() ? "diskdump" : "compressed kdump");

	dd->dumpable_bitmap = calloc(bitmap_len, 1);

	if (CRASHDEBUG(8))
		fprintf(fp, "%s: memory bitmap offset: %llx\n",
			DISKDUMP_VALID() ? "diskdump" : "compressed kdump",
			(ulonglong)offset);

	if (FLAT_FORMAT()) {
		if (!read_flattened_format(dd->dfd, offset, dd->bitmap, bitmap_len)) {
			error(INFO, "%s: cannot read memory bitmap\n",
				DISKDUMP_VALID() ? "diskdump" : "compressed kdump");
			goto err;
		}
	} else {
		if (lseek(dd->dfd, offset, SEEK_SET) == failed) {
			error(INFO, "%s: cannot lseek memory bitmap\n",
				DISKDUMP_VALID() ? "diskdump" : "compressed kdump");
			goto err;
		}
		bufptr = dd->bitmap;
		len = bitmap_len;
		while (len) {
			bytes_read = read(dd->dfd, bufptr, len);
			if (bytes_read <= 0) {
				error(INFO, "%s: cannot read memory bitmap\n",
					DISKDUMP_VALID() ? "diskdump"
					: "compressed kdump");
				goto err;
			}
			len -= bytes_read;
			bufptr += bytes_read;
		}
	}

	if (dump_is_partial(header))
		memcpy(dd->dumpable_bitmap, dd->bitmap + bitmap_len/2,
		       bitmap_len/2);
	else
		memcpy(dd->dumpable_bitmap, dd->bitmap, bitmap_len);

	dd->data_offset
		= (1UL + header->sub_hdr_size + header->bitmap_blocks)
		* header->block_size;

```

#### region() [lines 695-802]
```c

	if (header->header_version < 6)
		dd->max_mapnr = header->max_mapnr;

	/* read memory bitmap */
	bitmap_len = (off_t)block_size * header->bitmap_blocks;
	dd->bitmap_len = bitmap_len;

	offset = (off_t)block_size * (1 + header->sub_hdr_size);

	if ((dd->bitmap = malloc(bitmap_len)) == NULL)
		error(FATAL, "%s: cannot malloc bitmap buffer\n",
			DISKDUMP_VALID() ? "diskdump" : "compressed kdump");

	dd->dumpable_bitmap = calloc(bitmap_len, 1);

	if (CRASHDEBUG(8))
		fprintf(fp, "%s: memory bitmap offset: %llx\n",
			DISKDUMP_VALID() ? "diskdump" : "compressed kdump",
			(ulonglong)offset);

	if (FLAT_FORMAT()) {
		if (!read_flattened_format(dd->dfd, offset, dd->bitmap, bitmap_len)) {
			error(INFO, "%s: cannot read memory bitmap\n",
				DISKDUMP_VALID() ? "diskdump" : "compressed kdump");
			goto err;
		}
	} else {
		if (lseek(dd->dfd, offset, SEEK_SET) == failed) {
			error(INFO, "%s: cannot lseek memory bitmap\n",
				DISKDUMP_VALID() ? "diskdump" : "compressed kdump");
			goto err;
		}
		bufptr = dd->bitmap;
		len = bitmap_len;
		while (len) {
			bytes_read = read(dd->dfd, bufptr, len);
			if (bytes_read <= 0) {
				error(INFO, "%s: cannot read memory bitmap\n",
					DISKDUMP_VALID() ? "diskdump"
					: "compressed kdump");
				goto err;
			}
			len -= bytes_read;
			bufptr += bytes_read;
		}
	}

	if (dump_is_partial(header))
		memcpy(dd->dumpable_bitmap, dd->bitmap + bitmap_len/2,
		       bitmap_len/2);
	else
		memcpy(dd->dumpable_bitmap, dd->bitmap, bitmap_len);

	dd->data_offset
		= (1UL + header->sub_hdr_size + header->bitmap_blocks)
		* header->block_size;

	dd->header = header;

	if (machine_type("ARM"))
		dd->machine_type = EM_ARM;
	else if (machine_type("MIPS") || machine_type("MIPS64"))
		dd->machine_type = EM_MIPS;
	else if (machine_type("X86"))
		dd->machine_type = EM_386;
	else if (machine_type("X86_64"))
		dd->machine_type = EM_X86_64;
	else if (machine_type("IA64"))
		dd->machine_type = EM_IA_64;
	else if (machine_type("PPC"))
		dd->machine_type = EM_PPC;
	else if (machine_type("PPC64"))
		dd->machine_type = EM_PPC64;
	else if (machine_type("S390X"))
		dd->machine_type = EM_S390;
	else if (machine_type("ARM64"))
		dd->machine_type = EM_AARCH64;
	else if (machine_type("SPARC64"))
		dd->machine_type = EM_SPARCV9;
	else {
		error(INFO, "%s: unsupported machine type: %s\n",
			DISKDUMP_VALID() ? "diskdump" : "compressed kdump",
			MACHINE_TYPE);
		goto err;
	}

	/* process elf notes data */
	if (KDUMP_CMPRS_VALID() && !(dd->flags & NO_ELF_NOTES) &&
		(dd->header->header_version >= 4) &&
		(sub_header_kdump->offset_note) &&
		(sub_header_kdump->size_note) && (machdep->process_elf_notes)) {
		size = sub_header_kdump->size_note;
		offset = sub_header_kdump->offset_note;

		if ((dd->notes_buf = malloc(size)) == NULL)
			error(FATAL, "compressed kdump: cannot malloc notes"
				" buffer\n");

		if ((dd->nt_prstatus_percpu = malloc(NR_CPUS * sizeof(void *))) == NULL)
			error(FATAL, "compressed kdump: cannot malloc pointer"
				" to NT_PRSTATUS notes\n");

		if ((dd->nt_qemu_percpu = malloc(NR_CPUS * sizeof(void *))) == NULL)
			error(FATAL, "qemu mem dump compressed: cannot malloc pointer"
				" to QEMU notes\n");

		if ((dd->nt_qemucs_percpu = malloc(NR_CPUS * sizeof(void *))) == NULL)
```

## Upstream Fix
```diff
From b80b16549e24769c7d5fe3a10c4b1a1c4b5161f3 Mon Sep 17 00:00:00 2001
From: Dave Anderson <anderson@redhat.com>
Date: Mon, 23 Mar 2020 15:52:11 -0400
Subject: [PATCH] Fix for reading compressed kdump dumpfiles from systems with
 physical memory located at extraordinarily high addresses.  In a system with
 a physical address range from 0x602770ecf000 to 0x6027ffffffff, the crash
 utility fails during session initialization due to an integer overflow,
 ending with the error message "crash: vmlinux and vmcore do not match!".
 (chenjialong@huawei.com)

References: bsc#1168233 ltc#184660
Upstream: merged
Git-commit: b80b16549e24769c7d5fe3a10c4b1a1c4b5161f3

---
 diskdump.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/diskdump.c b/diskdump.c
index e88243e616cc..328c932dad5a 100644
--- a/diskdump.c
+++ b/diskdump.c
@@ -233,7 +233,7 @@ clean_diskdump_data(void)
 }

 static inline int
-get_bit(char *map, int byte, int bit)
+get_bit(char *map, unsigned long byte, int bit)
 {
 	return map[byte] & (1<<bit);
 }
@@ -694,7 +694,7 @@ restart:
 		dd->max_mapnr = header->max_mapnr;

 	/* read memory bitmap */
-	bitmap_len = block_size * header->bitmap_blocks;
+	bitmap_len = (off_t)block_size * header->bitmap_blocks;
 	dd->bitmap_len = bitmap_len;

 	offset = (off_t)block_size * (1 + header->sub_hdr_size);
@@ -744,7 +744,7 @@ restart:
 		memcpy(dd->dumpable_bitmap, dd->bitmap, bitmap_len);

 	dd->data_offset
-		= (1 + header->sub_hdr_size + header->bitmap_blocks)
+		= (1UL + header->sub_hdr_size + header->bitmap_blocks)
 		* header->block_size;

 	dd->header = header;
--
2.23.0

```

Generate a backported patch for the SUSE target version.

[Assistant]
From b80b16549e24769c7d5fe3a10c4b1a1c4b5161f3 Mon Sep 17 00:00:00 2001
From: Dave Anderson <anderson@redhat.com>
Date: Mon, 23 Mar 2020 15:52:11 -0400
Subject: [PATCH] Fix for reading compressed kdump dumpfiles from systems with
 physical memory located at extraordinarily high addresses.  In a system with
 a physical address range from 0x602770ecf000 to 0x6027ffffffff, the crash
 utility fails during session initialization due to an integer overflow,
 ending with the error message "crash: vmlinux and vmcore do not match!".
 (chenjialong@huawei.com)

References: bsc#1168233 ltc#184660
Upstream: merged
Git-commit: b80b16549e24769c7d5fe3a10c4b1a1c4b5161f3

---
 diskdump.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/diskdump.c b/diskdump.c
index e88243e616cc..328c932dad5a 100644
--- a/diskdump.c
+++ b/diskdump.c
@@ -233,7 +233,7 @@ clean_diskdump_data(void)
 }

 static inline int
-get_bit(char *map, int byte, int bit)
+get_bit(char *map, unsigned long byte, int bit)
 {
 	return map[byte] & (1<<bit);
 }
@@ -694,7 +694,7 @@ restart:
 		dd->max_mapnr = header->max_mapnr;

 	/* read memory bitmap */
-	bitmap_len = block_size * header->bitmap_blocks;
+	bitmap_len = (off_t)block_size * header->bitmap_blocks;
 	dd->bitmap_len = bitmap_len;

 	offset = (off_t)block_size * (1 + header->sub_hdr_size);
@@ -744,7 +744,7 @@ restart:
 		memcpy(dd->dumpable_bitmap, dd->bitmap, bitmap_len);

 	dd->data_offset
-		= (1 + header->sub_hdr_size + header->bitmap_blocks)
+		= (1UL + header->sub_hdr_size + header->bitmap_blocks)
 		* header->block_size;

 	dd->header = header;
--
2.23.0


[System]
You are a security patch backporting assistant for SUSE/openSUSE.

Given a CVE description and an upstream fix, adapt the patch to work with
the target SUSE package version. Output the backported patch in unified
diff format. If the upstream fix applies directly, output it unchanged.

[User]
## CVE: CVE-2020-14356, CVE-2020-14331, CVE-2020-16166, CVE-2020-10135, CVE-2020-0305, CVE-2020-15780, CVE-2020-10781

From: Petr Tesarik <ptesarik@suse.cz>

## Package
crash

## Files to modify
- filesys.c

## Target Source Code

### filesys.c

#### region() [lines 532-638]
```c
redhat_kernel_directory_v2(char *buf)
{
        char *p1, *p2;

        if (!strstr(kt->proc_version, "Linux version "))
                return FALSE;

        BZERO(buf, BUFSIZE);
        sprintf(buf, "/usr/src/redhat/BUILD/kernel-");

        p1 = &kt->proc_version[strlen("Linux version ")];
        p2 = &buf[strlen(buf)];

        while (((*p1 >= '0') && (*p1 <= '9')) || (*p1 == '.'))
                *p2++ = *p1++;

        strcat(buf, "/linux-");

        p1 = &kt->proc_version[strlen("Linux version ")];
        p2 = &buf[strlen(buf)];

        while (((*p1 >= '0') && (*p1 <= '9')) || (*p1 == '.'))
                *p2++ = *p1++;

        return TRUE;
}

static int
redhat_debug_directory(char *buf)
{
        char *p1, *p2;

        if (!strstr(kt->proc_version, "Linux version "))
                return FALSE;

        BZERO(buf, BUFSIZE);
        sprintf(buf, "%s/", pc->redhat_debug_loc);

        p1 = &kt->proc_version[strlen("Linux version ")];
        p2 = &buf[strlen(buf)];

        while (*p1 != ' ')
                *p2++ = *p1++;

        return TRUE;
}

/*
 *  If a namelist was not entered, presume we're using the currently-running
 *  kernel.  Read its version string from /proc/version, and then look in
 *  the search directories for a kernel with the same version string embedded
 *  in it.
 */
static int
find_booted_kernel(void)
{
	char kernel[BUFSIZE];
	char buffer[BUFSIZE];
	char **searchdirs;
	int i, preferred, wrapped;
        DIR *dirp;
        struct dirent *dp;
	int found;

	pc->flags |= FINDKERNEL;

	fflush(fp);

	if (!file_exists("/proc/version", NULL)) {
		error(INFO,
		    "/proc/version: %s: cannot determine booted kernel\n",
			strerror(ENOENT));
		return FALSE;
	}

	if (!get_proc_version()) {
                error(INFO, "/proc/version: %s\n", strerror(errno));
                return FALSE;
	}

        if (CRASHDEBUG(1))
                fprintf(fp, "\nfind_booted_kernel: search for [%s]\n",
			kt->proc_version);

        searchdirs = build_searchdirs(CREATE, &preferred);

	for (i = preferred, wrapped = found = FALSE; !found; i++) {
		if (!searchdirs[i]) {
			if (preferred && !wrapped) {
				wrapped = TRUE;
				i = 0;
			} else
				break;
		} else if (wrapped && (preferred == i))
			break;

	        dirp = opendir(searchdirs[i]);
		if (!dirp)
			continue;
	        for (dp = readdir(dirp); dp != NULL; dp = readdir(dirp)) {
			if (dp->d_name[0] == '.')
				continue;

			sprintf(kernel, "%s%s", searchdirs[i], dp->d_name);

			if (mount_point(kernel) ||
```

#### find_booted_kernel() [lines 116-197]
```c
			}
			if (!pc->dumpfile)
				check_live_arch_mismatch();
			if (!find_booted_kernel())
	                	program_usage(SHORT_FORM);
		}

		if (!pc->dumpfile) {
			pc->flags |= LIVE_SYSTEM;
			get_live_memory_source();
		}

		if ((pc->nfd = open(pc->namelist, O_RDONLY)) < 0)
			error(FATAL, "%s: %s\n", pc->namelist, strerror(errno));
		else {
			close(pc->nfd);
			pc->nfd = -1;
		}

		if (LOCAL_ACTIVE() && !(pc->namelist_debug || pc->system_map)) {
			memory_source_init();
			match_proc_version();
		}

	}

	memory_source_init();

	if (ACTIVE())
		proc_kcore_init(fp, UNUSED);

	if (CRASHDEBUG(1)) {
		fprintf(fp, "readmem: %s() ", readmem_function_name());
		if (ACTIVE()) {
			fprintf(fp, "-> %s ", pc->live_memsrc);
			if (pc->flags & MEMMOD)
				fprintf(fp, "(module)");
			else if (pc->flags & CRASHBUILTIN)
				fprintf(fp, "(built-in)");
		}
		fprintf(fp, "\n");
	}
}

/*
 *  Do whatever's necessary to handle the memory source.
 */
static void
memory_source_init(void)
{
	if (REMOTE() && !(pc->flags2 & MEMSRC_LOCAL))
		return;

	if (pc->flags & KERNEL_DEBUG_QUERY)
		return;

        if (LOCAL_ACTIVE()) {
		if (pc->mfd != -1)  /* already been here */
			return;

		if (!STREQ(pc->live_memsrc, "/dev/mem") &&
		     STREQ(pc->live_memsrc, pc->memory_device)) {
			if (memory_driver_init())
				return;

			error(INFO, "cannot initialize crash memory driver\n");
			error(INFO, "using /dev/mem\n\n");
			pc->flags &= ~MEMMOD;
			pc->flags |= DEVMEM;
			pc->readmem = read_dev_mem;
			pc->writemem = write_dev_mem;
			pc->live_memsrc = "/dev/mem";
		}

		if (STREQ(pc->live_memsrc, "/dev/mem")) {
	                if ((pc->mfd = open("/dev/mem", O_RDWR)) < 0) {
	                        if ((pc->mfd = open("/dev/mem", O_RDONLY)) < 0)
	                                error(FATAL, "/dev/mem: %s\n",
	                                        strerror(errno));
	                } else
	                        pc->flags |= MFD_RDWR;
		} else if (STREQ(pc->live_memsrc, "/proc/kcore")) {
```

## Upstream Fix
```diff
From: Petr Tesarik <ptesarik@suse.cz>
Subject: Automatically detect compressed booted kernel
References: bnc#777516, bnc#828260
Patch-mainline: not yet

Signed-off-by: Petr Tesarik <ptesarik@suse.cz>

---
 filesys.c |   26 ++++++++++++++++++++++----
 1 file changed, 22 insertions(+), 4 deletions(-)

Index: crash-7.2.7/filesys.c
===================================================================
--- crash-7.2.7.orig/filesys.c
+++ crash-7.2.7/filesys.c
@@ -581,6 +581,7 @@ static int
 find_booted_kernel(void)
 {
 	char kernel[BUFSIZE];
+	char *real_kernel;
 	char buffer[BUFSIZE];
 	char **searchdirs;
 	int i, preferred, wrapped;
@@ -630,16 +631,24 @@ find_booted_kernel(void)
 			sprintf(kernel, "%s%s", searchdirs[i], dp->d_name);

 			if (mount_point(kernel) ||
-			    !file_readable(kernel) ||
-                            !is_kernel(kernel))
+			    !file_readable(kernel))
 				continue;

+			if (!is_compressed_kernel(kernel, &real_kernel))
+				real_kernel = kernel;
+
 			if (CRASHDEBUG(1))
 				fprintf(fp, "find_booted_kernel: check: %s\n",
 					kernel);

-			found = match_file_string(kernel, kt->proc_version, buffer);
-
+			if (!is_kernel(real_kernel)) {
+				if (real_kernel != kernel)
+					free(real_kernel);
+				continue;
+			}
+
+			found = match_file_string(real_kernel, kt->proc_version, buffer);
+
 			if (found)
 				break;
 	        }
@@ -659,10 +668,19 @@ find_booted_kernel(void)
 			if (CRASHDEBUG(1))
 				fprintf(fp, "find_booted_kernel: found: %s\n",
 					pc->namelist);
+			if (real_kernel != kernel) {
+				pc->namelist_orig = pc->namelist;
+				pc->namelist = real_kernel;
+			}
                         return TRUE;
                 }
 	}

+	if (real_kernel != kernel) {
+		remove(real_kernel);
+		free(real_kernel);
+	}
+
 	error(INFO,
              "cannot find booted kernel -- please enter namelist argument\n\n");
 	return FALSE;

```

Generate a backported patch for the SUSE target version.

[Assistant]
From: Petr Tesarik <ptesarik@suse.cz>
Subject: Automatically detect compressed booted kernel
References: bnc#777516, bnc#828260
Patch-mainline: not yet

Signed-off-by: Petr Tesarik <ptesarik@suse.cz>

---
 filesys.c |   26 ++++++++++++++++++++++----
 1 file changed, 22 insertions(+), 4 deletions(-)

Index: crash-7.2.7/filesys.c
===================================================================
--- crash-7.2.7.orig/filesys.c
+++ crash-7.2.7/filesys.c
@@ -581,6 +581,7 @@ static int
 find_booted_kernel(void)
 {
 	char kernel[BUFSIZE];
+	char *real_kernel;
 	char buffer[BUFSIZE];
 	char **searchdirs;
 	int i, preferred, wrapped;
@@ -630,16 +631,24 @@ find_booted_kernel(void)
 			sprintf(kernel, "%s%s", searchdirs[i], dp->d_name);

 			if (mount_point(kernel) ||
-			    !file_readable(kernel) ||
-                            !is_kernel(kernel))
+			    !file_readable(kernel))
 				continue;

+			if (!is_compressed_kernel(kernel, &real_kernel))
+				real_kernel = kernel;
+
 			if (CRASHDEBUG(1))
 				fprintf(fp, "find_booted_kernel: check: %s\n",
 					kernel);

-			found = match_file_string(kernel, kt->proc_version, buffer);
-
+			if (!is_kernel(real_kernel)) {
+				if (real_kernel != kernel)
+					free(real_kernel);
+				continue;
+			}
+
+			found = match_file_string(real_kernel, kt->proc_version, buffer);
+
 			if (found)
 				break;
 	        }
@@ -659,10 +668,19 @@ find_booted_kernel(void)
 			if (CRASHDEBUG(1))
 				fprintf(fp, "find_booted_kernel: found: %s\n",
 					pc->namelist);
+			if (real_kernel != kernel) {
+				pc->namelist_orig = pc->namelist;
+				pc->namelist = real_kernel;
+			}
                         return TRUE;
                 }
 	}

+	if (real_kernel != kernel) {
+		remove(real_kernel);
+		free(real_kernel);
+	}
+
 	error(INFO,
              "cannot find booted kernel -- please enter namelist argument\n\n");
 	return FALSE;


[System]
You are a security patch backporting assistant for SUSE/openSUSE.

Given a CVE description and an upstream fix, adapt the patch to work with
the target SUSE package version. Output the backported patch in unified
diff format. If the upstream fix applies directly, output it unchanged.

[User]
## CVE: CVE-2020-14356, CVE-2020-14331, CVE-2020-16166, CVE-2020-10135, CVE-2020-0305, CVE-2020-15780, CVE-2020-10781

Fix "uptime" and "ps -t" for SLES9

## Package
crash

## Files to modify
- b/defs.h
- b/kernel.c
- b/task.c

## Target Source Code

### defs.h

#### region() [lines 692-798]
```c
	ulong stext_init;
	ulong etext_init;
	ulong init_begin;
	ulong init_end;
	ulong end;
	int cpus;
	char *cpus_override;
	void (*display_bh)(void);
        ulong module_list;
        ulong kernel_module;
	int mods_installed;
	struct timespec date;
	char proc_version[BUFSIZE];
	struct new_utsname utsname;
	uint kernel_version[3];
	uint gcc_version[3];
	int runq_siblings;
	int kernel_NR_CPUS;
	long __per_cpu_offset[NR_CPUS];
	long *__rq_idx;
	long *__cpu_idx;
	ulong *cpu_flags;
#define POSSIBLE  (0x1)
#define PRESENT   (0x2)
#define ONLINE    (0x4)
#define NMI       (0x8)
#define POSSIBLE_MAP (POSSIBLE)
#define PRESENT_MAP   (PRESENT)
#define ONLINE_MAP     (ONLINE)
#define ACTIVE_MAP       (0x10)
	int BUG_bytes;
	ulong xen_flags;
#define WRITABLE_PAGE_TABLES    (0x1)
#define SHADOW_PAGE_TABLES      (0x2)
#define CANONICAL_PAGE_TABLES   (0x4)
#define XEN_SUSPEND             (0x8)
	char *m2p_page;
	ulong phys_to_machine_mapping;
	ulong p2m_table_size;
#define P2M_MAPPING_CACHE    (512)
	struct p2m_mapping_cache {
		ulong mapping;
		ulong pfn;
		ulong start;
		ulong end;
	} p2m_mapping_cache[P2M_MAPPING_CACHE];
#define P2M_MAPPING_PAGE_PFN(c) \
   (PVOPS_XEN() ? kt->p2m_mapping_cache[c].pfn : \
    (((kt->p2m_mapping_cache[c].mapping - kt->phys_to_machine_mapping)/PAGESIZE()) \
    * XEN_PFNS_PER_PAGE))
	ulong last_mapping_read;
	ulong p2m_cache_index;
	ulong p2m_pages_searched;
	ulong p2m_mfn_cache_hits;
	ulong p2m_page_cache_hits;
	ulong relocate;
	char *module_tree;
	struct pvops_xen_info {
		int p2m_top_entries;
		ulong p2m_top;
		ulong p2m_mid_missing;
		ulong p2m_missing;
	} pvops_xen;
	int highest_irq;
#define IKCONFIG_AVAIL	0x1	/* kernel contains ikconfig data */
#define IKCONFIG_LOADED	0x2	/* ikconfig data is currently loaded */
	int ikconfig_flags;
	int ikconfig_ents;
	char *hypervisor;
	struct vmcoreinfo_data {
		ulong log_buf_SYMBOL;
		ulong log_end_SYMBOL;
		ulong log_buf_len_SYMBOL;
		ulong logged_chars_SYMBOL;
		ulong log_first_idx_SYMBOL;
		ulong log_next_idx_SYMBOL;
		long log_SIZE;
		long log_ts_nsec_OFFSET;
		long log_len_OFFSET;
		long log_text_len_OFFSET;
		long log_dict_len_OFFSET;
		ulong phys_base_SYMBOL;
		ulong _stext_SYMBOL;
	} vmcoreinfo;
	ulonglong flags2;
	char *source_tree;
	struct timespec boot_date;
};

/*
 * Aid for the two versions of the kernel's module list linkage.
 */
#define NEXT_MODULE(next_module, modbuf)                             \
{                                                                    \
        switch (kt->flags & (KMOD_V1|KMOD_V2))                       \
        {                                                            \
        case KMOD_V1:                                                \
                next_module = ULONG(modbuf + OFFSET(module_next));   \
                break;                                               \
        case KMOD_V2:                                                \
                next_module = ULONG(modbuf + OFFSET(module_list));   \
                if (next_module != kt->kernel_module)                \
                        next_module -= OFFSET(module_list);          \
                break;                                               \
        }                                                            \
}

```

#### region() [lines 6839-6945]
```c
int vmware_vmss_init(char *filename, FILE *ofp);
uint vmware_vmss_page_size(void);
int read_vmware_vmss(int, void *, int, ulong, physaddr_t);
int write_vmware_vmss(int, void *, int, ulong, physaddr_t);
void vmware_vmss_display_regs(int, FILE *);
void get_vmware_vmss_regs(struct bt_info *, ulong *, ulong *);
int vmware_vmss_memory_dump(FILE *);
void dump_registers_for_vmss_dump(void);
int vmware_vmss_valid_regs(struct bt_info *);
int vmware_vmss_get_nr_cpus(void);
int vmware_vmss_get_cr3_cr4_idtr(int, ulong *, ulong *, ulong *);
int vmware_vmss_phys_base(ulong *phys_base);
int vmware_vmss_set_phys_base(ulong);

/*
 * vmware_guestdump.c
 */
int is_vmware_guestdump(char *filename);
int vmware_guestdump_init(char *filename, FILE *ofp);
int vmware_guestdump_memory_dump(FILE *);

/*
 * kaslr_helper.c
 */
int calc_kaslr_offset(ulong *, ulong *);

/*
 * printk.c
 */
void dump_lockless_record_log(int);

/* ... truncated ... */
```

### kernel.c

#### kernel_init() [lines 101-823]
```c
 *  Gather a few kernel basics.
 */
void
kernel_init()
{
	int i, c;
	char *p1, *p2, buf[BUFSIZE];
	struct syment *sp1, *sp2;
	char *rqstruct;
	char *rq_timestamp_name = NULL;
	char *irq_desc_type_name;
	ulong pv_init_ops;
	struct gnu_request req;

	if (pc->flags & KERNEL_DEBUG_QUERY)
		return;

        if (!(kt->cpu_flags = (ulong *)calloc(NR_CPUS, sizeof(ulong))))
                error(FATAL, "cannot malloc cpu_flags array");

	cpu_maps_init();

	kt->stext = symbol_value("_stext");
	kt->etext = symbol_value("_etext");
	get_text_init_space();
	if (symbol_exists("__init_begin")) {
		kt->init_begin = symbol_value("__init_begin");
		kt->init_end = symbol_value("__init_end");
	}
	kt->end = highest_bss_symbol();
	if ((sp1 = kernel_symbol_search("_end")) && (sp1->value > kt->end))
		kt->end = sp1->value;

	check_vmcoreinfo();

	/*
	 *  For the traditional (non-pv_ops) Xen architecture, default to writable
         *  page tables unless:
	 *
	 *  (1) it's an "xm save" CANONICAL_PAGE_TABLES dumpfile,  or
/* ... 147 lines omitted ... */
			*p2 = NULLCHAR;
			kt->kernel_version[2] = atoi(p1);
		} else
			kt->kernel_version[2] = 0;

		if (CRASHDEBUG(1))
			fprintf(fp, "base kernel version: %d.%d.%d\n",
				kt->kernel_version[0],
				kt->kernel_version[1],
				kt->kernel_version[2]);
	} else
		error(INFO, "cannot determine base kernel version\n");

	verify_version();

	if (symbol_exists("__per_cpu_offset")) {
		if (LKCD_KERNTYPES())
			i = get_cpus_possible();
		else
			i = get_array_length("__per_cpu_offset", NULL, 0);
		get_symbol_data("__per_cpu_offset",
			sizeof(long)*((i && (i <= NR_CPUS)) ? i : NR_CPUS),
			&kt->__per_cpu_offset[0]);
                kt->flags |= PER_CPU_OFF;
	}
/* ... 490 lines omitted ... */
	MEMBER_OFFSET_INIT(hrtimer_softexpires, "hrtimer", "_softexpires");
	MEMBER_OFFSET_INIT(hrtimer_function, "hrtimer", "function");

	MEMBER_OFFSET_INIT(ktime_t_tv64, "ktime", "tv64");
	if (INVALID_MEMBER(ktime_t_tv64))
		MEMBER_OFFSET_INIT(ktime_t_tv64, "ktime_t", "tv64");
	MEMBER_OFFSET_INIT(ktime_t_sec, "ktime", "sec");
	if (INVALID_MEMBER(ktime_t_sec))
		MEMBER_OFFSET_INIT(ktime_t_sec, "ktime_t", "sec");
	MEMBER_OFFSET_INIT(ktime_t_nsec, "ktime", "nsec");
	if (INVALID_MEMBER(ktime_t_nsec))
		MEMBER_OFFSET_INIT(ktime_t_nsec, "ktime_t", "nsec");

	if (kt->source_tree)
		source_tree_init();

	kt->flags &= ~PRE_KERNEL_INIT;
}

/*
```

#### get_uptime() [lines 5718-5756]
```c
 *  Calculate and return the uptime.
 */
char *
get_uptime(char *buf, ulonglong *j64p)
{
	ulong jiffies, tmp1, tmp2;
	ulonglong jiffies_64, wrapped;

	if (symbol_exists("jiffies_64")) {
		get_symbol_data("jiffies_64", sizeof(ulonglong), &jiffies_64);
		if (THIS_KERNEL_VERSION >= LINUX(2,6,0)) {
			wrapped = (jiffies_64 & 0xffffffff00000000ULL);
			if (wrapped) {
				wrapped -= 0x100000000ULL;
				jiffies_64 &= 0x00000000ffffffffULL;
				jiffies_64 |= wrapped;
                		jiffies_64 += (ulonglong)(300*machdep->hz);
			} else {
				tmp1 = (ulong)(uint)(-300*machdep->hz);
				tmp2 = (ulong)jiffies_64;
				jiffies_64 = (ulonglong)(tmp2 - tmp1);
			}
		}
		if (buf)
			convert_time(jiffies_64, buf);
		if (j64p)
			*j64p = jiffies_64;
	} else {
		get_symbol_data("jiffies", sizeof(long), &jiffies);
		if (buf)
			convert_time((ulonglong)jiffies, buf);
		if (j64p)
			*j64p = (ulonglong)jiffies;
	}

	return buf;
}

#define FSHIFT          11              /* nr of bits of precision */
```

#### region() [lines 6201-6221]
```c
		}
		fprintf(fp, "%lx ", kt->cpu_flags[i]);
		for (j = i, more = FALSE; j < nr_cpus; j++) {
			if (kt->cpu_flags[j])
				more = TRUE;
		}
		if (!more) {
			fprintf(fp, "...");
			break;
		}
	}
	fprintf(fp, "\n");
	fprintf(fp, "        possible cpus: ");
	if (cpu_map_addr("possible")) {
		for (i = c = 0; i < nr_cpus; i++) {
			if (kt->cpu_flags[i] & POSSIBLE_MAP) {
				fprintf(fp, "%d ", i);
				c++;
			}
		}
		fprintf(fp, "%s\n", c ? "" : "(none)");
```

### task.c

#### start_time_timespec() [lines 4532-4545]
```c
 		tsp->tc = tc;

		if (BITS32() && (SIZE(task_struct_start_time) == 8)) {
			if (start_time_timespec())
				tsp->start_time =
					ULONG(tt->task_struct +
					OFFSET(task_struct_start_time));
			else
				tsp->start_time =
					ULONGLONG(tt->task_struct +
					OFFSET(task_struct_start_time));
		} else {
			start_time_timespec();
			tsp->start_time = ULONG(tt->task_struct +
```

#### convert_start_time() [lines 4613-4641]
```c
        for (i = 0, tsp = task_start_times; i < tasks; i++, tsp++) {
		print_task_header(fp, tsp->tc, 0);
		fprintf(fp, "    RUN TIME: %s\n", symbol_exists("jiffies_64") ?
			convert_time(convert_start_time(tsp->start_time, jiffies_64), buf1) :
			convert_time(jiffies - tsp->start_time, buf1));
		fprintf(fp, "  START TIME: %llu\n", tsp->start_time);
		if (VALID_MEMBER(task_struct_times)) {
			fprintf(fp, "   USER TIME: %ld\n", tsp->tms_utime);
			fprintf(fp, " SYSTEM TIME: %ld\n\n", tsp->tms_stime);
		} else if (VALID_MEMBER(task_struct_utime)) {
			if (use_utime_stime) {
				fprintf(fp, "       UTIME: %lld\n",
					(ulonglong)tsp->utime);
				fprintf(fp, "       STIME: %lld\n\n",
					(ulonglong)tsp->stime);
			} else if (use_kernel_timeval) {
				fprintf(fp, "   USER TIME: %d\n",
					tsp->kutime.tv_sec);
				fprintf(fp, " SYSTEM TIME: %d\n\n",
					tsp->kstime.tv_sec);
			} else {
				fprintf(fp, "   USER TIME: %ld\n",
					tsp->old_utime.tv_sec);
				fprintf(fp, " SYSTEM TIME: %ld\n\n",
					tsp->old_stime.tv_sec);
			}
		}
	}
	FREEBUF(task_start_times);
```

## Upstream Fix
```diff
From: Alan Tyson <atyson@hp.com>
Subject: [PATCH] Fix "uptime" and "ps -t" for SLES9
References: 352836

This patch adds a quirk for SLES9 jiffies initialisation and corrects the time
data in "uptime" and "ps -t" command.

Acked-by: Bernhard Walle <bwalle@suse.de>

---
 defs.h   |    8 ++++++++
 kernel.c |    9 ++++++++-
 task.c   |   11 +++++++++++
 3 files changed, 27 insertions(+), 1 deletion(-)

Index: b/defs.h
===================================================================
--- a/defs.h
+++ b/defs.h
@@ -741,6 +741,7 @@ struct kernel_table {
 		ulong p2m_missing;
 	} pvops_xen;
 	int highest_irq;
+    int is_suse_kernel;
 #define IKCONFIG_AVAIL	0x1	/* kernel contains ikconfig data */
 #define IKCONFIG_LOADED	0x2	/* ikconfig data is currently loaded */
 	int ikconfig_flags;
@@ -6888,6 +6889,13 @@ extern struct lkcd_environment *lkcd;

 #endif  /* LKCD_COMMON */

+
+/*
+ * SUSE specific
+ */
+#define is_SLES9() \
+	((THIS_KERNEL_VERSION == LINUX(2,6,5)) && kt->is_suse_kernel)
+
 /*
  *  gdb_interface.c
  */
Index: b/kernel.c
===================================================================
--- a/kernel.c
+++ b/kernel.c
@@ -297,6 +297,12 @@ kernel_init()

 	verify_version();

+	/*
+	 * check if we have a suse kernel (this is the module supported
+	 * patch of agruen@suse.de
+	 */
+	kt->is_suse_kernel = symbol_exists("unsupported");
+
 	if (symbol_exists("__per_cpu_offset")) {
 		if (LKCD_KERNTYPES())
 			i = get_cpus_possible();
@@ -5617,7 +5623,7 @@ get_uptime(char *buf, ulonglong *j64p)

 	if (symbol_exists("jiffies_64")) {
 		get_symbol_data("jiffies_64", sizeof(ulonglong), &jiffies_64);
-		if (THIS_KERNEL_VERSION >= LINUX(2,6,0)) {
+		if (THIS_KERNEL_VERSION >= LINUX(2,6,0) && !is_SLES9()) {
 			wrapped = (jiffies_64 & 0xffffffff00000000ULL);
 			if (wrapped) {
 				wrapped -= 0x100000000ULL;
@@ -6213,6 +6219,7 @@ no_cpu_flags:
 			fprintf(fp, "            p2m_mid_missing: %lx\n", kt->pvops_xen.p2m_mid_missing);
 		fprintf(fp, "                p2m_missing: %lx\n", kt->pvops_xen.p2m_missing);
 	}
+	fprintf(fp, "         is_suse_kernel: %ld\n", kt->is_suse_kernel);
 }

 /*
Index: b/task.c
===================================================================
--- a/task.c
+++ b/task.c
@@ -4631,6 +4631,12 @@ start_time_timespec(void)
 	default:
 		break;
 	}
+	/* SLES9 stores start_time in nanoseconds, so set TIMESPEC in order */
+	/* to do the right calculations in convert_start_time               */
+	if (is_SLES9()) {
+		tt->flags |= TIMESPEC;
+		return TRUE;
+	}

 	tt->flags |= NO_TIMESPEC;

@@ -4667,6 +4673,11 @@ convert_start_time(ulonglong start_time,
 	ulong tmp1, tmp2;
 	ulonglong wrapped;

+	/* SLES9's start_time is neither jiffies nor a timespec.  It's ns */
+	if (is_SLES9()) {
+		start_time = start_time / 1000000000;
+	}
+
         switch(tt->flags & (TIMESPEC | NO_TIMESPEC | START_TIME_NSECS))
         {
 	case START_TIME_NSECS:

```

Generate a backported patch for the SUSE target version.

[Assistant]
From: Alan Tyson <atyson@hp.com>
Subject: [PATCH] Fix "uptime" and "ps -t" for SLES9
References: 352836

This patch adds a quirk for SLES9 jiffies initialisation and corrects the time
data in "uptime" and "ps -t" command.

Acked-by: Bernhard Walle <bwalle@suse.de>

---
 defs.h   |    8 ++++++++
 kernel.c |    9 ++++++++-
 task.c   |   11 +++++++++++
 3 files changed, 27 insertions(+), 1 deletion(-)

Index: b/defs.h
===================================================================
--- a/defs.h
+++ b/defs.h
@@ -741,6 +741,7 @@ struct kernel_table {
 		ulong p2m_missing;
 	} pvops_xen;
 	int highest_irq;
+    int is_suse_kernel;
 #define IKCONFIG_AVAIL	0x1	/* kernel contains ikconfig data */
 #define IKCONFIG_LOADED	0x2	/* ikconfig data is currently loaded */
 	int ikconfig_flags;
@@ -6888,6 +6889,13 @@ extern struct lkcd_environment *lkcd;

 #endif  /* LKCD_COMMON */

+
+/*
+ * SUSE specific
+ */
+#define is_SLES9() \
+	((THIS_KERNEL_VERSION == LINUX(2,6,5)) && kt->is_suse_kernel)
+
 /*
  *  gdb_interface.c
  */
Index: b/kernel.c
===================================================================
--- a/kernel.c
+++ b/kernel.c
@@ -297,6 +297,12 @@ kernel_init()

 	verify_version();

+	/*
+	 * check if we have a suse kernel (this is the module supported
+	 * patch of agruen@suse.de
+	 */
+	kt->is_suse_kernel = symbol_exists("unsupported");
+
 	if (symbol_exists("__per_cpu_offset")) {
 		if (LKCD_KERNTYPES())
 			i = get_cpus_possible();
@@ -5617,7 +5623,7 @@ get_uptime(char *buf, ulonglong *j64p)

 	if (symbol_exists("jiffies_64")) {
 		get_symbol_data("jiffies_64", sizeof(ulonglong), &jiffies_64);
-		if (THIS_KERNEL_VERSION >= LINUX(2,6,0)) {
+		if (THIS_KERNEL_VERSION >= LINUX(2,6,0) && !is_SLES9()) {
 			wrapped = (jiffies_64 & 0xffffffff00000000ULL);
 			if (wrapped) {
 				wrapped -= 0x100000000ULL;
@@ -6213,6 +6219,7 @@ no_cpu_flags:
 			fprintf(fp, "            p2m_mid_missing: %lx\n", kt->pvops_xen.p2m_mid_missing);
 		fprintf(fp, "                p2m_missing: %lx\n", kt->pvops_xen.p2m_missing);
 	}
+	fprintf(fp, "         is_suse_kernel: %ld\n", kt->is_suse_kernel);
 }

 /*
Index: b/task.c
===================================================================
--- a/task.c
+++ b/task.c
@@ -4631,6 +4631,12 @@ start_time_timespec(void)
 	default:
 		break;
 	}
+	/* SLES9 stores start_time in nanoseconds, so set TIMESPEC in order */
+	/* to do the right calculations in convert_start_time               */
+	if (is_SLES9()) {
+		tt->flags |= TIMESPEC;
+		return TRUE;
+	}

 	tt->flags |= NO_TIMESPEC;

@@ -4667,6 +4673,11 @@ convert_start_time(ulonglong start_time,
 	ulong tmp1, tmp2;
 	ulonglong wrapped;

+	/* SLES9's start_time is neither jiffies nor a timespec.  It's ns */
+	if (is_SLES9()) {
+		start_time = start_time / 1000000000;
+	}
+
         switch(tt->flags & (TIMESPEC | NO_TIMESPEC | START_TIME_NSECS))
         {
 	case START_TIME_NSECS:


[System]
You are a security patch backporting assistant for SUSE/openSUSE.

Given a CVE description and an upstream fix, adapt the patch to work with
the target SUSE package version. Output the backported patch in unified
diff format. If the upstream fix applies directly, output it unchanged.

[User]
## CVE: CVE-2020-14356, CVE-2020-14331, CVE-2020-16166, CVE-2020-10135, CVE-2020-0305, CVE-2020-15780, CVE-2020-10781

Add quirk for SLES9 LKCD header

## Package
crash

## Files to modify
- lkcd_v8.c

## Target Source Code

### lkcd_v8.c

#### lkcd_dump_init_v8_arch() [lines 90-195]
```c

#ifndef HAVE_NO_DUMP_HEADER_ASM
int
lkcd_dump_init_v8_arch(dump_header_t *dh)
{
	off_t 			ret_of;
	ssize_t 		ret_sz;
	uint32_t 		hdr_size, offset, nr_cpus;
	dump_header_asm_t 	arch_hdr;
	char 			*hdr_buf = NULL;

	ret_of = lseek(lkcd->fd, dh->dh_header_size +
			offsetof(dump_header_asm_t, dha_header_size),
			SEEK_SET);
	if (ret_of < 0) {
		perror("lseek failed in " __FILE__ ":" STR(__LINE__));
		goto err;
	}

	ret_sz = read(lkcd->fd, (char *)&hdr_size, sizeof(hdr_size));
	if (ret_sz != sizeof(hdr_size)) {
		perror("Reading hdr_size failed in " __FILE__ ":" STR(__LINE__));
		goto err;
	}

	ret_of = lseek(lkcd->fd, dh->dh_header_size, SEEK_SET);
	if (ret_of < 0) {
		perror("lseek failed in " __FILE__ ":" STR(__LINE__));
		goto err;
	}

	hdr_buf = (char *)malloc(hdr_size);
	if (!hdr_buf) {
		perror("Could not allocate memory for dump header\n");
		goto err;
	}

	ret_sz = read(lkcd->fd, (char *)hdr_buf, hdr_size);
	if (ret_sz != hdr_size) {
		perror("Could not read header " __FILE__ ":" STR(__LINE__));
		goto err;
	}

	/*
         * Though we have KL_NR_CPUS is 128, the header size is different
         * CONFIG_NR_CPUS might be different in the kernel. Hence, need
         * to find out how many CPUs are configured.
         */
        offset = offsetof(dump_header_asm_t, dha_smp_regs[0]);
        nr_cpus = (hdr_size - offset) / sizeof(dump_CPU_info_t);

	/* check for CPU overflow */
	if (nr_cpus > NR_CPUS) {
		fprintf(stderr, "CPU number too high %d (%s:%d)\n",
				nr_cpus, __FILE__, __LINE__);
		goto err;
	}

	/* parts that don't depend on the number of CPUs */
	memcpy(&arch_hdr, (void *)hdr_buf, offset);

	/* registers */
	memcpy(&arch_hdr.dha_smp_regs, (void *)&hdr_buf[offset],
			nr_cpus * sizeof(struct pt_regs));
	offset += nr_cpus * sizeof(struct pt_regs);

	/* current task */
	memcpy(&arch_hdr.dha_smp_current_task, (void *)&hdr_buf[offset],
			nr_cpus * sizeof(&arch_hdr.dha_smp_current_task[0]));
	offset += nr_cpus * sizeof(&arch_hdr.dha_smp_current_task[0]);

	/* stack */
	memcpy(&arch_hdr.dha_stack, (void *)&hdr_buf[offset],
			nr_cpus * sizeof(&arch_hdr.dha_stack[0]));
	offset += nr_cpus * sizeof(&arch_hdr.dha_stack[0]);

	/* stack_ptr */
	memcpy(&arch_hdr.dha_stack_ptr, (void *)&hdr_buf[offset],
			nr_cpus * sizeof(&arch_hdr.dha_stack_ptr[0]));
	offset += nr_cpus * sizeof(&arch_hdr.dha_stack_ptr[0]);

	if (arch_hdr.dha_magic_number != DUMP_ASM_MAGIC_NUMBER) {
		fprintf(stderr, "Invalid magic number for x86_64\n");
		goto err;
	}

	/*
	 * read the kernel load address on IA64 -- other architectures have
	 * no relocatable kernel at the lifetime of LKCD
	 */
#ifdef IA64
	memcpy(&arch_hdr.dha_kernel_addr, (void *)&hdr_buf[offset], sizeof(uint64_t));
#endif

	memcpy(&dump_header_asm_v8, &arch_hdr, sizeof(dump_header_asm_t));

	free(hdr_buf);
	return 0;

err:
	free(hdr_buf);
	return -1;
}

#else /* architecture that has no lkcd_dump_init_v8 */
```

### Type definitions

```c
/* from lkcd_dump_v8.h */
struct pt_regs {
	long ebx;
	long ecx;
	long edx;
	long esi;
	long edi;
	long ebp;
	long eax;
	int  xds;
	int  xes;
	long orig_eax;
	long eip;
	int  xcs;
	long eflags;
	long esp;
	int  xss;
};
```

## Upstream Fix
```diff
From: Bernhard Walle <bwalle@suse.de>
Subject: [PATCH] Add quirk for SLES9 LKCD header
Patch-mainline: never

On SLES9, we have a different header on IA64:

    SLES 10:

    typedef struct __dump_header_asm {
            uint64_t            dha_magic_number;
            uint32_t            dha_version;
            uint32_t            dha_header_size;
            uint64_t            dha_pt_regs;
            struct pt_regs      dha_regs;
            uint64_t            dha_rnat;
            uint64_t            dha_pfs;
            uint64_t            dha_bspstore;
            uint32_t	        dha_smp_num_cpus;
            uint32_t	        dha_dumping_cpu;
            struct pt_regs	dha_smp_regs[NR_CPUS];
            uint64_t	        dha_smp_current_task[NR_CPUS];
            uint64_t	        dha_stack[NR_CPUS];
            uint64_t	        dha_stack_ptr[NR_CPUS];
            uint64_t            dha_kernel_addr;
    } __attribute__((packed)) dump_header_asm_t;

    SLES 9:
    typedef struct __dump_header_asm {
            uint64_t            dha_magic_number;
            uint32_t            dha_version;
            uint32_t            dha_header_size;
            uint64_t            dha_kernel_addr;
            uint64_t            dha_pt_regs;
            struct pt_regs      dha_regs;
            uint64_t            dha_rnat;
            uint64_t            dha_pfs;
            uint64_t            dha_bspstore;
            uint32_t	        dha_smp_num_cpus;
            uint32_t	        dha_dumping_cpu;
            struct pt_regs	dha_smp_regs[NR_CPUS];
            uint64_t	        dha_smp_current_task[NR_CPUS];
            uint64_t	        dha_stack[NR_CPUS];
            uint64_t	        dha_stack_ptr[NR_CPUS];
    } __attribute__((packed)) dump_header_asm_t;

That patch tries to guess if it's a SLES 9 or a SLES 10 header
at runtime.

Signed-off-by: Bernhard Walle <bwalle@suse.de>

---
 lkcd_v8.c |   11 +++++++++++
 1 file changed, 11 insertions(+)

--- a/lkcd_v8.c
+++ b/lkcd_v8.c
@@ -130,6 +130,17 @@ lkcd_dump_init_v8_arch(dump_header_t *dh
 		goto err;
 	}

+#if IA64
+	/* SLES9 on IA64? */
+	if ( *((uint64_t *)(hdr_buf + hdr_size - sizeof(uint64_t))) <= NR_CPUS) {
+		uint64_t kernel_addr;
+		kernel_addr = ((dump_header_asm_t *)hdr_buf)->dha_pt_regs;
+		memmove(hdr_buf + offsetof(dump_header_asm_t, dha_pt_regs),
+				hdr_buf + offsetof(dump_header_asm_t, dha_regs),
+				hdr_size - offsetof(dump_header_asm_t, dha_regs));
+		*((uint64_t *)(hdr_buf + hdr_size - sizeof(uint64_t))) = kernel_addr;
+	}
+#endif

 	/*
          * Though we have KL_NR_CPUS is 128, the header size is different

```

Generate a backported patch for the SUSE target version.

[Assistant]
From: Bernhard Walle <bwalle@suse.de>
Subject: [PATCH] Add quirk for SLES9 LKCD header
Patch-mainline: never

On SLES9, we have a different header on IA64:

    SLES 10:

    typedef struct __dump_header_asm {
            uint64_t            dha_magic_number;
            uint32_t            dha_version;
            uint32_t            dha_header_size;
            uint64_t            dha_pt_regs;
            struct pt_regs      dha_regs;
            uint64_t            dha_rnat;
            uint64_t            dha_pfs;
            uint64_t            dha_bspstore;
            uint32_t	        dha_smp_num_cpus;
            uint32_t	        dha_dumping_cpu;
            struct pt_regs	dha_smp_regs[NR_CPUS];
            uint64_t	        dha_smp_current_task[NR_CPUS];
            uint64_t	        dha_stack[NR_CPUS];
            uint64_t	        dha_stack_ptr[NR_CPUS];
            uint64_t            dha_kernel_addr;
    } __attribute__((packed)) dump_header_asm_t;

    SLES 9:
    typedef struct __dump_header_asm {
            uint64_t            dha_magic_number;
            uint32_t            dha_version;
            uint32_t            dha_header_size;
            uint64_t            dha_kernel_addr;
            uint64_t            dha_pt_regs;
            struct pt_regs      dha_regs;
            uint64_t            dha_rnat;
            uint64_t            dha_pfs;
            uint64_t            dha_bspstore;
            uint32_t	        dha_smp_num_cpus;
            uint32_t	        dha_dumping_cpu;
            struct pt_regs	dha_smp_regs[NR_CPUS];
            uint64_t	        dha_smp_current_task[NR_CPUS];
            uint64_t	        dha_stack[NR_CPUS];
            uint64_t	        dha_stack_ptr[NR_CPUS];
    } __attribute__((packed)) dump_header_asm_t;

That patch tries to guess if it's a SLES 9 or a SLES 10 header
at runtime.

Signed-off-by: Bernhard Walle <bwalle@suse.de>

---
 lkcd_v8.c |   11 +++++++++++
 1 file changed, 11 insertions(+)

--- a/lkcd_v8.c
+++ b/lkcd_v8.c
@@ -130,6 +130,17 @@ lkcd_dump_init_v8_arch(dump_header_t *dh
 		goto err;
 	}

+#if IA64
+	/* SLES9 on IA64? */
+	if ( *((uint64_t *)(hdr_buf + hdr_size - sizeof(uint64_t))) <= NR_CPUS) {
+		uint64_t kernel_addr;
+		kernel_addr = ((dump_header_asm_t *)hdr_buf)->dha_pt_regs;
+		memmove(hdr_buf + offsetof(dump_header_asm_t, dha_pt_regs),
+				hdr_buf + offsetof(dump_header_asm_t, dha_regs),
+				hdr_size - offsetof(dump_header_asm_t, dha_regs));
+		*((uint64_t *)(hdr_buf + hdr_size - sizeof(uint64_t))) = kernel_addr;
+	}
+#endif

 	/*
          * Though we have KL_NR_CPUS is 128, the header size is different


[System]
You are a security patch backporting assistant for SUSE/openSUSE.

Given a CVE description and an upstream fix, adapt the patch to work with
the target SUSE package version. Output the backported patch in unified
diff format. If the upstream fix applies directly, output it unchanged.

[User]
## CVE: CVE-2020-14356, CVE-2020-14331, CVE-2020-16166, CVE-2020-10135, CVE-2020-0305, CVE-2020-15780, CVE-2020-10781

From: Hari Bathini <hbathini@linux.ibm.com>

## Package
crash

## Files to modify
- ppc64.c

## Target Source Code

### ppc64.c

#### ppc64_init() [lines 300-720]
```c
 *  times during initialization.
 */
void
ppc64_init(int when)
{
#if defined(__x86_64__)
        if (ACTIVE())
                error(FATAL, "compiled for the PPC64 architecture\n");
#endif
	switch (when)
	{
	case SETUP_ENV:
		machdep->process_elf_notes = process_elf64_notes;
		break;

	case PRE_SYMTAB:
		machdep->machspec = &ppc64_machine_specific;
		machdep->verify_symbol = ppc64_verify_symbol;
		if (pc->flags & KERNEL_DEBUG_QUERY)
			return;
		machdep->stacksize = PPC64_STACK_SIZE;
		machdep->last_pgd_read = 0;
		machdep->last_pud_read = 0;
		machdep->last_pmd_read = 0;
		machdep->last_ptbl_read = 0;
		machdep->verify_paddr = generic_verify_paddr;
		machdep->ptrs_per_pgd = PTRS_PER_PGD;
		machdep->flags |= MACHDEP_BT_TEXT;
                if (machdep->cmdline_args[0])
                        parse_cmdline_args();
		 machdep->clear_machdep_cache = ppc64_clear_machdep_cache;
		break;

	case PRE_GDB:
		/*
                * Recently there were changes made to kexec tools
                * to support 64K page size. With those changes
                * vmcore file obtained from a kernel which supports
                * 64K page size cannot be analyzed using crash on a
                * machine running with kernel supporting 4K page size
/* ... 170 lines omitted ... */

				} else if (!(machdep->flags & BOOK3E) &&
				    (THIS_KERNEL_VERSION >= LINUX(4,6,0))) {
					m->l1_index_size = PTE_INDEX_SIZE_L4_64K_3_10;

					if (THIS_KERNEL_VERSION >= LINUX(4,12,0)) {
						m->l2_index_size = PMD_INDEX_SIZE_L4_64K_4_12;
						if (THIS_KERNEL_VERSION >= LINUX(4,17,0))
							m->l3_index_size = PUD_INDEX_SIZE_L4_64K_4_17;
						else
							m->l3_index_size = PUD_INDEX_SIZE_L4_64K_4_12;
						m->l4_index_size = PGD_INDEX_SIZE_L4_64K_4_12;
					} else {
						m->l2_index_size = PMD_INDEX_SIZE_L4_64K_4_6;
						m->l3_index_size = PUD_INDEX_SIZE_L4_64K_4_6;
						m->l4_index_size = PGD_INDEX_SIZE_L4_64K_3_10;
					}
				} else if (THIS_KERNEL_VERSION >= LINUX(3,10,0)) {
					m->l1_index_size = PTE_INDEX_SIZE_L4_64K_3_10;
					m->l2_index_size = PMD_INDEX_SIZE_L4_64K_3_10;
					m->l3_index_size = PUD_INDEX_SIZE_L4_64K;
					m->l4_index_size = PGD_INDEX_SIZE_L4_64K_3_10;

				} else {
					m->l1_index_size = PTE_INDEX_SIZE_L4_64K;
					m->l2_index_size = PMD_INDEX_SIZE_L4_64K;
					m->l3_index_size = PUD_INDEX_SIZE_L4_64K;
					m->l4_index_size = PGD_INDEX_SIZE_L4_64K;
/* ... 163 lines omitted ... */
		}
		/*
		 * IRQ stacks are introduced in 2.6 and also configurable.
		 */
		if ((THIS_KERNEL_VERSION >= LINUX(2,6,0)) &&
			symbol_exists("hardirq_ctx"))
			ASSIGN_SIZE(irq_ctx) = STACKSIZE();

		break;

	case POST_INIT:
		break;

	case LOG_ONLY:
		machdep->identity_map_base = kt->vmcoreinfo._stext_SYMBOL;
		break;
	}
}

#ifndef KSYMS_START
```

## Upstream Fix
```diff
From 28fa7bd09013455b5ddc020dea4706278cda0d65 Mon Sep 17 00:00:00 2001
From: Hari Bathini <hbathini@linux.ibm.com>
Date: Wed, 20 Jun 2018 01:34:22 +0530
Subject: book3s/ppc64: Increase the VA range
Upstream: no, adapts the below upstream commit for SLE15 SP1
Git-commit: 28fa7bd09013455b5ddc020dea4706278cda0d65

Fix for PPC64 kernel virtual address translation in Linux 4.17 and
later kernels with commit c2b4d8b7417a59b7f9a52d0d8402f5257cbbd398,
titled "powerpc/mm/hash64: Increase the VA range", in which the
maximum virtual address value has been increased to 4PB.  Without
the patch, the translation/access of high vmalloc space addresses
fails; for example, the "kmem -[sS]" option fails the translation
of per-cpu kmem_cache_cpu addresses located in vmalloc space, with
the error messages "kmem: invalid kernel virtual address: <address>
type: kmem_cache_cpu.freelist" and "kmem: invalid kernel virtual
address: <address>  type: kmem_cache_cpu.page", and the "vtop"
command shows the addresses as "(not mapped)". (hbathini@linux.ibm.com)

[note: apply on 4.12+ for SLE 15 SP1 - incompatible with SLE 15 SP0]

---

Index: crash-7.2.8/ppc64.c
===================================================================
--- crash-7.2.8.orig/ppc64.c
+++ crash-7.2.8/ppc64.c
@@ -519,8 +519,9 @@ ppc64_init(int when)

 					if (THIS_KERNEL_VERSION >= LINUX(4,12,0)) {
 						m->l2_index_size = PMD_INDEX_SIZE_L4_64K_4_12;
-						if (THIS_KERNEL_VERSION >= LINUX(4,17,0))
-							m->l3_index_size = PUD_INDEX_SIZE_L4_64K_4_17;
+						if (THIS_KERNEL_VERSION >= LINUX(4,17,0) ||
+							is_SLE15SP1())
+								m->l3_index_size = PUD_INDEX_SIZE_L4_64K_4_17;
 						else
 							m->l3_index_size = PUD_INDEX_SIZE_L4_64K_4_12;
 						m->l4_index_size = PGD_INDEX_SIZE_L4_64K_4_12;

```

Generate a backported patch for the SUSE target version.

[Assistant]
From 28fa7bd09013455b5ddc020dea4706278cda0d65 Mon Sep 17 00:00:00 2001
From: Hari Bathini <hbathini@linux.ibm.com>
Date: Wed, 20 Jun 2018 01:34:22 +0530
Subject: book3s/ppc64: Increase the VA range
Upstream: no, adapts the below upstream commit for SLE15 SP1
Git-commit: 28fa7bd09013455b5ddc020dea4706278cda0d65

Fix for PPC64 kernel virtual address translation in Linux 4.17 and
later kernels with commit c2b4d8b7417a59b7f9a52d0d8402f5257cbbd398,
titled "powerpc/mm/hash64: Increase the VA range", in which the
maximum virtual address value has been increased to 4PB.  Without
the patch, the translation/access of high vmalloc space addresses
fails; for example, the "kmem -[sS]" option fails the translation
of per-cpu kmem_cache_cpu addresses located in vmalloc space, with
the error messages "kmem: invalid kernel virtual address: <address>
type: kmem_cache_cpu.freelist" and "kmem: invalid kernel virtual
address: <address>  type: kmem_cache_cpu.page", and the "vtop"
command shows the addresses as "(not mapped)". (hbathini@linux.ibm.com)

[note: apply on 4.12+ for SLE 15 SP1 - incompatible with SLE 15 SP0]

---

Index: crash-7.2.8/ppc64.c
===================================================================
--- crash-7.2.8.orig/ppc64.c
+++ crash-7.2.8/ppc64.c
@@ -519,8 +519,9 @@ ppc64_init(int when)

 					if (THIS_KERNEL_VERSION >= LINUX(4,12,0)) {
 						m->l2_index_size = PMD_INDEX_SIZE_L4_64K_4_12;
-						if (THIS_KERNEL_VERSION >= LINUX(4,17,0))
-							m->l3_index_size = PUD_INDEX_SIZE_L4_64K_4_17;
+						if (THIS_KERNEL_VERSION >= LINUX(4,17,0) ||
+							is_SLE15SP1())
+								m->l3_index_size = PUD_INDEX_SIZE_L4_64K_4_17;
 						else
 							m->l3_index_size = PUD_INDEX_SIZE_L4_64K_4_12;
 						m->l4_index_size = PGD_INDEX_SIZE_L4_64K_4_12;


[System]
You are a security patch backporting assistant for SUSE/openSUSE.

Given a CVE description and an upstream fix, adapt the patch to work with
the target SUSE package version. Output the backported patch in unified
diff format. If the upstream fix applies directly, output it unchanged.

[User]
## CVE: CVE-2020-14356, CVE-2020-14331, CVE-2020-16166, CVE-2020-10135, CVE-2020-0305, CVE-2020-15780, CVE-2020-10781

fix "kmem -[sS]" for caches created during SLUB bootstrap

## Package
crash

## Files to modify
- memory.c

## Upstream Fix
```diff
From 50f39247d80519c71d1f03984bc34aa476a9c2bd Mon Sep 17 00:00:00 2001
From: Hari Bathini <hbathini@in.ibm.com>
Date: Wed, 8 Apr 2020 11:38:23 +0200
Subject: [PATCH] fix "kmem -[sS]" for caches created during SLUB bootstrap

References: bsc#1164815 ltc#182973 https://www.redhat.com/archives/crash-utility/2020-April/msg00029.html
Upstream: submitted

Fix for "kmem -[sS]" options on Linux 4.14 and later kernels built
with CONFIG_SLAB_FREELIST_HARDENED enabled. Without the patch, there
will error messages of the type "kmem: <cache name> slab: <address>
invalid freepointer: <obfuscated address>" for caches created during
SLUB bootstrap, as they are likely to have s->random == 0.

Signed-off-by: Hari Bathini <hbathini linux ibm com>
---
 memory.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/memory.c b/memory.c
index ccc29442c3f6..c2433ebe5e75 100644
--- a/memory.c
+++ b/memory.c
@@ -19244,7 +19244,7 @@ count_free_objects(struct meminfo *si, ulong freelist)
 static ulong
 freelist_ptr(struct meminfo *si, ulong ptr, ulong ptr_addr)
 {
-	if (si->random)
+	if (VALID_MEMBER(kmem_cache_random))
 		/* CONFIG_SLAB_FREELIST_HARDENED */
 		return (ptr ^ si->random ^ ptr_addr);
 	else
--
2.23.0

```

Generate a backported patch for the SUSE target version.

[Assistant]
From 50f39247d80519c71d1f03984bc34aa476a9c2bd Mon Sep 17 00:00:00 2001
From: Hari Bathini <hbathini@in.ibm.com>
Date: Wed, 8 Apr 2020 11:38:23 +0200
Subject: [PATCH] fix "kmem -[sS]" for caches created during SLUB bootstrap

References: bsc#1164815 ltc#182973 https://www.redhat.com/archives/crash-utility/2020-April/msg00029.html
Upstream: submitted

Fix for "kmem -[sS]" options on Linux 4.14 and later kernels built
with CONFIG_SLAB_FREELIST_HARDENED enabled. Without the patch, there
will error messages of the type "kmem: <cache name> slab: <address>
invalid freepointer: <obfuscated address>" for caches created during
SLUB bootstrap, as they are likely to have s->random == 0.

Signed-off-by: Hari Bathini <hbathini linux ibm com>
---
 memory.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/memory.c b/memory.c
index ccc29442c3f6..c2433ebe5e75 100644
--- a/memory.c
+++ b/memory.c
@@ -19244,7 +19244,7 @@ count_free_objects(struct meminfo *si, ulong freelist)
 static ulong
 freelist_ptr(struct meminfo *si, ulong ptr, ulong ptr_addr)
 {
-	if (si->random)
+	if (VALID_MEMBER(kmem_cache_random))
 		/* CONFIG_SLAB_FREELIST_HARDENED */
 		return (ptr ^ si->random ^ ptr_addr);
 	else
--
2.23.0


[System]
You are a security patch backporting assistant for SUSE/openSUSE.

Given a CVE description and an upstream fix, adapt the patch to work with
the target SUSE package version. Output the backported patch in unified
diff format. If the upstream fix applies directly, output it unchanged.

[User]
## CVE: CVE-2020-14356, CVE-2020-14331, CVE-2020-16166, CVE-2020-10135, CVE-2020-0305, CVE-2020-15780, CVE-2020-10781

printf("%p %7d %7d %7d 0x%02x 0x%08x %5d:%-5d %s\n"

## Package
crash

## Upstream Fix
```diff
diff -Nurp sial-scripts-2008-02-08.orig//ps.c sial-scripts-2008-02-08/ps.c
--- sial-scripts-2008-02-08.orig//ps.c	2010-03-12 19:59:03.227788951 +0100
+++ sial-scripts-2008-02-08/ps.c	2010-03-12 19:59:16.690665574 +0100
@@ -192,7 +192,11 @@ string cmd;

 	printf("%p %7d %7d %7d 0x%02x 0x%08x %5d:%-5d %s\n"
 		, t
+#if LINUX_RELEASE > 0x02061d
+		, t->real_cred->uid
+#else
 		, t->uid
+#endif
 		, t->pid
 #if LINUX_2_6_X
 		, t->parent->pid

```

Generate a backported patch for the SUSE target version.

[Assistant]
diff -Nurp sial-scripts-2008-02-08.orig//ps.c sial-scripts-2008-02-08/ps.c
--- sial-scripts-2008-02-08.orig//ps.c	2010-03-12 19:59:03.227788951 +0100
+++ sial-scripts-2008-02-08/ps.c	2010-03-12 19:59:16.690665574 +0100
@@ -192,7 +192,11 @@ string cmd;

 	printf("%p %7d %7d %7d 0x%02x 0x%08x %5d:%-5d %s\n"
 		, t
+#if LINUX_RELEASE > 0x02061d
+		, t->real_cred->uid
+#else
 		, t->uid
+#endif
 		, t->pid
 #if LINUX_2_6_X
 		, t->parent->pid


[System]
You are a security patch backporting assistant for SUSE/openSUSE.

Given a CVE description and an upstream fix, adapt the patch to work with
the target SUSE package version. Output the backported patch in unified
diff format. If the upstream fix applies directly, output it unchanged.

[User]
## CVE: CVE-2020-14356, CVE-2020-14331, CVE-2020-16166, CVE-2020-10135, CVE-2020-0305, CVE-2020-15780, CVE-2020-10781

main.c |    8 +-------

## Package
crash

## Files to modify
- main.c

## Target Source Code

### main.c

#### setup_environment() [lines 1080-1245]
```c

static void
setup_environment(int argc, char **argv)
{
	int i;
	char *p1;
	char buf[BUFSIZE];
	char homerc[BUFSIZE];
	char localrc[BUFSIZE];
	FILE *afp;
	char *program;

	program = argv[0];

	/*
	 *  Program output typically goes via "fprintf(fp, ...)", but the
	 *  contents of fp are modified on the fly to handle redirection
	 *  to pipes or output files.
	 */
	fp = stdout;

	if (!set_error("default")) {
		fprintf(stderr, "crash: cannot malloc error() path string\n");
		clean_exit(1);
	}

	/*
	 *  Start populating the program_context structure.  It's used so
	 *  frequently that "pc" has been declared globally to point to the
	 *  "program_context" structure.
	 */
        pc->program_name = (char *)basename(program);
	pc->program_path = program;
        pc->program_version = build_version;
	pc->program_pid = (ulong)getpid();
        pc->curcmd = pc->program_name;
        pc->flags = (HASH|SCROLL);
	pc->flags |= DATADEBUG;          /* default until unnecessary */
	pc->flags2 |= REDZONE;
/* ... 40 lines omitted ... */
			pc->scroll_command = SCROLL_CRASHPAGER;
		} else if (file_exists("/usr/bin/less", NULL)) {
			pc->flags |= SCROLL;
			pc->scroll_command = SCROLL_LESS;
		} else if (file_exists("/bin/more", NULL)) {
			pc->flags |= SCROLL;
			pc->scroll_command = SCROLL_MORE;
		} else {
                	pc->scroll_command = SCROLL_NONE;
                	pc->flags &= ~SCROLL;
        	}
	}

	/*
	 *  Setup the readline command line editing mode based upon the
	 *  following order:
	 *
	 *   (1) EDITOR environment variable
         *   (2) overridden by any .crashrc entry: "set vi" or "set emacs"
         *   (3) RL_VI_MODE if not set anywhere else
	 */

	pc->flags |= READLINE;
	pc->editing_mode = "no_mode";

	if ((p1 = getenv("EDITOR"))) {
		if (strstr(p1, "vi"))
			pc->editing_mode = "vi";
		if (strstr(p1, "emacs"))
			pc->editing_mode = "emacs";
	}

/* ... 34 lines omitted ... */
	    !(pc->flags & NOCRASHRC) && file_exists(localrc, NULL)) {
		if ((afp = fopen(localrc, "r")) == NULL)
                        error(INFO, "cannot open %s: %s\n",
				localrc, strerror(errno));
		else if (untrusted_file(afp, localrc))
			fclose(afp);
		else {
			while (fgets(buf, BUFSIZE, afp))
				resolve_rc_cmd(buf, ALIAS_RCLOCAL);
			fclose(afp);
		}
	}

	if (STREQ(pc->editing_mode, "no_mode"))
		pc->editing_mode = "vi";

	machdep_init(SETUP_ENV);
}

```

## Upstream Fix
```diff
---
 main.c |    8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)

Index: crash-7.2.7/main.c
===================================================================
--- crash-7.2.7.orig/main.c
+++ crash-7.2.7/main.c
@@ -1169,12 +1169,6 @@ setup_environment(int argc, char **argv)
 	pc->flags |= READLINE;
 	pc->editing_mode = "no_mode";

-	if ((p1 = getenv("EDITOR"))) {
-		if (strstr(p1, "vi"))
-			pc->editing_mode = "vi";
-		if (strstr(p1, "emacs"))
-			pc->editing_mode = "emacs";
-	}

 	/*
 	 *  Resolve $HOME .rc file first, then the one in the local directory.
@@ -1224,7 +1218,7 @@ setup_environment(int argc, char **argv)
 	}

 	if (STREQ(pc->editing_mode, "no_mode"))
-		pc->editing_mode = "vi";
+		pc->editing_mode = "emacs";

 	machdep_init(SETUP_ENV);
 }

```

Generate a backported patch for the SUSE target version.

[Assistant]
---
 main.c |    8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)

Index: crash-7.2.7/main.c
===================================================================
--- crash-7.2.7.orig/main.c
+++ crash-7.2.7/main.c
@@ -1169,12 +1169,6 @@ setup_environment(int argc, char **argv)
 	pc->flags |= READLINE;
 	pc->editing_mode = "no_mode";

-	if ((p1 = getenv("EDITOR"))) {
-		if (strstr(p1, "vi"))
-			pc->editing_mode = "vi";
-		if (strstr(p1, "emacs"))
-			pc->editing_mode = "emacs";
-	}

 	/*
 	 *  Resolve $HOME .rc file first, then the one in the local directory.
@@ -1224,7 +1218,7 @@ setup_environment(int argc, char **argv)
 	}

 	if (STREQ(pc->editing_mode, "no_mode"))
-		pc->editing_mode = "vi";
+		pc->editing_mode = "emacs";

 	machdep_init(SETUP_ENV);
 }


[System]
You are a security patch backporting assistant for SUSE/openSUSE.

Given a CVE description and an upstream fix, adapt the patch to work with
the target SUSE package version. Output the backported patch in unified
diff format. If the upstream fix applies directly, output it unchanged.

[User]
## CVE: CVE-2020-14356, CVE-2020-14331, CVE-2020-16166, CVE-2020-10135, CVE-2020-0305, CVE-2020-15780, CVE-2020-10781

From: Hari Bathini <hbathini@linux.ibm.com>

## Package
crash

## Files to modify
- defs.h
- ppc64.c

## Target Source Code

### defs.h

#### region() [lines 6847-6953]
```c
int vmware_vmss_valid_regs(struct bt_info *);
int vmware_vmss_get_nr_cpus(void);
int vmware_vmss_get_cr3_cr4_idtr(int, ulong *, ulong *, ulong *);
int vmware_vmss_phys_base(ulong *phys_base);
int vmware_vmss_set_phys_base(ulong);

/*
 * vmware_guestdump.c
 */
int is_vmware_guestdump(char *filename);
int vmware_guestdump_init(char *filename, FILE *ofp);
int vmware_guestdump_memory_dump(FILE *);

/*
 * kaslr_helper.c
 */
int calc_kaslr_offset(ulong *, ulong *);

/*
 * printk.c
 */
void dump_lockless_record_log(int);

/*
 *  gnu_binutils.c
 */

/* NO LONGER IN USE */

/*
 *  test.c
 */
void cmd_template(void);
void foreach_test(ulong, ulong);

/*
 *  va_server.c
 */
int mclx_page_size(void);
int vas_memory_used(void);
int vas_memory_dump(FILE *);
int vas_free_memory(char *);
void set_vas_debug(ulong);
size_t vas_write(void *, size_t);
int va_server_init(char *, ulong *, ulong *, ulong *);
size_t vas_read(void *, size_t);
int vas_lseek(ulong, int);

/*
 *  lkcd_x86_trace.c
 */
int lkcd_x86_back_trace(struct bt_info *, int, FILE *);

/*
 * lkcd_common.c
 */
int lkcd_dump_init(FILE *, int, char *);
ulong get_lkcd_panic_task(void);
void get_lkcd_panicmsg(char *);
int is_lkcd_compressed_dump(char *);
void dump_lkcd_environment(ulong);
int lkcd_lseek(physaddr_t);
long lkcd_read(void *, long);
void set_lkcd_debug(ulong);
FILE *set_lkcd_fp(FILE *);
uint lkcd_page_size(void);
int lkcd_memory_used(void);
int lkcd_memory_dump(FILE *);
int lkcd_free_memory(void);
void lkcd_print(char *, ...);
void set_remote_lkcd_panic_data(ulong, char *);
void set_lkcd_nohash(void);
int lkcd_load_dump_page_header(void *, ulong);
void lkcd_dumpfile_complaint(uint32_t, uint32_t, int);
int set_mb_benchmark(ulong);
ulonglong fix_lkcd_address(ulonglong);
int lkcd_get_kernel_start(ulong *addr);
int get_lkcd_regs_for_cpu(struct bt_info *bt, ulong *eip, ulong *esp);

/*
 * lkcd_v1.c
 */
int lkcd_dump_init_v1(FILE *, int);
void dump_dump_page_v1(char *, void *);
void dump_lkcd_environment_v1(ulong);
uint32_t get_dp_size_v1(void);
uint32_t get_dp_flags_v1(void);
uint64_t get_dp_address_v1(void);

/*
 * lkcd_v2_v3.c
 */
int lkcd_dump_init_v2_v3(FILE *, int);
void dump_dump_page_v2_v3(char *, void *);
void dump_lkcd_environment_v2_v3(ulong);
uint32_t get_dp_size_v2_v3(void);
uint32_t get_dp_flags_v2_v3(void);
uint64_t get_dp_address_v2_v3(void);

/*
 * lkcd_v5.c
 */
int lkcd_dump_init_v5(FILE *, int);
void dump_dump_page_v5(char *, void *);
void dump_lkcd_environment_v5(ulong);
uint32_t get_dp_size_v5(void);
uint32_t get_dp_flags_v5(void);
```

### ppc64.c

#### set_ppc64_max_physmem_bits() [lines 222-258]
```c

#define is_RHEL8() (strstr(kt->proc_version, ".el8."))

static int set_ppc64_max_physmem_bits(void)
{
	int dimension;
	char *string;

	if ((string = pc->read_vmcoreinfo("NUMBER(MAX_PHYSMEM_BITS)"))) {
		machdep->max_physmem_bits = atol(string);
		free(string);
		return 0;
	}

	get_array_length("mem_section", &dimension, 0);

	if ((machdep->flags & VMEMMAP) &&
	    (THIS_KERNEL_VERSION >= LINUX(4,20,0)) &&
	    !dimension && (machdep->pagesize == 65536)) {
		/*
		 * SPARSEMEM_VMEMMAP & SPARSEMEM_EXTREME configurations with
		 * 64K pagesize and v4.20 kernel or later.
		 */
		machdep->max_physmem_bits = _MAX_PHYSMEM_BITS_4_20;
	} else if ((machdep->flags & VMEMMAP) &&
	    ((THIS_KERNEL_VERSION >= LINUX(4,19,0)) || is_RHEL8())) {
		/* SPARSEMEM_VMEMMAP & v4.19 kernel or later, or RHEL8 */
		machdep->max_physmem_bits = _MAX_PHYSMEM_BITS_4_19;
	} else if (THIS_KERNEL_VERSION >= LINUX(3,7,0))
		machdep->max_physmem_bits = _MAX_PHYSMEM_BITS_3_7;
	else
		machdep->max_physmem_bits = _MAX_PHYSMEM_BITS;

	return 0;
}

struct machine_specific ppc64_machine_specific = {
```

## Upstream Fix
```diff
From 599a6579aa916df7800f8e889d68e4287e4520dd Mon Sep 17 00:00:00 2001
From: Hari Bathini <hbathini@linux.ibm.com>
Date: Thu, 27 Sep 2018 02:06:49 +0530
Subject: ppc64: increase MAX_PHYSMEM_BITS to 128TB
Upstream: no, adapts the below upstream commit for SLE15 SP1
Git-commit: 599a6579aa916df7800f8e889d68e4287e4520dd

With Linux 4.19-rc1 commit 7d4340bb92a9df78e6e28152f3dd89d9bd82146b,
titled "powerpc/mm: Increase MAX_PHYSMEM_BITS to 128TB with
SPARSEMEM_VMEMMAP config", the PPC64 MAX_PHYSMEM_BITS value has been
bumped up to 47.  The appropriate update has been made in this patch.
(hbathini@linux.ibm.com)

[note: apply on 4.12+ for SLE 15 SP1 - incompatible with SLE 15 SP0]
---

Index: crash-7.2.8/defs.h
===================================================================
--- crash-7.2.8.orig/defs.h
+++ crash-7.2.8/defs.h
@@ -6896,6 +6896,9 @@ extern struct lkcd_environment *lkcd;
 #define is_SLES9() \
 	((THIS_KERNEL_VERSION == LINUX(2,6,5)) && kt->is_suse_kernel)

+#define is_SLE15SP1() \
+	((THIS_KERNEL_VERSION >= LINUX(4,12,0)) && kt->is_suse_kernel)
+
 /*
  *  gdb_interface.c
  */
Index: crash-7.2.8/ppc64.c
===================================================================
--- crash-7.2.8.orig/ppc64.c
+++ crash-7.2.8/ppc64.c
@@ -244,9 +244,14 @@ static int set_ppc64_max_physmem_bits(vo
 		 */
 		machdep->max_physmem_bits = _MAX_PHYSMEM_BITS_4_20;
 	} else if ((machdep->flags & VMEMMAP) &&
-	    ((THIS_KERNEL_VERSION >= LINUX(4,19,0)) || is_RHEL8())) {
-		/* SPARSEMEM_VMEMMAP & v4.19 kernel or later, or RHEL8 */
-		machdep->max_physmem_bits = _MAX_PHYSMEM_BITS_4_19;
+	    ((THIS_KERNEL_VERSION >= LINUX(4,19,0)) ||
+		is_RHEL8() ||
+		is_SLE15SP1())) {
+			/*
+			 * SPARSEMEM_VMEMMAP & v4.19 kernel or later,
+			 * or RHEL8 or SLE-15-SP1
+			 */
+			machdep->max_physmem_bits = _MAX_PHYSMEM_BITS_4_19;
 	} else if (THIS_KERNEL_VERSION >= LINUX(3,7,0))
 		machdep->max_physmem_bits = _MAX_PHYSMEM_BITS_3_7;
 	else

```

Generate a backported patch for the SUSE target version.

[Assistant]
From 599a6579aa916df7800f8e889d68e4287e4520dd Mon Sep 17 00:00:00 2001
From: Hari Bathini <hbathini@linux.ibm.com>
Date: Thu, 27 Sep 2018 02:06:49 +0530
Subject: ppc64: increase MAX_PHYSMEM_BITS to 128TB
Upstream: no, adapts the below upstream commit for SLE15 SP1
Git-commit: 599a6579aa916df7800f8e889d68e4287e4520dd

With Linux 4.19-rc1 commit 7d4340bb92a9df78e6e28152f3dd89d9bd82146b,
titled "powerpc/mm: Increase MAX_PHYSMEM_BITS to 128TB with
SPARSEMEM_VMEMMAP config", the PPC64 MAX_PHYSMEM_BITS value has been
bumped up to 47.  The appropriate update has been made in this patch.
(hbathini@linux.ibm.com)

[note: apply on 4.12+ for SLE 15 SP1 - incompatible with SLE 15 SP0]
---

Index: crash-7.2.8/defs.h
===================================================================
--- crash-7.2.8.orig/defs.h
+++ crash-7.2.8/defs.h
@@ -6896,6 +6896,9 @@ extern struct lkcd_environment *lkcd;
 #define is_SLES9() \
 	((THIS_KERNEL_VERSION == LINUX(2,6,5)) && kt->is_suse_kernel)

+#define is_SLE15SP1() \
+	((THIS_KERNEL_VERSION >= LINUX(4,12,0)) && kt->is_suse_kernel)
+
 /*
  *  gdb_interface.c
  */
Index: crash-7.2.8/ppc64.c
===================================================================
--- crash-7.2.8.orig/ppc64.c
+++ crash-7.2.8/ppc64.c
@@ -244,9 +244,14 @@ static int set_ppc64_max_physmem_bits(vo
 		 */
 		machdep->max_physmem_bits = _MAX_PHYSMEM_BITS_4_20;
 	} else if ((machdep->flags & VMEMMAP) &&
-	    ((THIS_KERNEL_VERSION >= LINUX(4,19,0)) || is_RHEL8())) {
-		/* SPARSEMEM_VMEMMAP & v4.19 kernel or later, or RHEL8 */
-		machdep->max_physmem_bits = _MAX_PHYSMEM_BITS_4_19;
+	    ((THIS_KERNEL_VERSION >= LINUX(4,19,0)) ||
+		is_RHEL8() ||
+		is_SLE15SP1())) {
+			/*
+			 * SPARSEMEM_VMEMMAP & v4.19 kernel or later,
+			 * or RHEL8 or SLE-15-SP1
+			 */
+			machdep->max_physmem_bits = _MAX_PHYSMEM_BITS_4_19;
 	} else if (THIS_KERNEL_VERSION >= LINUX(3,7,0))
 		machdep->max_physmem_bits = _MAX_PHYSMEM_BITS_3_7;
 	else


[System]
You are a security patch backporting assistant for SUSE/openSUSE.

Given a CVE description and an upstream fix, adapt the patch to work with
the target SUSE package version. Output the backported patch in unified
diff format. If the upstream fix applies directly, output it unchanged.

[User]
## CVE: CVE-2017-5715

From: Petr Tesarik <ptesarik@suse.cz>

## Package
crash

## Files to modify
- Makefile

## Upstream Fix
```diff
From: Petr Tesarik <ptesarik@suse.cz>
Subject: Apply custom patches to gdb
Patch-mainline: never

Enhance the crash specfile to allow applying custom patches.

Update jeffm 17 Sep 2014: What used to be in the series file is now in
gdb-7.6-ppc64le-support.patch. We used to apply it unconditionally so
we'll continue to do so.

Signed-off-by: Petr Tesarik <ptesarik@suse.cz>

---
 Makefile |    7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

--- a/Makefile
+++ b/Makefile
@@ -263,8 +263,11 @@ gdb_unzip:
 gdb_patch:
 	if [ -f ${GDB}.patch ] && [ -s ${GDB}.patch ]; then \
 		patch -p0 < ${GDB}.patch; cp ${GDB}.patch ${GDB}; fi
-	if [ "${ARCH}" = "ppc64le" ] && [ -f ${GDB}-ppc64le-support.patch ]; then \
-		patch -d ${GDB} -p1 -F0 < ${GDB}-ppc64le-support.patch ; \
+	patch -d ${GDB} -p1 -F0 < ${GDB}-ppc64le-support.patch ; \
+	if [ -f ${GDB}.series ]; then \
+		while read p; do \
+			patch -d ${GDB} -p1 -F0 < "$$p" ; \
+		done < ${GDB}.series ; \
 	fi
 	if [ "${ARCH}" = "x86_64" ] && [ "${TARGET}" = "PPC64" ] && [ -f ${GDB}-ppc64le-support.patch ]; then \
 		patch -d ${GDB} -p1 -F0 < ${GDB}-ppc64le-support.patch ; \

```

Generate a backported patch for the SUSE target version.

[Assistant]
From: Petr Tesarik <ptesarik@suse.cz>
Subject: Apply custom patches to gdb
Patch-mainline: never

Enhance the crash specfile to allow applying custom patches.

Update jeffm 17 Sep 2014: What used to be in the series file is now in
gdb-7.6-ppc64le-support.patch. We used to apply it unconditionally so
we'll continue to do so.

Signed-off-by: Petr Tesarik <ptesarik@suse.cz>

---
 Makefile |    7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

--- a/Makefile
+++ b/Makefile
@@ -263,8 +263,11 @@ gdb_unzip:
 gdb_patch:
 	if [ -f ${GDB}.patch ] && [ -s ${GDB}.patch ]; then \
 		patch -p0 < ${GDB}.patch; cp ${GDB}.patch ${GDB}; fi
-	if [ "${ARCH}" = "ppc64le" ] && [ -f ${GDB}-ppc64le-support.patch ]; then \
-		patch -d ${GDB} -p1 -F0 < ${GDB}-ppc64le-support.patch ; \
+	patch -d ${GDB} -p1 -F0 < ${GDB}-ppc64le-support.patch ; \
+	if [ -f ${GDB}.series ]; then \
+		while read p; do \
+			patch -d ${GDB} -p1 -F0 < "$$p" ; \
+		done < ${GDB}.series ; \
 	fi
 	if [ "${ARCH}" = "x86_64" ] && [ "${TARGET}" = "PPC64" ] && [ -f ${GDB}-ppc64le-support.patch ]; then \
 		patch -d ${GDB} -p1 -F0 < ${GDB}-ppc64le-support.patch ; \


[System]
You are a security patch backporting assistant for SUSE/openSUSE.

Given a CVE description and an upstream fix, adapt the patch to work with
the target SUSE package version. Output the backported patch in unified
diff format. If the upstream fix applies directly, output it unchanged.

[User]
## CVE: CVE-2015-8956, CVE-2016-5195, CVE-2016-8658, CVE-2016-7117, CVE-2016-0823, CVE-2016-7425, CVE-2016-6327, CVE-2016-6828, CVE-2016-5696, CVE-2016-6480, CVE-2015-7513, CVE-2016-1237

From: Petr Tesarik <ptesarik@suse.cz>

## Package
crash

## Files to modify
- Makefile

## Upstream Fix
```diff
From: Petr Tesarik <ptesarik@suse.cz>
Subject: Apply custom patches to gdb
Patch-mainline: never

Enhance the crash specfile to allow applying custom patches.

Update jeffm 17 Sep 2014: What used to be in the series file is now in
gdb-7.6-ppc64le-support.patch. We used to apply it unconditionally so
we'll continue to do so.

Signed-off-by: Petr Tesarik <ptesarik@suse.cz>

---
 Makefile |    7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

--- a/Makefile	2014-09-17 10:54:23.070488397 -0400
+++ b/Makefile	2014-09-17 10:54:59.557726952 -0400
@@ -260,8 +260,11 @@ gdb_unzip:
 gdb_patch:
 	if [ -f ${GDB}.patch ] && [ -s ${GDB}.patch ]; then \
 		patch -p0 < ${GDB}.patch; cp ${GDB}.patch ${GDB}; fi
-	if [ "${ARCH}" = "ppc64le" ] && [ -f ${GDB}-ppc64le-support.patch ]; then \
-		patch -d ${GDB} -p1 -F0 < ${GDB}-ppc64le-support.patch ; \
+	patch -d ${GDB} -p1 -F0 < ${GDB}-ppc64le-support.patch ; \
+	if [ -f ${GDB}.series ]; then \
+		while read p; do \
+			patch -d ${GDB} -p1 -F0 < "$$p" ; \
+		done < ${GDB}.series ; \
 	fi

 library: make_build_data ${OBJECT_FILES}

```

Generate a backported patch for the SUSE target version.

[Assistant]
From: Petr Tesarik <ptesarik@suse.cz>
Subject: Apply custom patches to gdb
Patch-mainline: never

Enhance the crash specfile to allow applying custom patches.

Update jeffm 17 Sep 2014: What used to be in the series file is now in
gdb-7.6-ppc64le-support.patch. We used to apply it unconditionally so
we'll continue to do so.

Signed-off-by: Petr Tesarik <ptesarik@suse.cz>

---
 Makefile |    7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

--- a/Makefile	2014-09-17 10:54:23.070488397 -0400
+++ b/Makefile	2014-09-17 10:54:59.557726952 -0400
@@ -260,8 +260,11 @@ gdb_unzip:
 gdb_patch:
 	if [ -f ${GDB}.patch ] && [ -s ${GDB}.patch ]; then \
 		patch -p0 < ${GDB}.patch; cp ${GDB}.patch ${GDB}; fi
-	if [ "${ARCH}" = "ppc64le" ] && [ -f ${GDB}-ppc64le-support.patch ]; then \
-		patch -d ${GDB} -p1 -F0 < ${GDB}-ppc64le-support.patch ; \
+	patch -d ${GDB} -p1 -F0 < ${GDB}-ppc64le-support.patch ; \
+	if [ -f ${GDB}.series ]; then \
+		while read p; do \
+			patch -d ${GDB} -p1 -F0 < "$$p" ; \
+		done < ${GDB}.series ; \
 	fi

 library: make_build_data ${OBJECT_FILES}


[System]
You are a security patch backporting assistant for SUSE/openSUSE.

Given a CVE description and an upstream fix, adapt the patch to work with
the target SUSE package version. Output the backported patch in unified
diff format. If the upstream fix applies directly, output it unchanged.

[User]
## CVE: CVE-2018-5383

Version 16.242414.0

## Package
kernel-firmware

## Upstream Fix
```diff
--- kernel-firmware-20170530.old/WHENCE	2017-05-30 21:23:02.000000000 +0200
+++ kernel-firmware-20170530/WHENCE	2017-11-15 14:53:05.255112317 +0100
@@ -861,7 +861,7 @@
 Version 16.242414.0

 File: iwlwifi-7260-17.ucode
-Version 17.459231.0
+Version 17.608620.0

 File: iwlwifi-3160-7.ucode
 Version: 22.1.7.0
@@ -885,7 +885,7 @@
 Version 16.242414.0

 File: iwlwifi-3160-17.ucode
-Version 17.459231.0
+Version 17.608620.0

 File: iwlwifi-7265-8.ucode
 Version: 22.24.8.0
@@ -906,7 +906,7 @@
 Version 16.242414.0

 File: iwlwifi-7265-17.ucode
-Version 17.459231.0
+Version 17.608620.0

 File: iwlwifi-7265D-10.ucode
 Version: 23.15.10.0

```

Generate a backported patch for the SUSE target version.

[Assistant]
--- kernel-firmware-20170530.old/WHENCE	2017-05-30 21:23:02.000000000 +0200
+++ kernel-firmware-20170530/WHENCE	2017-11-15 14:53:05.255112317 +0100
@@ -861,7 +861,7 @@
 Version 16.242414.0

 File: iwlwifi-7260-17.ucode
-Version 17.459231.0
+Version 17.608620.0

 File: iwlwifi-3160-7.ucode
 Version: 22.1.7.0
@@ -885,7 +885,7 @@
 Version 16.242414.0

 File: iwlwifi-3160-17.ucode
-Version 17.459231.0
+Version 17.608620.0

 File: iwlwifi-7265-8.ucode
 Version: 22.24.8.0
@@ -906,7 +906,7 @@
 Version 16.242414.0

 File: iwlwifi-7265-17.ucode
-Version 17.459231.0
+Version 17.608620.0

 File: iwlwifi-7265D-10.ucode
 Version: 23.15.10.0