buglibsigsegv - Bugs: bug #42187, libsigsegv uses the obsolete...

 
 

bug #42187: libsigsegv uses the obsolete ioctl-based version of the /proc interface on Solaris

Submitter:  Roger Faulkner <roger_faulkner>
Submitted:  Thu 24 Apr 2014 06:44:44 PM UTC
   
 
Category:  None Severity:  3 - Normal
Item Group:  None Status:  Fix Released
Privacy:  Public Assigned to:  haible
Open/Closed:  Closed
* Mandatory Fields

Add a New Comment Rich Markup
   

Sat 18 Feb 2017 10:53:16 PM UTC, comment #1: 

Thank you for the report. The new libsigsegv-2.11 release prefers the newer /proc interface to the older one on Solaris.

https://git.savannah.gnu.org/gitweb/?p=libsigsegv.git;a=commit;h=759f643e3f5765713ebfeeefd90f6192a4aef609

I couldn't use your patch as-is, because
  - I did not want to throw away the support for the older Solaris platforms which don't have the new /proc interface,
  - your code reads past the bounds of the data read from the /proc/self/map file,
  - I don't know when the /proc/self symlink was introduced, so I prefer to avoid it,
  - read() can fail with EINTR on Solaris.
Therefore I wrote the new code from scratch.

But I thank you for the report. I wouldn't have known which Solaris interfaces are of age and which are not.

Bruno Haible <haible>
Group administrator
Thu 24 Apr 2014 06:44:44 PM UTC, original submission:  

libsigsegv should use the structured /proc interface,
which has been the default interface on Solaris  since
Solaris 2.6 (1997).  The old ioctl-based version of the
/proc interface is scheduled for removal from Solaris.

This is the patch that will make this  happen:

diff -r -u libsigsegv-2.6/configure.orig libsigsegv-2.6/configure
--- libsigsegv-2.6/configure.orig       2008-08-24 15:58:15.000000000 -0700
+++ libsigsegv-2.6/configure    2014-04-10 11:02:03.212637829 -0700
@@ -15596,8 +15596,8 @@
 _ACEOF


-{ $as_echo "$as_me:$LINENO: checking for PIOCMAP in sys/procfs.h" >&5
-$as_echo_n "checking for PIOCMAP in sys/procfs.h... " >&6; }
+{ $as_echo "$as_me:$LINENO: checking for prmap_t in procfs.h" >&5
+$as_echo_n "checking for prmap_t in procfs.h... " >&6; }
 if test "${sv_cv_procfsvma+set}" = set; then
   $as_echo_n "(cached) " >&6
 else
@@ -15608,12 +15608,11 @@
 cat confdefs.h >>conftest.$ac_ext
 cat >>conftest.$ac_ext <<_ACEOF
 /* end confdefs.h.  */
-#include <sys/procfs.h>
+#include <procfs.h>
 int
 main ()
 {
-int x = PIOCNMAP + PIOCMAP; prmap_t y;
-  ;
+  prmap_t y;
   return 0;
 }
 _ACEOF
diff -r -u libsigsegv-2.6/configure.ac.orig libsigsegv-2.6/configure.ac
--- libsigsegv-2.6/configure.ac.orig    2014-04-10 10:55:23.907673765 -0700
+++ libsigsegv-2.6/configure.ac 2014-04-10 11:02:35.810560742 -0700
@@ -619,9 +619,9 @@
    STACK_DIRECTION = 0 => spaghetti stack.])

 dnl Determination of the stack's virtual memory area.
-AC_CACHE_CHECK([for PIOCMAP in sys/procfs.h], sv_cv_procfsvma, [
-  AC_TRY_LINK([#include <sys/procfs.h>],
-    [int x = PIOCNMAP + PIOCMAP; prmap_t y;],
+AC_CACHE_CHECK([for prmap_t in procfs.h], sv_cv_procfsvma, [
+  AC_TRY_LINK([#include <procfs.h>],
+    [ prmap_t y;],
     sv_cv_procfsvma=yes, sv_cv_procfsvma=no)
 ])
 AC_CHECK_FUNCS([mincore])
diff -r -u libsigsegv-2.6/src/stackvma-procfs.c.orig libsigsegv-2.6/src/stackvma-procfs.c
--- libsigsegv-2.6/src/stackvma-procfs.c.orig   2014-04-10 11:05:58.957104341 -0700
+++ libsigsegv-2.6/src/stackvma-procfs.c        2014-04-10 10:49:41.584900672 -0700
@@ -19,8 +19,9 @@
 #include <unistd.h> /* open, close */
 #include <fcntl.h> /* open */
 #include <sys/types.h>
+#include <sys/stat.h>
 #include <sys/mman.h> /* mmap, munmap */
-#include <sys/procfs.h> /* PIOC*, prmap_t */
+#include <procfs.h> /* prmap_t */

 #include "stackvma-simple.c"

@@ -43,10 +44,7 @@
 int
 sigsegv_get_vma (unsigned long address, struct vma_struct *vma)
 {
-  char fnamebuf[6+10+1];
-  char *fname;
   int fd;
-  int nmaps;
   size_t memneed;
 #if HAVE_MMAP_ANON
 # define zero_fd -1
@@ -58,6 +56,7 @@
   int zero_fd;
 # define map_flags 0
 #endif
+  struct stat statb;
   void *auxmap;
   unsigned long auxmap_start;
   unsigned long auxmap_end;
@@ -71,26 +70,14 @@
   if (pagesize == 0)
     init_pagesize ();

-  /* Construct fname = sprintf (fnamebuf+i, "/proc/%u", getpid ()).  */
-  fname = fnamebuf + sizeof (fnamebuf) - 1;
-  *fname = '\0';
-  {
-    unsigned int value = getpid ();
-    do
-      *--fname = (value % 10) + '0';
-    while ((value = value / 10) > 0);
-  }
-  fname -= 6;
-  memcpy (fname, "/proc/", 6);
-
-  fd = open (fname, O_RDONLY);
+  fd = open ("/proc/self/map", O_RDONLY);
   if (fd < 0)
     goto failed;

-  if (ioctl (fd, PIOCNMAP, &nmaps) < 0)
+  if (fstat(fd, &statb) == -1)
     goto fail2;

-  memneed = (nmaps + 10) * sizeof (prmap_t);
+  memneed = statb.st_size + 10 * sizeof (prmap_t);
   /* Allocate memneed bytes of memory.
      We cannot use alloca here, because we are low on stack space.
      We also cannot use malloc here, because a malloc() call may have been
@@ -112,7 +99,7 @@
   auxmap_end = auxmap_start + memneed;
   maps = (prmap_t *) auxmap;

-  if (ioctl (fd, PIOCMAP, maps) < 0)
+  if (read(fd, (void *)maps, memneed) <= 0)
     goto fail1;

 #if STACK_DIRECTION < 0

Roger Faulkner <roger_faulkner>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by haible (Posted a comment)
  • -email is unavailable- added by roger_faulkner (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.

     

    Follow 4 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2023-01-04 haible StatusFixed Fix Released
    2017-02-18 haible StatusNone Fixed
        Assigned toNone haible
        Open/ClosedOpen Closed

    Back to the top

    Powered by Savane 3.13-d3ae.
    Corresponding source code