[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: David Mair <dmair@suse.com>

## Package
crash

## Files to modify
- Makefile

## Upstream Fix
```diff
From: David Mair <dmair@suse.com>
Date: 2017-03-28 17:17:25.532260682 -0600
Subject: Add application of GLIBC proc_service prototype cleanup from upstream
References: bnc#1029318 bnc#1022962
Upstream: tbd (crash); merged (gdb)

crash source nests gdb source but crash/gdb has a newly seen build error on
some cases due to a "cause" and a new build environment. The cause is that the
function prototype for extern ps_get_thread_area() in GLIBC/proc_service has a
non-const first argument but implementations in crash's gdb have a const first
argument. Then gcc considers the definition as for a different function from
the declaration (conflicting types for 'ps_get_thread_area').

The fix is in upstream gdb (current):

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=commitdiff;h=754653a7c0a43a668a38aa30c4063b9e292a19f9

...but not upstream crash's gdb (older).

Created crash patch:

crash-gdb-add-proc_service-sync-with-GLIBC.patch

...to create a context fixed version of the gdb patch in expanded crash and
added it's application to the gdb Makefile patch. Note that "fixed" means
making it applicable to the older version of gdb in crash rather than the gdb
version the upstream gdb patch was intended for. Resolves the build error
causes I'm aware of.

I will make a public submission to crash upstream right away but there it will
probably be of the nested content rather than this patch of a patch. Upstream
generates the source tarball and the method used here was to avoid creating a
unique case of the source tarball containing the patch.

---
 Makefile |    1 +
 gdb-7.6-sync-proc_service-definition-with-GLIBC.patch | 277 +++++++++++++++++++
 2 file changed, 278 insertions(+)

--- a/Makefile
+++ b/Makefile
@@ -263,8 +263,9 @@ gdb_unzip:
 gdb_patch:
 	if [ -f ${GDB}.patch ] && [ -s ${GDB}.patch ]; then \
 		patch -p0 < ${GDB}.patch; cp ${GDB}.patch ${GDB}; fi
 	patch -d ${GDB} -p1 -F0 < ${GDB}-ppc64le-support.patch ; \
+	patch -d ${GDB} -p1 -F0 < ${GDB}-sync-proc_service-definition-with-GLIBC.patch ; \
 	if [ -f ${GDB}.series ]; then \
 		while read p; do \
 			patch -d ${GDB} -p1 -F0 < "$$p" ; \
 		done < ${GDB}.series ; \
--- /dev/null
+++ b/gdb-7.6-sync-proc_service-definition-with-GLIBC.patch
@@ -0,0 +1,277 @@
+From 754653a7c0a43a668a38aa30c4063b9e292a19f9 Mon Sep 17 00:00:00 2001
+From: Adhemerval Zanella <adhemerval.zanella@linaro.org>
+Date: Thu, 25 Aug 2016 08:42:03 +0100
+Subject: [PATCH] Sync proc_service definition with GLIBC
+
+GLIBC BZ#20311 [1] proc_service.h install patch also remove 'const'
+attributes from ps_get_thread_area and comment #15 discuss why to remove
+the const attribute (basically since it a callback with the struct
+ps_prochandle owned by the client it should be able to modify it if
+it the case).
+
+On default build this is not the issue and current g++ does not trigger
+any issue with this mismatch declaration.  However, on some bootstrap
+build configuration where gdbserver is build with gcc instead this
+triggers:
+
+error: conflicting types for 'ps_get_thread_area'
+
+This patch fixes it by syncing the declaration with GLIBC.
+
+[1] https://sourceware.org/bugzilla/show_bug.cgi?id=20311
+
+gdb/ChangeLog:
+
+2016-08-25  Adhemerval Zanella  <adhemerval.zanella@linaro.org>
+
+	* aarch64-linux-nat.c (ps_get_thread_area): Remove const from
+	struct ps_prochandle.
+	* amd64-linux-nat.c (ps_get_thread_area): Likewise.
+	* arm-linux-nat.c (ps_get_thread_area): Likewise.
+	* gdb_proc_service.h (ps_get_thread_area): Likewise.
+	* i386-linux-nat.c (ps_get_thread_area): Likewise.
+	* m68klinux-nat.c (ps_get_thread_area): Likewise.
+	* mips-linux-nat.c (ps_get_thread_area): Likewise.
+
+gdb/gdbserver/ChangeLog:
+
+2016-08-25  Adhemerval Zanella  <adhemerval.zanella@linaro.org>
+
+	PR server/20491
+	* gdb_proc_service.h (ps_get_thread_area): Remove const from struct
+	ps_prochandle.
+	* linux-aarch64-low.c (ps_get_thread_area): Likewise.
+	* linux-arm-low.c (ps_get_thread_area): Likewise.
+	* linux-m68k-low.c (ps_get_thread_area): Likewise.
+	* linux-mips-low.c (ps_get_thread_area): Likewise.
+	* linux-tic6x-low.c (ps_get_thread_area): Likewise.
+	* linux-x86-low.c (ps_get_thread_area): Likewise.
+---
+ gdb/ChangeLog                     | 14 ++++++++++++++
+ gdb/aarch64-linux-nat.c           |  2 +-
+ gdb/amd64-linux-nat.c             |  2 +-
+ gdb/arm-linux-nat.c               |  2 +-
+ gdb/gdb_proc_service.h            |  2 +-
+ gdb/gdbserver/ChangeLog           | 15 +++++++++++++++
+ gdb/gdbserver/linux-aarch64-low.c |  2 +-
+ gdb/gdbserver/linux-arm-low.c     |  2 +-
+ gdb/gdbserver/linux-m68k-low.c    |  2 +-
+ gdb/gdbserver/linux-mips-low.c    |  2 +-
+ gdb/gdbserver/linux-tic6x-low.c   |  2 +-
+ gdb/gdbserver/linux-x86-low.c     |  2 +-
+ gdb/i386-linux-nat.c              |  2 +-
+ gdb/m68klinux-nat.c               |  2 +-
+ gdb/mips-linux-nat.c              |  2 +-
+ 17 files changed, 44 insertions(+), 15 deletions(-)
+
+diff --git a/gdb/ChangeLog b/gdb/ChangeLog
+index 0d875c8..677ed7d 100644
+--- a/gdb/ChangeLog
++++ b/gdb/ChangeLog
+@@ -1,3 +1,14 @@
++2016-08-25  Adhemerval Zanella  <adhemerval.zanella@linaro.org>
++
++	* aarch64-linux-nat.c (ps_get_thread_area): Remove const from
++	struct ps_prochandle.
++	* amd64-linux-nat.c (ps_get_thread_area): Likewise.
++	* arm-linux-nat.c (ps_get_thread_area): Likewise.
++	* gdb_proc_service.h (ps_get_thread_area): Likewise.
++	* i386-linux-nat.c (ps_get_thread_area): Likewise.
++	* m68klinux-nat.c (ps_get_thread_area): Likewise.
++	* mips-linux-nat.c (ps_get_thread_area): Likewise.
++
+ 2013-11-15  Alan Modra  <amodra@gmail.com>
+
+ 	* ppc64-tdep.c (ppc64_plt_entry_point): Renamed from..
+diff --git a/gdb/aarch64-linux-nat.c b/gdb/aarch64-linux-nat.c
+index e431637..65ca8ff 100644
+--- a/gdb/aarch64-linux-nat.c
++++ b/gdb/aarch64-linux-nat.c
+@@ -750,7 +750,7 @@ aarch64_linux_new_fork (struct lwp_info *parent, pid_t child_pid)
+    storage (or its descriptor).  */
+
+ ps_err_e
+-ps_get_thread_area (const struct ps_prochandle *ph,
++ps_get_thread_area (struct ps_prochandle *ph,
+ 		    lwpid_t lwpid, int idx, void **base)
+ {
+   struct iovec iovec;
+diff --git a/gdb/amd64-linux-nat.c b/gdb/amd64-linux-nat.c
+index fea6ee2..5122b04 100644
+--- a/gdb/amd64-linux-nat.c
++++ b/gdb/amd64-linux-nat.c
+@@ -493,7 +493,7 @@ amd64_linux_store_inferior_registers (struct target_ops *ops,
+    a request for a thread's local storage address.  */
+
+ ps_err_e
+-ps_get_thread_area (const struct ps_prochandle *ph,
++ps_get_thread_area (struct ps_prochandle *ph,
+                     lwpid_t lwpid, int idx, void **base)
+ {
+   if (gdbarch_bfd_arch_info (target_gdbarch ())->bits_per_word == 32)
+diff --git a/gdb/arm-linux-nat.c b/gdb/arm-linux-nat.c
+index d77ca93..d11bdc6 100644
+--- a/gdb/arm-linux-nat.c
++++ b/gdb/arm-linux-nat.c
+@@ -613,7 +613,7 @@ supply_fpregset (struct regcache *regcache, const gdb_fpregset_t *fpregsetp)
+ /* Fetch the thread-local storage pointer for libthread_db.  */
+
+ ps_err_e
+-ps_get_thread_area (const struct ps_prochandle *ph,
++ps_get_thread_area (struct ps_prochandle *ph,
+                     lwpid_t lwpid, int idx, void **base)
+ {
+   if (ptrace (PTRACE_GET_THREAD_AREA, lwpid, NULL, base) != 0)
+diff --git a/gdb/gdb_proc_service.h b/gdb/gdb_proc_service.h
+index 38b98fc..0a9f26d 100644
+--- a/gdb/gdb_proc_service.h
++++ b/gdb/gdb_proc_service.h
+@@ -115,7 +115,7 @@ extern pid_t ps_getpid (struct ps_prochandle *);
+ /* Fetch the special per-thread address associated with the given LWP.
+    This call is only used on a few platforms (most use a normal register).
+    The meaning of the `int' parameter is machine-dependent.  */
+-extern ps_err_e ps_get_thread_area (const struct ps_prochandle *,
++extern ps_err_e ps_get_thread_area (struct ps_prochandle *,
+ 				    lwpid_t, int, psaddr_t *);
+
+
+diff --git a/gdb/gdbserver/ChangeLog b/gdb/gdbserver/ChangeLog
+index c28c2cb..af0140f 100644
+--- a/gdb/gdbserver/ChangeLog
++++ b/gdb/gdbserver/ChangeLog
+@@ -1,3 +1,15 @@
++2016-08-25  Adhemerval Zanella  <adhemerval.zanella@linaro.org>
++
++	PR server/20491
++	* gdb_proc_service.h (ps_get_thread_area): Remove const from struct
++	ps_prochandle.
++	* linux-aarch64-low.c (ps_get_thread_area): Likewise.
++	* linux-arm-low.c (ps_get_thread_area): Likewise.
++	* linux-m68k-low.c (ps_get_thread_area): Likewise.
++	* linux-mips-low.c (ps_get_thread_area): Likewise.
++	* linux-tic6x-low.c (ps_get_thread_area): Likewise.
++	* linux-x86-low.c (ps_get_thread_area): Likewise.
++
+ 2013-04-25  Hui Zhu  <hui@codesourcery.com>
+
+ 	PR gdb/15186
+diff --git a/gdb/gdbserver/linux-aarch64-low.c b/gdb/gdbserver/linux-aarch64-low.c
+index 6efa035..e54a8ba 100644
+--- a/gdb/gdbserver/linux-aarch64-low.c
++++ b/gdb/gdbserver/linux-aarch64-low.c
+@@ -1089,7 +1089,7 @@ aarch64_stopped_by_watchpoint (void)
+ /* Fetch the thread-local storage pointer for libthread_db.  */
+
+ ps_err_e
+-ps_get_thread_area (const struct ps_prochandle *ph,
++ps_get_thread_area (struct ps_prochandle *ph,
+ 		    lwpid_t lwpid, int idx, void **base)
+ {
+   struct iovec iovec;
+diff --git a/gdb/gdbserver/linux-arm-low.c b/gdb/gdbserver/linux-arm-low.c
+index e1261e5..ed9b356 100644
+--- a/gdb/gdbserver/linux-arm-low.c
++++ b/gdb/gdbserver/linux-arm-low.c
+@@ -325,7 +325,7 @@ get_next_pcs_read_memory_unsigned_integer (CORE_ADDR memaddr,
+ /* Fetch the thread-local storage pointer for libthread_db.  */
+
+ ps_err_e
+-ps_get_thread_area (const struct ps_prochandle *ph,
++ps_get_thread_area (struct ps_prochandle *ph,
+ 		    lwpid_t lwpid, int idx, void **base)
+ {
+   if (ptrace (PTRACE_GET_THREAD_AREA, lwpid, NULL, base) != 0)
+diff --git a/gdb/gdbserver/linux-m68k-low.c b/gdb/gdbserver/linux-m68k-low.c
+index df3d7c6..78a340f 100644
+--- a/gdb/gdbserver/linux-m68k-low.c
++++ b/gdb/gdbserver/linux-m68k-low.c
+@@ -159,7 +159,7 @@ m68k_breakpoint_at (CORE_ADDR pc)
+ /* Fetch the thread-local storage pointer for libthread_db.  */
+
+ ps_err_e
+-ps_get_thread_area (const struct ps_prochandle *ph,
++ps_get_thread_area (struct ps_prochandle *ph,
+ 		    lwpid_t lwpid, int idx, void **base)
+ {
+   if (ptrace (PTRACE_GET_THREAD_AREA, lwpid, NULL, base) != 0)
+diff --git a/gdb/gdbserver/linux-mips-low.c b/gdb/gdbserver/linux-mips-low.c
+index 30a03d5..9356bb3 100644
+--- a/gdb/gdbserver/linux-mips-low.c
++++ b/gdb/gdbserver/linux-mips-low.c
+@@ -238,7 +238,7 @@ mips_stopped_data_address (void)
+ /* Fetch the thread-local storage pointer for libthread_db.  */
+
+ ps_err_e
+-ps_get_thread_area (const struct ps_prochandle *ph,
++ps_get_thread_area (struct ps_prochandle *ph,
+ 		    lwpid_t lwpid, int idx, void **base)
+ {
+   if (ptrace (PTRACE_GET_THREAD_AREA, lwpid, NULL, base) != 0)
+diff --git a/gdb/gdbserver/linux-tic6x-low.c b/gdb/gdbserver/linux-tic6x-low.c
+index e40a3af..6b90560 100644
+--- a/gdb/gdbserver/linux-tic6x-low.c
++++ b/gdb/gdbserver/linux-tic6x-low.c
+@@ -256,7 +256,7 @@ tic6x_breakpoint_at (CORE_ADDR where)
+ /* Fetch the thread-local storage pointer for libthread_db.  */
+
+ ps_err_e
+-ps_get_thread_area (const struct ps_prochandle *ph,
++ps_get_thread_area (struct ps_prochandle *ph,
+ 		    lwpid_t lwpid, int idx, void **base)
+ {
+   if (ptrace (PTRACE_GET_THREAD_AREA, lwpid, NULL, base) != 0)
+diff --git a/gdb/gdbserver/linux-x86-low.c b/gdb/gdbserver/linux-x86-low.c
+index d847b93..acded1a 100644
+--- a/gdb/gdbserver/linux-x86-low.c
++++ b/gdb/gdbserver/linux-x86-low.c
+@@ -164,7 +164,7 @@ is_64bit_tdesc (void)
+ /* Called by libthread_db.  */
+
+ ps_err_e
+-ps_get_thread_area (const struct ps_prochandle *ph,
++ps_get_thread_area (struct ps_prochandle *ph,
+ 		    lwpid_t lwpid, int idx, void **base)
+ {
+ #ifdef __x86_64__
+diff --git a/gdb/i386-linux-nat.c b/gdb/i386-linux-nat.c
+index a41ee21..70d954f 100644
+--- a/gdb/i386-linux-nat.c
++++ b/gdb/i386-linux-nat.c
+@@ -849,7 +849,7 @@ i386_linux_new_fork (struct lwp_info *parent, pid_t child_pid)
+    storage (or its descriptor).  */
+
+ ps_err_e
+-ps_get_thread_area (const struct ps_prochandle *ph,
++ps_get_thread_area (struct ps_prochandle *ph,
+ 		    lwpid_t lwpid, int idx, void **base)
+ {
+   /* NOTE: cagney/2003-08-26: The definition of this buffer is found
+diff --git a/gdb/m68klinux-nat.c b/gdb/m68klinux-nat.c
+index 24b6242..5b8684b 100644
+--- a/gdb/m68klinux-nat.c
++++ b/gdb/m68klinux-nat.c
+@@ -568,7 +568,7 @@ m68k_linux_store_inferior_registers (struct target_ops *ops,
+ /* Fetch the thread-local storage pointer for libthread_db.  */
+
+ ps_err_e
+-ps_get_thread_area (const struct ps_prochandle *ph,
++ps_get_thread_area (struct ps_prochandle *ph,
+ 		    lwpid_t lwpid, int idx, void **base)
+ {
+   if (ptrace (PTRACE_GET_THREAD_AREA, lwpid, NULL, base) < 0)
+diff --git a/gdb/mips-linux-nat.c b/gdb/mips-linux-nat.c
+index bfe9fcb..0f20f16 100644
+--- a/gdb/mips-linux-nat.c
++++ b/gdb/mips-linux-nat.c
+@@ -154,7 +154,7 @@ mips64_linux_register_addr (struct gdbarch *gdbarch, int regno, int store)
+ /* Fetch the thread-local storage pointer for libthread_db.  */
+
+ ps_err_e
+-ps_get_thread_area (const struct ps_prochandle *ph,
++ps_get_thread_area (struct ps_prochandle *ph,
+                     lwpid_t lwpid, int idx, void **base)
+ {
+   if (ptrace (PTRACE_GET_THREAD_AREA, lwpid, NULL, base) != 0)
+--
+2.9.3
+

```

Generate a backported patch for the SUSE target version.

[Assistant]
From: David Mair <dmair@suse.com>
Date: 2017-03-28 17:17:25.532260682 -0600
Subject: Add application of GLIBC proc_service prototype cleanup from upstream
References: bnc#1029318 bnc#1022962
Upstream: tbd (crash); merged (gdb)

crash source nests gdb source but crash/gdb has a newly seen build error on
some cases due to a "cause" and a new build environment. The cause is that the
function prototype for extern ps_get_thread_area() in GLIBC/proc_service has a
non-const first argument but implementations in crash's gdb have a const first
argument. Then gcc considers the definition as for a different function from
the declaration (conflicting types for 'ps_get_thread_area').

The fix is in upstream gdb (current):

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=commitdiff;h=754653a7c0a43a668a38aa30c4063b9e292a19f9

...but not upstream crash's gdb (older).

Created crash patch:

crash-gdb-add-proc_service-sync-with-GLIBC.patch

...to create a context fixed version of the gdb patch in expanded crash and
added it's application to the gdb Makefile patch. Note that "fixed" means
making it applicable to the older version of gdb in crash rather than the gdb
version the upstream gdb patch was intended for. Resolves the build error
causes I'm aware of.

I will make a public submission to crash upstream right away but there it will
probably be of the nested content rather than this patch of a patch. Upstream
generates the source tarball and the method used here was to avoid creating a
unique case of the source tarball containing the patch.

---
 Makefile |    1 +
 gdb-7.6-sync-proc_service-definition-with-GLIBC.patch | 277 +++++++++++++++++++
 2 file changed, 278 insertions(+)

--- a/Makefile
+++ b/Makefile
@@ -263,8 +263,9 @@ gdb_unzip:
 gdb_patch:
 	if [ -f ${GDB}.patch ] && [ -s ${GDB}.patch ]; then \
 		patch -p0 < ${GDB}.patch; cp ${GDB}.patch ${GDB}; fi
 	patch -d ${GDB} -p1 -F0 < ${GDB}-ppc64le-support.patch ; \
+	patch -d ${GDB} -p1 -F0 < ${GDB}-sync-proc_service-definition-with-GLIBC.patch ; \
 	if [ -f ${GDB}.series ]; then \
 		while read p; do \
 			patch -d ${GDB} -p1 -F0 < "$$p" ; \
 		done < ${GDB}.series ; \
--- /dev/null
+++ b/gdb-7.6-sync-proc_service-definition-with-GLIBC.patch
@@ -0,0 +1,277 @@
+From 754653a7c0a43a668a38aa30c4063b9e292a19f9 Mon Sep 17 00:00:00 2001
+From: Adhemerval Zanella <adhemerval.zanella@linaro.org>
+Date: Thu, 25 Aug 2016 08:42:03 +0100
+Subject: [PATCH] Sync proc_service definition with GLIBC
+
+GLIBC BZ#20311 [1] proc_service.h install patch also remove 'const'
+attributes from ps_get_thread_area and comment #15 discuss why to remove
+the const attribute (basically since it a callback with the struct
+ps_prochandle owned by the client it should be able to modify it if
+it the case).
+
+On default build this is not the issue and current g++ does not trigger
+any issue with this mismatch declaration.  However, on some bootstrap
+build configuration where gdbserver is build with gcc instead this
+triggers:
+
+error: conflicting types for 'ps_get_thread_area'
+
+This patch fixes it by syncing the declaration with GLIBC.
+
+[1] https://sourceware.org/bugzilla/show_bug.cgi?id=20311
+
+gdb/ChangeLog:
+
+2016-08-25  Adhemerval Zanella  <adhemerval.zanella@linaro.org>
+
+	* aarch64-linux-nat.c (ps_get_thread_area): Remove const from
+	struct ps_prochandle.
+	* amd64-linux-nat.c (ps_get_thread_area): Likewise.
+	* arm-linux-nat.c (ps_get_thread_area): Likewise.
+	* gdb_proc_service.h (ps_get_thread_area): Likewise.
+	* i386-linux-nat.c (ps_get_thread_area): Likewise.
+	* m68klinux-nat.c (ps_get_thread_area): Likewise.
+	* mips-linux-nat.c (ps_get_thread_area): Likewise.
+
+gdb/gdbserver/ChangeLog:
+
+2016-08-25  Adhemerval Zanella  <adhemerval.zanella@linaro.org>
+
+	PR server/20491
+	* gdb_proc_service.h (ps_get_thread_area): Remove const from struct
+	ps_prochandle.
+	* linux-aarch64-low.c (ps_get_thread_area): Likewise.
+	* linux-arm-low.c (ps_get_thread_area): Likewise.
+	* linux-m68k-low.c (ps_get_thread_area): Likewise.
+	* linux-mips-low.c (ps_get_thread_area): Likewise.
+	* linux-tic6x-low.c (ps_get_thread_area): Likewise.
+	* linux-x86-low.c (ps_get_thread_area): Likewise.
+---
+ gdb/ChangeLog                     | 14 ++++++++++++++
+ gdb/aarch64-linux-nat.c           |  2 +-
+ gdb/amd64-linux-nat.c             |  2 +-
+ gdb/arm-linux-nat.c               |  2 +-
+ gdb/gdb_proc_service.h            |  2 +-
+ gdb/gdbserver/ChangeLog           | 15 +++++++++++++++
+ gdb/gdbserver/linux-aarch64-low.c |  2 +-
+ gdb/gdbserver/linux-arm-low.c     |  2 +-
+ gdb/gdbserver/linux-m68k-low.c    |  2 +-
+ gdb/gdbserver/linux-mips-low.c    |  2 +-
+ gdb/gdbserver/linux-tic6x-low.c   |  2 +-
+ gdb/gdbserver/linux-x86-low.c     |  2 +-
+ gdb/i386-linux-nat.c              |  2 +-
+ gdb/m68klinux-nat.c               |  2 +-
+ gdb/mips-linux-nat.c              |  2 +-
+ 17 files changed, 44 insertions(+), 15 deletions(-)
+
+diff --git a/gdb/ChangeLog b/gdb/ChangeLog
+index 0d875c8..677ed7d 100644
+--- a/gdb/ChangeLog
++++ b/gdb/ChangeLog
+@@ -1,3 +1,14 @@
++2016-08-25  Adhemerval Zanella  <adhemerval.zanella@linaro.org>
++
++	* aarch64-linux-nat.c (ps_get_thread_area): Remove const from
++	struct ps_prochandle.
++	* amd64-linux-nat.c (ps_get_thread_area): Likewise.
++	* arm-linux-nat.c (ps_get_thread_area): Likewise.
++	* gdb_proc_service.h (ps_get_thread_area): Likewise.
++	* i386-linux-nat.c (ps_get_thread_area): Likewise.
++	* m68klinux-nat.c (ps_get_thread_area): Likewise.
++	* mips-linux-nat.c (ps_get_thread_area): Likewise.
++
+ 2013-11-15  Alan Modra  <amodra@gmail.com>
+
+ 	* ppc64-tdep.c (ppc64_plt_entry_point): Renamed from..
+diff --git a/gdb/aarch64-linux-nat.c b/gdb/aarch64-linux-nat.c
+index e431637..65ca8ff 100644
+--- a/gdb/aarch64-linux-nat.c
++++ b/gdb/aarch64-linux-nat.c
+@@ -750,7 +750,7 @@ aarch64_linux_new_fork (struct lwp_info *parent, pid_t child_pid)
+    storage (or its descriptor).  */
+
+ ps_err_e
+-ps_get_thread_area (const struct ps_prochandle *ph,
++ps_get_thread_area (struct ps_prochandle *ph,
+ 		    lwpid_t lwpid, int idx, void **base)
+ {
+   struct iovec iovec;
+diff --git a/gdb/amd64-linux-nat.c b/gdb/amd64-linux-nat.c
+index fea6ee2..5122b04 100644
+--- a/gdb/amd64-linux-nat.c
++++ b/gdb/amd64-linux-nat.c
+@@ -493,7 +493,7 @@ amd64_linux_store_inferior_registers (struct target_ops *ops,
+    a request for a thread's local storage address.  */
+
+ ps_err_e
+-ps_get_thread_area (const struct ps_prochandle *ph,
++ps_get_thread_area (struct ps_prochandle *ph,
+                     lwpid_t lwpid, int idx, void **base)
+ {
+   if (gdbarch_bfd_arch_info (target_gdbarch ())->bits_per_word == 32)
+diff --git a/gdb/arm-linux-nat.c b/gdb/arm-linux-nat.c
+index d77ca93..d11bdc6 100644
+--- a/gdb/arm-linux-nat.c
++++ b/gdb/arm-linux-nat.c
+@@ -613,7 +613,7 @@ supply_fpregset (struct regcache *regcache, const gdb_fpregset_t *fpregsetp)
+ /* Fetch the thread-local storage pointer for libthread_db.  */
+
+ ps_err_e
+-ps_get_thread_area (const struct ps_prochandle *ph,
++ps_get_thread_area (struct ps_prochandle *ph,
+                     lwpid_t lwpid, int idx, void **base)
+ {
+   if (ptrace (PTRACE_GET_THREAD_AREA, lwpid, NULL, base) != 0)
+diff --git a/gdb/gdb_proc_service.h b/gdb/gdb_proc_service.h
+index 38b98fc..0a9f26d 100644
+--- a/gdb/gdb_proc_service.h
++++ b/gdb/gdb_proc_service.h
+@@ -115,7 +115,7 @@ extern pid_t ps_getpid (struct ps_prochandle *);
+ /* Fetch the special per-thread address associated with the given LWP.
+    This call is only used on a few platforms (most use a normal register).
+    The meaning of the `int' parameter is machine-dependent.  */
+-extern ps_err_e ps_get_thread_area (const struct ps_prochandle *,
++extern ps_err_e ps_get_thread_area (struct ps_prochandle *,
+ 				    lwpid_t, int, psaddr_t *);
+
+
+diff --git a/gdb/gdbserver/ChangeLog b/gdb/gdbserver/ChangeLog
+index c28c2cb..af0140f 100644
+--- a/gdb/gdbserver/ChangeLog
++++ b/gdb/gdbserver/ChangeLog
+@@ -1,3 +1,15 @@
++2016-08-25  Adhemerval Zanella  <adhemerval.zanella@linaro.org>
++
++	PR server/20491
++	* gdb_proc_service.h (ps_get_thread_area): Remove const from struct
++	ps_prochandle.
++	* linux-aarch64-low.c (ps_get_thread_area): Likewise.
++	* linux-arm-low.c (ps_get_thread_area): Likewise.
++	* linux-m68k-low.c (ps_get_thread_area): Likewise.
++	* linux-mips-low.c (ps_get_thread_area): Likewise.
++	* linux-tic6x-low.c (ps_get_thread_area): Likewise.
++	* linux-x86-low.c (ps_get_thread_area): Likewise.
++
+ 2013-04-25  Hui Zhu  <hui@codesourcery.com>
+
+ 	PR gdb/15186
+diff --git a/gdb/gdbserver/linux-aarch64-low.c b/gdb/gdbserver/linux-aarch64-low.c
+index 6efa035..e54a8ba 100644
+--- a/gdb/gdbserver/linux-aarch64-low.c
++++ b/gdb/gdbserver/linux-aarch64-low.c
+@@ -1089,7 +1089,7 @@ aarch64_stopped_by_watchpoint (void)
+ /* Fetch the thread-local storage pointer for libthread_db.  */
+
+ ps_err_e
+-ps_get_thread_area (const struct ps_prochandle *ph,
++ps_get_thread_area (struct ps_prochandle *ph,
+ 		    lwpid_t lwpid, int idx, void **base)
+ {
+   struct iovec iovec;
+diff --git a/gdb/gdbserver/linux-arm-low.c b/gdb/gdbserver/linux-arm-low.c
+index e1261e5..ed9b356 100644
+--- a/gdb/gdbserver/linux-arm-low.c
++++ b/gdb/gdbserver/linux-arm-low.c
+@@ -325,7 +325,7 @@ get_next_pcs_read_memory_unsigned_integer (CORE_ADDR memaddr,
+ /* Fetch the thread-local storage pointer for libthread_db.  */
+
+ ps_err_e
+-ps_get_thread_area (const struct ps_prochandle *ph,
++ps_get_thread_area (struct ps_prochandle *ph,
+ 		    lwpid_t lwpid, int idx, void **base)
+ {
+   if (ptrace (PTRACE_GET_THREAD_AREA, lwpid, NULL, base) != 0)
+diff --git a/gdb/gdbserver/linux-m68k-low.c b/gdb/gdbserver/linux-m68k-low.c
+index df3d7c6..78a340f 100644
+--- a/gdb/gdbserver/linux-m68k-low.c
++++ b/gdb/gdbserver/linux-m68k-low.c
+@@ -159,7 +159,7 @@ m68k_breakpoint_at (CORE_ADDR pc)
+ /* Fetch the thread-local storage pointer for libthread_db.  */
+
+ ps_err_e
+-ps_get_thread_area (const struct ps_prochandle *ph,
++ps_get_thread_area (struct ps_prochandle *ph,
+ 		    lwpid_t lwpid, int idx, void **base)
+ {
+   if (ptrace (PTRACE_GET_THREAD_AREA, lwpid, NULL, base) != 0)
+diff --git a/gdb/gdbserver/linux-mips-low.c b/gdb/gdbserver/linux-mips-low.c
+index 30a03d5..9356bb3 100644
+--- a/gdb/gdbserver/linux-mips-low.c
++++ b/gdb/gdbserver/linux-mips-low.c
+@@ -238,7 +238,7 @@ mips_stopped_data_address (void)
+ /* Fetch the thread-local storage pointer for libthread_db.  */
+
+ ps_err_e
+-ps_get_thread_area (const struct ps_prochandle *ph,
++ps_get_thread_area (struct ps_prochandle *ph,
+ 		    lwpid_t lwpid, int idx, void **base)
+ {
+   if (ptrace (PTRACE_GET_THREAD_AREA, lwpid, NULL, base) != 0)
+diff --git a/gdb/gdbserver/linux-tic6x-low.c b/gdb/gdbserver/linux-tic6x-low.c
+index e40a3af..6b90560 100644
+--- a/gdb/gdbserver/linux-tic6x-low.c
++++ b/gdb/gdbserver/linux-tic6x-low.c
+@@ -256,7 +256,7 @@ tic6x_breakpoint_at (CORE_ADDR where)
+ /* Fetch the thread-local storage pointer for libthread_db.  */
+
+ ps_err_e
+-ps_get_thread_area (const struct ps_prochandle *ph,
++ps_get_thread_area (struct ps_prochandle *ph,
+ 		    lwpid_t lwpid, int idx, void **base)
+ {
+   if (ptrace (PTRACE_GET_THREAD_AREA, lwpid, NULL, base) != 0)
+diff --git a/gdb/gdbserver/linux-x86-low.c b/gdb/gdbserver/linux-x86-low.c
+index d847b93..acded1a 100644
+--- a/gdb/gdbserver/linux-x86-low.c
++++ b/gdb/gdbserver/linux-x86-low.c
+@@ -164,7 +164,7 @@ is_64bit_tdesc (void)
+ /* Called by libthread_db.  */
+
+ ps_err_e
+-ps_get_thread_area (const struct ps_prochandle *ph,
++ps_get_thread_area (struct ps_prochandle *ph,
+ 		    lwpid_t lwpid, int idx, void **base)
+ {
+ #ifdef __x86_64__
+diff --git a/gdb/i386-linux-nat.c b/gdb/i386-linux-nat.c
+index a41ee21..70d954f 100644
+--- a/gdb/i386-linux-nat.c
++++ b/gdb/i386-linux-nat.c
+@@ -849,7 +849,7 @@ i386_linux_new_fork (struct lwp_info *parent, pid_t child_pid)
+    storage (or its descriptor).  */
+
+ ps_err_e
+-ps_get_thread_area (const struct ps_prochandle *ph,
++ps_get_thread_area (struct ps_prochandle *ph,
+ 		    lwpid_t lwpid, int idx, void **base)
+ {
+   /* NOTE: cagney/2003-08-26: The definition of this buffer is found
+diff --git a/gdb/m68klinux-nat.c b/gdb/m68klinux-nat.c
+index 24b6242..5b8684b 100644
+--- a/gdb/m68klinux-nat.c
++++ b/gdb/m68klinux-nat.c
+@@ -568,7 +568,7 @@ m68k_linux_store_inferior_registers (struct target_ops *ops,
+ /* Fetch the thread-local storage pointer for libthread_db.  */
+
+ ps_err_e
+-ps_get_thread_area (const struct ps_prochandle *ph,
++ps_get_thread_area (struct ps_prochandle *ph,
+ 		    lwpid_t lwpid, int idx, void **base)
+ {
+   if (ptrace (PTRACE_GET_THREAD_AREA, lwpid, NULL, base) < 0)
+diff --git a/gdb/mips-linux-nat.c b/gdb/mips-linux-nat.c
+index bfe9fcb..0f20f16 100644
+--- a/gdb/mips-linux-nat.c
++++ b/gdb/mips-linux-nat.c
+@@ -154,7 +154,7 @@ mips64_linux_register_addr (struct gdbarch *gdbarch, int regno, int store)
+ /* Fetch the thread-local storage pointer for libthread_db.  */
+
+ ps_err_e
+-ps_get_thread_area (const struct ps_prochandle *ph,
++ps_get_thread_area (struct ps_prochandle *ph,
+                     lwpid_t lwpid, int idx, void **base)
+ {
+   if (ptrace (PTRACE_GET_THREAD_AREA, lwpid, NULL, base) != 0)
+--
+2.9.3
+


[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

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;
/* ... 29 lines omitted ... */
	 *  Get gdb version before initializing it since this might be one
         *  of the short-hand commands that need it without running gdb.
	 */
	get_gdb_version();

	/*
	 *  Set up the default scrolling behavior for terminal output.
	 */
	if (isatty(fileno(stdout))) {
		if (CRASHPAGER_valid()) {
			pc->flags |= SCROLL;
			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
	 */
/* ... 45 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(-)

--- a/main.c
+++ b/main.c
@@ -1158,12 +1158,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.
@@ -1213,7 +1207,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(-)

--- a/main.c
+++ b/main.c
@@ -1158,12 +1158,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.
@@ -1213,7 +1207,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-2017-5715

From: Petr Tesarik <ptesarik@suse.cz>

## Package
crash

## Files to modify
- gdb-7.6.patch

## Upstream Fix
```diff
From: Petr Tesarik <ptesarik@suse.cz>
Subject: Add missing includes

This fixes a compilation failure on ppc64.

---
 gdb-7.6.patch |   10 ++++++++++
 1 file changed, 10 insertions(+)

--- a/gdb-7.6.patch
+++ b/gdb-7.6.patch
@@ -17,6 +17,16 @@
  	./pex-djgpp.$(objext) ./pex-msdos.$(objext)			\
  	 ./pex-unix.$(objext) ./pex-win32.$(objext)			\
  	 ./putenv.$(objext)						\
+--- gdb-7.6/sim/common/gentmap.c.orig
++++ gdb-7.6/sim/common/gentmap.c
+@@ -2,6 +2,7 @@
+
+ #include <stdio.h>
+ #include <stdlib.h>
++#include <string.h>
+
+ struct tdefs {
+   char *symbol;
 --- gdb-7.6/opcodes/i386-dis.c.orig
 +++ gdb-7.6/opcodes/i386-dis.c
 @@ -11510,6 +11510,10 @@ print_insn (bfd_vma pc, disassemble_info

```

Generate a backported patch for the SUSE target version.

[Assistant]
From: Petr Tesarik <ptesarik@suse.cz>
Subject: Add missing includes

This fixes a compilation failure on ppc64.

---
 gdb-7.6.patch |   10 ++++++++++
 1 file changed, 10 insertions(+)

--- a/gdb-7.6.patch
+++ b/gdb-7.6.patch
@@ -17,6 +17,16 @@
  	./pex-djgpp.$(objext) ./pex-msdos.$(objext)			\
  	 ./pex-unix.$(objext) ./pex-win32.$(objext)			\
  	 ./putenv.$(objext)						\
+--- gdb-7.6/sim/common/gentmap.c.orig
++++ gdb-7.6/sim/common/gentmap.c
+@@ -2,6 +2,7 @@
+
+ #include <stdio.h>
+ #include <stdlib.h>
++#include <string.h>
+
+ struct tdefs {
+   char *symbol;
 --- gdb-7.6/opcodes/i386-dis.c.orig
 +++ gdb-7.6/opcodes/i386-dis.c
 @@ -11510,6 +11510,10 @@ print_insn (bfd_vma pc, disassemble_info


[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: Hari Krishna Bathini <hbathini@in.ibm.com>

## Package
crash

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

## Target Source Code

### defs.h

#### region() [lines 3788-3894]
```c
	void *mmu_special;
};

/* machdep flags for ppc32 specific */
#define IS_PAE()		(machdep->flags & PAE)
#define IS_BOOKE()		(machdep->flags & CPU_BOOKE)
/* Page translation bits */
#define PPC_PLATFORM		(machdep->machspec->platform)
#define PTE_SIZE		(machdep->machspec->pte_size)
#define PTE_RPN_SHIFT		(machdep->machspec->pte_rpn_shift)
#define PAGE_SHIFT		(12)
#define PTE_T_LOG2		(ffs(PTE_SIZE) - 1)
#define PTE_SHIFT		(PAGE_SHIFT - PTE_T_LOG2)
#define PGDIR_SHIFT		(PAGE_SHIFT + PTE_SHIFT)
#define PTRS_PER_PGD		(1 << (32 - PGDIR_SHIFT))
#define PTRS_PER_PTE		(1 << PTE_SHIFT)
/* special vtop */
#define VTOP_SPECIAL		(machdep->machspec->vtop_special)
#define MMU_SPECIAL		(machdep->machspec->mmu_special)

/* PFN shifts */
#define BOOKE3E_PTE_RPN_SHIFT	(24)

/* PAGE flags */
#define _PAGE_PRESENT   (machdep->machspec->_page_present)	/* software: pte contains a translation */
#define _PAGE_USER      (machdep->machspec->_page_user)		/* matches one of the PP bits */
#define _PAGE_RW        (machdep->machspec->_page_rw)		/* software: user write access allowed */
#define _PAGE_GUARDED   (machdep->machspec->_page_guarded)
#define _PAGE_COHERENT  (machdep->machspec->_page_coherent	/* M: enforce memory coherence (SMP systems) */)
#define _PAGE_NO_CACHE  (machdep->machspec->_page_no_cache)	/* I: cache inhibit */
#define _PAGE_WRITETHRU (machdep->machspec->_page_writethru)	/* W: cache write-through */
#define _PAGE_DIRTY     (machdep->machspec->_page_dirty)	/* C: page changed */
#define _PAGE_ACCESSED  (machdep->machspec->_page_accessed)	/* R: page referenced */
#define _PAGE_HWWRITE   (machdep->machspec->_page_hwwrite)	/* software: _PAGE_RW & _PAGE_DIRTY */
#define _PAGE_SHARED    (machdep->machspec->_page_shared)
#define _PAGE_K_RW	(machdep->machspec->_page_k_rw)		/* privilege only write access allowed */

/* Default values for PAGE flags */
#define DEFAULT_PAGE_PRESENT   0x001
#define DEFAULT_PAGE_USER      0x002
#define DEFAULT_PAGE_RW        0x004
#define DEFAULT_PAGE_GUARDED   0x008
#define DEFAULT_PAGE_COHERENT  0x010
#define DEFAULT_PAGE_NO_CACHE  0x020
#define DEFAULT_PAGE_WRITETHRU 0x040
#define DEFAULT_PAGE_DIRTY     0x080
#define DEFAULT_PAGE_ACCESSED  0x100
#define DEFAULT_PAGE_HWWRITE   0x200
#define DEFAULT_PAGE_SHARED    0

/* PPC44x PAGE flags: Values from kernel asm/pte-44x.h */
#define PPC44x_PAGE_PRESENT	0x001
#define PPC44x_PAGE_RW		0x002
#define PPC44x_PAGE_ACCESSED	0x008
#define PPC44x_PAGE_DIRTY	0x010
#define PPC44x_PAGE_USER	0x040
#define PPC44x_PAGE_GUARDED	0x100
#define PPC44x_PAGE_COHERENT	0x200
#define PPC44x_PAGE_NO_CACHE	0x400
#define PPC44x_PAGE_WRITETHRU	0x800
#define PPC44x_PAGE_HWWRITE	0
#define PPC44x_PAGE_SHARED	0

/* BOOK3E */
#define BOOK3E_PAGE_PRESENT	0x000001
#define BOOK3E_PAGE_BAP_SR	0x000004
#define BOOK3E_PAGE_BAP_UR	0x000008 /* User Readable */
#define BOOK3E_PAGE_BAP_SW	0x000010
#define BOOK3E_PAGE_BAP_UW	0x000020 /* User Writable */
#define BOOK3E_PAGE_DIRTY	0x001000
#define BOOK3E_PAGE_ACCESSED	0x040000
#define BOOK3E_PAGE_GUARDED	0x100000
#define BOOK3E_PAGE_COHERENT	0x200000
#define BOOK3E_PAGE_NO_CACHE	0x400000
#define BOOK3E_PAGE_WRITETHRU	0x800000
#define BOOK3E_PAGE_HWWRITE	0
#define BOOK3E_PAGE_SHARED	0
#define BOOK3E_PAGE_USER	(BOOK3E_PAGE_BAP_SR | BOOK3E_PAGE_BAP_UR)
#define BOOK3E_PAGE_RW		(BOOK3E_PAGE_BAP_SW | BOOK3E_PAGE_BAP_UW)
#define BOOK3E_PAGE_KERNEL_RW	(BOOK3E_PAGE_BAP_SW | BOOK3E_PAGE_BAP_SR | BOOK3E_PAGE_DIRTY)

/* FSL BOOKE */
#define FSL_BOOKE_PAGE_PRESENT	0x00001
#define FSL_BOOKE_PAGE_USER	0x00002
#define FSL_BOOKE_PAGE_RW	0x00004
#define FSL_BOOKE_PAGE_DIRTY	0x00008
#define FSL_BOOKE_PAGE_ACCESSED	0x00020
#define FSL_BOOKE_PAGE_GUARDED	0x00080
#define FSL_BOOKE_PAGE_COHERENT	0x00100
#define FSL_BOOKE_PAGE_NO_CACHE	0x00200
#define FSL_BOOKE_PAGE_WRITETHRU	0x00400
#define FSL_BOOKE_PAGE_HWWRITE	0
#define FSL_BOOKE_PAGE_SHARED	0

#define SWP_TYPE(entry) (((entry) >> 1) & 0x7f)
#define SWP_OFFSET(entry) ((entry) >> 8)
#define __swp_type(entry)   SWP_TYPE(entry)
#define __swp_offset(entry) SWP_OFFSET(entry)

#define TIF_SIGPENDING (2)

#define _SECTION_SIZE_BITS	24
#define _MAX_PHYSMEM_BITS	44

#define STACK_FRAME_OVERHEAD	16
#define STACK_FRAME_LR_SAVE	(sizeof(ulong))
#define STACK_FRAME_MARKER	(2 * sizeof(ulong))
```

#### region() [lines 3806-3912]
```c
#define MMU_SPECIAL		(machdep->machspec->mmu_special)

/* PFN shifts */
#define BOOKE3E_PTE_RPN_SHIFT	(24)

/* PAGE flags */
#define _PAGE_PRESENT   (machdep->machspec->_page_present)	/* software: pte contains a translation */
#define _PAGE_USER      (machdep->machspec->_page_user)		/* matches one of the PP bits */
#define _PAGE_RW        (machdep->machspec->_page_rw)		/* software: user write access allowed */
#define _PAGE_GUARDED   (machdep->machspec->_page_guarded)
#define _PAGE_COHERENT  (machdep->machspec->_page_coherent	/* M: enforce memory coherence (SMP systems) */)
#define _PAGE_NO_CACHE  (machdep->machspec->_page_no_cache)	/* I: cache inhibit */
#define _PAGE_WRITETHRU (machdep->machspec->_page_writethru)	/* W: cache write-through */
#define _PAGE_DIRTY     (machdep->machspec->_page_dirty)	/* C: page changed */
#define _PAGE_ACCESSED  (machdep->machspec->_page_accessed)	/* R: page referenced */
#define _PAGE_HWWRITE   (machdep->machspec->_page_hwwrite)	/* software: _PAGE_RW & _PAGE_DIRTY */
#define _PAGE_SHARED    (machdep->machspec->_page_shared)
#define _PAGE_K_RW	(machdep->machspec->_page_k_rw)		/* privilege only write access allowed */

/* Default values for PAGE flags */
#define DEFAULT_PAGE_PRESENT   0x001
#define DEFAULT_PAGE_USER      0x002
#define DEFAULT_PAGE_RW        0x004
#define DEFAULT_PAGE_GUARDED   0x008
#define DEFAULT_PAGE_COHERENT  0x010
#define DEFAULT_PAGE_NO_CACHE  0x020
#define DEFAULT_PAGE_WRITETHRU 0x040
#define DEFAULT_PAGE_DIRTY     0x080
#define DEFAULT_PAGE_ACCESSED  0x100
#define DEFAULT_PAGE_HWWRITE   0x200
#define DEFAULT_PAGE_SHARED    0

/* PPC44x PAGE flags: Values from kernel asm/pte-44x.h */
#define PPC44x_PAGE_PRESENT	0x001
#define PPC44x_PAGE_RW		0x002
#define PPC44x_PAGE_ACCESSED	0x008
#define PPC44x_PAGE_DIRTY	0x010
#define PPC44x_PAGE_USER	0x040
#define PPC44x_PAGE_GUARDED	0x100
#define PPC44x_PAGE_COHERENT	0x200
#define PPC44x_PAGE_NO_CACHE	0x400
#define PPC44x_PAGE_WRITETHRU	0x800
#define PPC44x_PAGE_HWWRITE	0
#define PPC44x_PAGE_SHARED	0

/* BOOK3E */
#define BOOK3E_PA
/* ... truncated ... */
```

### 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
/* ... 106 lines omitted ... */
			 * bit as it is always set on hash64 and on platforms
			 * that cannot always set it, _PAGE_NO_CACHE and
			 * _PAGE_WRITETHRU  can be used to infer it.
			 */
			if (THIS_KERNEL_VERSION >= LINUX(3,14,0))
				m->_page_coherent = 0x0UL;

			/*
			 * In kernel v4.5, _PAGE_PTE bit is introduced to
			 * distinguish PTEs from pointers.
			 */
			if (THIS_KERNEL_VERSION >= LINUX(4,5,0)) {
				m->_page_pte = 0x1UL;
				m->_page_present = 0x2UL;
				m->_page_user = 0x4UL;
				m->_page_rw = 0x8UL;
				m->_page_guarded = 0x10UL;
			}

			/*
			 * Starting with kernel v4.6, to accommodate both
			 * radix and hash MMU modes in a single kernel,
			 * _PAGE_PTE & _PAGE_PRESENT page flags are changed.
			 * Also, page table entries store physical addresses.
			 */
			if (THIS_KERNEL_VERSION >= LINUX(4,6,0)) {
				m->_page_pte = 0x1UL << 62;
/* ... 228 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
```

### Type definitions

```c
/* from defs.h */
struct efi_memory_desc_t {
        uint32_t type;
        uint32_t pad;
        uint64_t phys_addr;
        uint64_t virt_addr;
        uint64_t num_pages;
        uint64_t attribute;
} desc;
```

## Upstream Fix
```diff
From: Hari Krishna Bathini <hbathini@in.ibm.com>
Subject: book3s/ppc64: update hash page table geometry

Patch-mainline: never, SLE12-SP3 specific

Kernel commit f6eedbba7a26 ("powerpc/mm/hash: Increase VA range to 128TB")
updated hash page table geometry. A modified version of this commit is
included in SLES12 SP3. Make the corresponding changes in crash utility
for analyzing dump appropriately.
---
 defs.h  |    2 ++
 ppc64.c |   10 ++++++++--
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/defs.h b/defs.h
index 0fe8d36..f26f642 100755
--- a/defs.h
+++ b/defs.h
@@ -3837,6 +3837,7 @@ struct efi_memory_desc_t {
 #define PUD_INDEX_SIZE_L4_4K  7
 #define PGD_INDEX_SIZE_L4_4K  9
 #define PUD_INDEX_SIZE_L4_4K_3_7  9
+#define PGD_INDEX_SIZE_L4_4K_4_4_63  12
 #define PTE_INDEX_SIZE_RADIX_4K  9
 #define PMD_INDEX_SIZE_RADIX_4K  9
 #define PUD_INDEX_SIZE_RADIX_4K  9
@@ -3855,6 +3856,7 @@ struct efi_memory_desc_t {
 #define PTE_INDEX_SIZE_L4_64K_3_10  8
 #define PMD_INDEX_SIZE_L4_64K_3_10  10
 #define PGD_INDEX_SIZE_L4_64K_3_10  12
+#define PGD_INDEX_SIZE_L4_64K_4_4_63  15
 #define PMD_INDEX_SIZE_L4_64K_4_6  5
 #define PUD_INDEX_SIZE_L4_64K_4_6  5
 #define PTE_INDEX_SIZE_RADIX_64K  5
diff --git a/ppc64.c b/ppc64.c
index edf46dc..bed4dea 100755
--- a/ppc64.c
+++ b/ppc64.c
@@ -455,7 +455,10 @@ ppc64_init(int when)
 					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;
+					if (THIS_KERNEL_VERSION >= LINUX(4,4,63))
+						m->l4_index_size = PGD_INDEX_SIZE_L4_64K_4_4_63;
+					else
+						m->l4_index_size = PGD_INDEX_SIZE_L4_64K_3_10;

 				} else {
 					m->l1_index_size = PTE_INDEX_SIZE_L4_64K;
@@ -499,7 +502,10 @@ ppc64_init(int when)
 						m->l3_index_size = PUD_INDEX_SIZE_L4_4K_3_7;
 					else
 						m->l3_index_size = PUD_INDEX_SIZE_L4_4K;
-					m->l4_index_size = PGD_INDEX_SIZE_L4_4K;
+					if (THIS_KERNEL_VERSION >= LINUX(4,4,63))
+						m->l4_index_size = PGD_INDEX_SIZE_L4_4K_4_4_63;
+					else
+						m->l4_index_size = PGD_INDEX_SIZE_L4_4K;

 					if (machdep->flags & BOOK3E)
 						m->pte_rpn_shift = PTE_RPN_SHIFT_L4_BOOK3E_4K;

```

Generate a backported patch for the SUSE target version.

[Assistant]
From: Hari Krishna Bathini <hbathini@in.ibm.com>
Subject: book3s/ppc64: update hash page table geometry

Patch-mainline: never, SLE12-SP3 specific

Kernel commit f6eedbba7a26 ("powerpc/mm/hash: Increase VA range to 128TB")
updated hash page table geometry. A modified version of this commit is
included in SLES12 SP3. Make the corresponding changes in crash utility
for analyzing dump appropriately.
---
 defs.h  |    2 ++
 ppc64.c |   10 ++++++++--
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/defs.h b/defs.h
index 0fe8d36..f26f642 100755
--- a/defs.h
+++ b/defs.h
@@ -3837,6 +3837,7 @@ struct efi_memory_desc_t {
 #define PUD_INDEX_SIZE_L4_4K  7
 #define PGD_INDEX_SIZE_L4_4K  9
 #define PUD_INDEX_SIZE_L4_4K_3_7  9
+#define PGD_INDEX_SIZE_L4_4K_4_4_63  12
 #define PTE_INDEX_SIZE_RADIX_4K  9
 #define PMD_INDEX_SIZE_RADIX_4K  9
 #define PUD_INDEX_SIZE_RADIX_4K  9
@@ -3855,6 +3856,7 @@ struct efi_memory_desc_t {
 #define PTE_INDEX_SIZE_L4_64K_3_10  8
 #define PMD_INDEX_SIZE_L4_64K_3_10  10
 #define PGD_INDEX_SIZE_L4_64K_3_10  12
+#define PGD_INDEX_SIZE_L4_64K_4_4_63  15
 #define PMD_INDEX_SIZE_L4_64K_4_6  5
 #define PUD_INDEX_SIZE_L4_64K_4_6  5
 #define PTE_INDEX_SIZE_RADIX_64K  5
diff --git a/ppc64.c b/ppc64.c
index edf46dc..bed4dea 100755
--- a/ppc64.c
+++ b/ppc64.c
@@ -455,7 +455,10 @@ ppc64_init(int when)
 					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;
+					if (THIS_KERNEL_VERSION >= LINUX(4,4,63))
+						m->l4_index_size = PGD_INDEX_SIZE_L4_64K_4_4_63;
+					else
+						m->l4_index_size = PGD_INDEX_SIZE_L4_64K_3_10;

 				} else {
 					m->l1_index_size = PTE_INDEX_SIZE_L4_64K;
@@ -499,7 +502,10 @@ ppc64_init(int when)
 						m->l3_index_size = PUD_INDEX_SIZE_L4_4K_3_7;
 					else
 						m->l3_index_size = PUD_INDEX_SIZE_L4_4K;
-					m->l4_index_size = PGD_INDEX_SIZE_L4_4K;
+					if (THIS_KERNEL_VERSION >= LINUX(4,4,63))
+						m->l4_index_size = PGD_INDEX_SIZE_L4_4K_4_4_63;
+					else
+						m->l4_index_size = PGD_INDEX_SIZE_L4_4K;

 					if (machdep->flags & BOOK3E)
 						m->pte_rpn_shift = PTE_RPN_SHIFT_L4_BOOK3E_4K;


[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

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-2017-5715

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-2017-5715

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

## Package
crash

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

## Target Source Code

### defs.h

#### region() [lines 682-788]
```c
#define XEN_MACHADDR_NOT_FOUND   (~0ULL)

#define XEN_P2M_PER_PAGE	(PAGESIZE() / sizeof(unsigned long))
#define XEN_P2M_MID_PER_PAGE	(PAGESIZE() / sizeof(unsigned long *))
#define XEN_P2M_TOP_PER_PAGE	(PAGESIZE() / sizeof(unsigned long **))

struct kernel_table {                   /* kernel data */
	ulong flags;
	ulong stext;
	ulong etext;
	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:                                                \
```

#### region() [lines 6490-6596]
```c

/* from arch/mips/include/uapi/asm/ptrace.h */
struct mips64_register {
	ulong regs[45];
};

struct mips64_pt_regs_main {
	ulong regs[32];
	ulong cp0_status;
	ulong hi;
	ulong lo;
};

struct mips64_pt_regs_cp0 {
	ulong cp0_badvaddr;
	ulong cp0_cause;
	ulong cp0_epc;
};

struct mips64_unwind_frame {
	unsigned long sp;
	unsigned long pc;
	unsigned long ra;
};

#define KSYMS_START	(0x1)

struct machine_specific {
	ulong phys_base;
	ulong vmalloc_start_addr;
	ulong modules_vaddr;
	ulong modules_end;

	ulong _page_present;
	ulong _page_read;
	ulong _page_write;
	ulong _page_accessed;
	ulong _page_modified;
	ulong _page_huge;
	ulong _page_special;
	ulong _page_protnone;
	ulong _page_global;
	ulong _page_valid;
	ulong _page_no_read;
	ulong _page_no_exec;
	ulong _page_dirty;

	ulong _pfn_shift;

	struct mips64_register *crash_task_regs;
};
/* from arch/mips/include/asm/pgtable-bits.h */
#define _PAGE_PRESENT	(machdep->machspec->_page_present)
#define _PAGE_READ	(machdep->machspec->_page_read)
#define _PAGE_WRITE	(machdep->machspec->_page_write)
#define _PAGE_ACCESSED	(machdep->machspec->_page_accessed)
#define _PAGE_MODIFIED	(machdep->machspec->_page_modified)
#define _PAGE_HUGE	(machdep->machspec->_page_huge)
#define _PAGE_SPECIAL	(machdep->machspec->_page_special)
#define _PAGE_PROTNONE	(machdep->machspec->_page_protnone)
#define _PAGE_GLOBAL	(machdep->machspec->_page_global)
#define _PAGE_VALID	(machdep->machspec->_page_valid)
#define _PAGE_NO_READ	(machdep->machspec->_page_no_read)
#define _PAGE_NO_EXEC	(machdep->machspec->_page_no_exec)
#define _PAGE_DIRTY	(machdep->machspec->_page_dirty)
#define _PFN_SHIFT	(machdep->machspec->_pfn_shift)

#endif /* MIPS64 */

/*
 * sparc64.c
 */
#ifdef SPARC64
void sparc64_init(int);
void sparc64_dump_machdep_table(ulong);
int sparc64_vmalloc_addr(ulong);
#define display_idt_table() \
	error(FATAL, "The -d option is not applicable to sparc64.\n")
#endif

/*
 *  netdump.c
 */
int is_netdump(char *, ulong);
uint netdump_page_size(void);
int read_netdump(int, void *, int, ulong, physaddr_t);
int write_netdump(int, void *, int, ulong, physaddr_t);
int netdump_free_memory(void);
int netdump_memory_used(void);
int netdump_init(char *, FILE *);
ulong get_netdump_panic_task(void);
ulong get_netdump_switch_stack(ulong);
FILE *set_netdump_fp(FILE *);
int netdump_memory_dump(FILE *);
void get_netdump_regs(struct bt_info *, ulong *, ulong *);
int is_partial_netdump(void);
void get_netdump_regs_x86(struct bt_info *, ulong *, ulong *);
void get_netdump_regs_x86_64(struct bt_info *, ulong *, ulong *);
void dump_registers_for_elf_dumpfiles(void);
struct vmcore_data;
struct vmcore_data *get_kdump_vmcore_data(void);
int read_kdump(int, void *, int, ulong, physaddr_t);
int write_kdump(int, void *, int, ulong, physaddr_t);
int is_kdump(char *, ulong);
int kdump_init(char *, FILE *);
ulong get_kdump_panic_task(void);
uint kdump_page_size(void);
```

#### kernel_init() [lines 237-343]
```c
#define LIVE_RAMDUMP         (0x10000000ULL)
#define NAMELIST_SAVED       (0x20000000ULL)
#define DUMPFILE_SAVED       (0x40000000ULL)
#define UNLINK_NAMELIST      (0x80000000ULL)
#define NAMELIST_UNLINKED   (0x100000000ULL)
#define REM_MCLXCD          (0x200000000ULL)
#define REM_LKCD            (0x400000000ULL)
#define NAMELIST_NO_GZIP    (0x800000000ULL)
#define UNLINK_MODULES     (0x1000000000ULL)
#define S390D              (0x2000000000ULL)
#define REM_S390D          (0x4000000000ULL)
#define SYSRQ              (0x8000000000ULL)
#define KDUMP             (0x10000000000ULL)
#define NETDUMP           (0x20000000000ULL)
#define REM_NETDUMP       (0x40000000000ULL)
#define SYSMAP            (0x80000000000ULL)
#define SYSMAP_ARG       (0x100000000000ULL)
#define MEMMOD           (0x200000000000ULL)
#define MODPRELOAD       (0x400000000000ULL)
#define DISKDUMP         (0x800000000000ULL)
#define DATADEBUG       (0x1000000000000ULL)
#define FINDKERNEL      (0x2000000000000ULL)
#define VERSION_QUERY   (0x4000000000000ULL)
#define READNOW         (0x8000000000000ULL)
#define NOCRASHRC      (0x10000000000000ULL)
#define INIT_IFILE     (0x20000000000000ULL)
#define XENDUMP        (0x40000000000000ULL)
#define XEN_HYPER      (0x80000000000000ULL)
#define XEN_CORE      (0x100000000000000ULL)
#define PLEASE_WAIT   (0x200000000000000ULL)
#define IFILE_ERROR   (0x400000000000000ULL)
#define KERNTYPES     (0x800000000000000ULL)
#define MINIMAL_MODE (0x1000000000000000ULL)
#define CRASHBUILTIN (0x2000000000000000ULL)
#define PRELOAD_EXTENSIONS \
		     (0x4000000000000000ULL)
#define PROC_KCORE   (0x8000000000000000ULL)

#define ACTIVE()            (pc->flags & LIVE_SYSTEM)
#define LOCAL_ACTIVE()      ((pc->flags & (LIVE_SYSTEM|LIVE_RAMDUMP)) == LIVE_SYSTEM)
#define DUMPFILE()          (!(pc->flags & LIVE_SYSTEM))
#define LIVE()              (pc->flags2 & LIVE_DUMP || pc->flags & LIVE_SYSTEM)
#define MEMORY_SOURCES (NETDUMP|KDUMP|MCLXCD|LKCD|DEVMEM|S390D|MEMMOD|DISKDUMP|XENDUMP|CRASHBUILTIN|KVMDUMP|PROC_KCORE|SADUMP|VMWARE_VMSS|LIVE_RAMDUMP)
#define DUMPFILE_TYPES      (DISKDUMP|NETDUMP|KDUMP|MCLXCD|LKCD|S390D|XENDUMP|KVMDUMP|SADUMP|VMWARE_VMSS|LIVE_RAMDUMP)
#define REMOTE()            (pc->flags2 & REMOTE_DAEMON)
#define REMOTE_ACTIVE()     (pc->flags & REM_LIVE_SYSTEM)
#define REMOTE_DUMPFILE() \
	   (pc->flags & (REM_NETDUMP|REM_MCLXCD|REM_LKCD|REM_S390D))
#define REMOTE_MEMSRC()     (REMOTE_ACTIVE() || REMOTE_PAUSED() || REMOTE_DUMPFILE())
#define LKCD_DUMPFILE()     (pc->flags & (LKCD|REM_LKCD))
#define NETDUMP_DUMPFILE()  (pc->flags & (NETDUMP|REM_NETDUMP))
#define DISKDUMP_DUMPFILE() (pc->flags & DISKDUMP)
#define KDUMP_DUMPFILE()    (pc->flags & KDUMP)
#define XENDUMP_DUMPFILE()  (pc->flags & XENDUMP)
#define XEN_HYPER_MODE()    (pc->flags & XEN_HYPER)
#define SYSRQ_TASK(X)       ((pc->flags & SYSRQ) && is_task_active(X))
#define XEN_CORE_DUMPFILE() (pc->flags & XEN_CORE)
#define LKCD_KERNTYPES()    (pc->flags & KERNTYPES)
#define KVMDUMP_DUMPFILE()  (pc->flags & KVMDUMP)
#define SADUMP_DUMPFILE()  (pc->flags & SADUMP)
#define VMSS_DUMPFILE()     (pc->flags & VMWARE_VMSS)
#define QEMU_MEM_DUMP_NO_VMCOREINFO() \
	    ((pc->flags2 & (QEMU_MEM_DUMP_ELF|QEMU_MEM_DUMP_COMPRESSED)) && !(pc->flags2 & VMCOREINFO))

#define NETDUMP_LOCAL    (0x1)  /* netdump_data flags */
#define NETDUMP_REMOTE   (0x2)
#define VMCORE_VALID()   (nd->flags & (NETDUMP_LOCAL|NETDUMP_REMOTE|KDUMP_LOCAL))
#define NETDUMP_ELF32    (0x4)
#define NETDUMP_ELF64    (0x8)
#define PARTIAL_DUMP    (0x10)  /* netdump or diskdump */
#define KDUMP_ELF32     (0x20)
#define KDUMP_ELF64     (0x40)
#define KDUMP_LOCAL     (0x80)
#define KCORE_LOCAL    (0x100)
#define KCORE_ELF32    (0x200)
#define KCORE_ELF64    (0x400)
#define QEMU_MEM_DUMP_KDUMP_BACKUP \
                       (0x800)
#define KVMDUMP_LOCAL    (0x1)
#define KVMDUMP_VALID()  (kvm->flags & (KVMDUMP_LOCAL))

#define DUMPFILE_FORMAT(flags) ((flags) & \
		        (NETDUMP_ELF32|NETDUMP_ELF64|KDUMP_ELF32|KDUMP_ELF64))

#define DISKDUMP_LOCAL      (0x1)
#define KDUMP_CMPRS_LOCAL   (0x2)
#define ERROR_EXCLUDED      (0x4)
#define ZERO_EXCLUDED       (0x8)
#define DUMPFILE_SPLIT      (0x10)
#define NO_ELF_NOTES        (0x20)
#define LZO_SUPPORTED       (0x40)
#define SNAPPY_SUPPORTED    (0x80)
#define DISKDUMP_VALID()    (dd->flags & DISKDUMP_LOCAL)
#define KDUMP_CMPRS_VALID() (dd->flags & KDUMP_CMPRS_LOCAL)
#define KDUMP_SPLIT()       (dd->flags & DUMPFILE_SPLIT)

#define XENDUMP_LOCAL    (0x1)
#define XENDUMP_VALID()  (xd->flags & XENDUMP_LOCAL)

#define SADUMP_LOCAL   (0x1)
#define SADUMP_DISKSET (0x2)
#define SADUMP_MEDIA   (0x4)
#define SADUMP_ZERO_EXCLUDED (0x8)
#define SADUMP_KDUMP_BACKUP  (0x10)
#define SADUMP_VALID() (sd->flags & SADUMP_LOCAL)

```

#### get_uptime() [lines 5407-5514]
```c
int vaddr_type(ulong, struct task_context *);
char *format_stack_entry(struct bt_info *bt, char *, ulong, ulong);
int in_user_stack(ulong, ulong);
int dump_inode_page(ulong);
ulong valid_section_nr(ulong);
void display_memory_from_file_offset(ulonglong, long, void *);
void swap_info_init(void);

/*
 *  filesys.c
 */
void fd_init(void);
void vfs_init(void);
int is_a_tty(char *);
int file_exists(char *, struct stat *);
int file_readable(char *);
int is_directory(char *);
char *search_directory_tree(char *, char *, int);
void open_tmpfile(void);
void close_tmpfile(void);
void open_tmpfile2(void);
void set_tmpfile2(FILE *);
void close_tmpfile2(void);
void open_files_dump(ulong, int, struct reference *);
void get_pathname(ulong, char *, int, int, ulong);
ulong *get_mount_list(int *, struct task_context *);
char *vfsmount_devname(ulong, char *, int);
ulong file_to_dentry(ulong);
ulong file_to_vfsmnt(ulong);
int get_proc_version(void);
int file_checksum(char *, long *);
void dump_filesys_table(int);
char *fill_file_cache(ulong);
void clear_file_cache(void);
char *fill_dentry_cache(ulong);
void clear_dentry_cache(void);
char *fill_inode_cache(ulong);
void clear_inode_cache(void);
int monitor_memory(long *, long *, long *, long *);
int is_readable(char *);
struct list_pair {
	ulong index;
	void *value;
};
#define radix_tree_pair list_pair
ulong do_radix_tree(ulong, int, struct list_pair *);
#define RADIX_TREE_COUNT   (1)
#define RADIX_TREE_SEARCH  (2)
#define RADIX_TREE_DUMP    (3)
#define RADIX_TREE_GATHER  (4)
#define RADIX_TREE_DUMP_CB (5)
/*
 * from: "include/linux/radix-tree.h"
 */
#define RADIX_TREE_ENTRY_MASK           3UL
#define RADIX_TREE_EXCEPTIONAL_ENTRY    2

ulong do_xarray(ulong, int, struct list_pair *);
#define XARRAY_COUNT   (1)
#define XARRAY_SEARCH  (2)
#define XARRAY_DUMP    (3)
#define XARRAY_GATHER  (4)
#define XARRAY_DUMP_CB (5)
#define XARRAY_TAG_MASK      (3UL
/* ... truncated ... */
```

## 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(-)

--- a/defs.h
+++ b/defs.h
@@ -731,6 +731,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;
@@ -6539,6 +6540,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
  */
--- a/kernel.c
+++ b/kernel.c
@@ -286,6 +286,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();
@@ -5456,7 +5462,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;
@@ -6050,6 +6056,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);
 }

 /*
--- a/task.c
+++ b/task.c
@@ -4100,6 +4100,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;

@@ -4136,6 +4142,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(-)

--- a/defs.h
+++ b/defs.h
@@ -731,6 +731,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;
@@ -6539,6 +6540,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
  */
--- a/kernel.c
+++ b/kernel.c
@@ -286,6 +286,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();
@@ -5456,7 +5462,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;
@@ -6050,6 +6056,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);
 }

 /*
--- a/task.c
+++ b/task.c
@@ -4100,6 +4100,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;

@@ -4136,6 +4142,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-2017-5715

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.

---
 memory.c |    6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

--- a/memory.c
+++ b/memory.c
@@ -2237,13 +2237,15 @@ 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())
 				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.

---
 memory.c |    6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

--- a/memory.c
+++ b/memory.c
@@ -2237,13 +2237,15 @@ 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())
 				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: