[PATCH] BZ #14782 system async cancellation

Rich Felker dalias@aerifal.cx
Thu Nov 1 02:50:00 GMT 2012


This patch fixes the unintended and dangerous (calls to
non-async-cancel-safe functions, which could leave locks in corrupt
state if interrupted by cancellation) use of async cancellation mode
in the implementation of system(). As discussed with Carlos in the
nptl/tst-cancel7 thread on this list, the code seems to have been
introduced mechanically along with similar changes in a number of
other files, the rest of which were pure syscalls for which the issue
in this bug report does not apply.

Copyright papers should not be required since this patch is all-red.
:-)

Rich
-------------- next part --------------
diff -ur orig/sysdeps/posix/system.c new/sysdeps/posix/system.c
--- orig/sysdeps/posix/system.c	2012-10-31 22:37:48.000000000 -0400
+++ new/sysdeps/posix/system.c	2012-10-31 22:49:59.000000000 -0400
@@ -181,15 +181,8 @@
        not be available after a chroot(), for example.  */
     return do_system ("exit 0") == 0;
 
-  if (SINGLE_THREAD_P)
-    return do_system (line);
-
-  int oldtype = LIBC_CANCEL_ASYNC ();
-
   int result = do_system (line);
 
-  LIBC_CANCEL_RESET (oldtype);
-
   return result;
 }
 weak_alias (__libc_system, system)
diff -ur orig/sysdeps/unix/sysv/linux/system.c new/sysdeps/unix/sysv/linux/system.c
--- orig/sysdeps/unix/sysv/linux/system.c	2012-10-31 22:38:31.000000000 -0400
+++ new/sysdeps/unix/sysv/linux/system.c	2012-10-31 22:40:22.000000000 -0400
@@ -24,19 +24,6 @@
 #include <bits/libc-lock.h>
 #include <kernel-features.h>
 
-/* We have to and actually can handle cancelable system().  The big
-   problem: we have to kill the child process if necessary.  To do
-   this a cleanup handler has to be registered and is has to be able
-   to find the PID of the child.  The main problem is to reliable have
-   the PID when needed.  It is not necessary for the parent thread to
-   return.  It might still be in the kernel when the cancellation
-   request comes.  Therefore we have to use the clone() calls ability
-   to have the kernel write the PID into the user-level variable.  */
-#ifndef FORK
-# define FORK() \
-  INLINE_SYSCALL (clone, 3, CLONE_PARENT_SETTID | SIGCHLD, 0, &pid)
-#endif
-
 #ifdef _LIBC_REENTRANT
 static void cancel_handler (void *arg);
 


More information about the Libc-alpha mailing list