Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/kern Fix code generation for programs with a faulty proc...



details:   https://anonhg.NetBSD.org/src/rev/c9553b532364
branches:  trunk
changeset: 996162:c9553b532364
user:      kamil <kamil%NetBSD.org@localhost>
date:      Tue Jan 22 03:44:44 2019 +0000

description:
Fix code generation for programs with a faulty process map

In case of any errors of scanning the segments reset
their content to a default value with zeros. This is
achieved with shortening the p_filesz parameter.

This allows to emit core(5) files for a process
regardless of its state of mappings, such as mapping
pages after EOF in a file.

Fixes PR lib/53343

diffstat:

 sys/kern/core_elf32.c |  19 +++++++++++++++----
 1 files changed, 15 insertions(+), 4 deletions(-)

diffs (40 lines):

diff -r fe741cd219bd -r c9553b532364 sys/kern/core_elf32.c
--- a/sys/kern/core_elf32.c     Tue Jan 22 03:42:24 2019 +0000
+++ b/sys/kern/core_elf32.c     Tue Jan 22 03:44:44 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: core_elf32.c,v 1.57 2018/09/03 16:29:35 riastradh Exp $        */
+/*     $NetBSD: core_elf32.c,v 1.58 2019/01/22 03:44:44 kamil Exp $    */
 
 /*
  * Copyright (c) 2001 Wasabi Systems, Inc.
@@ -40,7 +40,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(1, "$NetBSD: core_elf32.c,v 1.57 2018/09/03 16:29:35 riastradh Exp $");
+__KERNEL_RCSID(1, "$NetBSD: core_elf32.c,v 1.58 2019/01/22 03:44:44 kamil Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_coredump.h"
@@ -313,8 +313,19 @@
                int i;
 
                end -= slen;
-               if ((error = copyin_proc(ws->p, (void *)end, buf, slen)) != 0)
-                       return error;
+               if ((error = copyin_proc(ws->p, (void *)end, buf, slen)) != 0) {
+                       /*
+                        * In case of any errors of scanning the segments reset
+                        * their content to a default value with zeros. This is
+                        * achieved with shortening the p_filesz parameter.
+                        *
+                        * This allows to emit core(5) files for a process
+                        * regardless of its state of mappings, such as mapping
+                        * pages after EOF in a file.
+                        */
+                       realsize -= slen;
+                       continue;
+               }
 
                ep = (const long *) &buf[slen / sizeof(buf[0])];
                for (i = 0, ep--; buf <= ep; ep--, i++) {



Home | Main Index | Thread Index | Old Index