arrfab / rpms / glibc

Forked from rpms/glibc 5 years ago
Clone

Blame SOURCES/glibc-rh1330705-4.patch

147e83
Adjusted for the lack of the ports move.
147e83
147e83
commit 65f6f938cd562a614a68e15d0581a34b177ec29d
147e83
Author: Eric Rannaud <e@nanocritical.com>
147e83
Date:   Tue Feb 24 13:12:26 2015 +0530
147e83
147e83
    linux: open and openat ignore 'mode' with O_TMPFILE in flags
147e83
    
147e83
    Both open and openat load their last argument 'mode' lazily, using
147e83
    va_arg() only if O_CREAT is found in oflag. This is wrong, mode is also
147e83
    necessary if O_TMPFILE is in oflag.
147e83
    
147e83
    By chance on x86_64, the problem wasn't evident when using O_TMPFILE
147e83
    with open, as the 3rd argument of open, even when not loaded with
147e83
    va_arg, is left untouched in RDX, where the syscall expects it.
147e83
    
147e83
    However, openat was not so lucky, and O_TMPFILE couldn't be used: mode
147e83
    is the 4th argument, in RCX, but the syscall expects its 4th argument in
147e83
    a different register than the glibc wrapper, in R10.
147e83
    
147e83
    Introduce a macro __OPEN_NEEDS_MODE (oflag) to test if either O_CREAT or
147e83
    O_TMPFILE is set in oflag.
147e83
    
147e83
Index: b/io/bits/fcntl2.h
147e83
===================================================================
147e83
--- a/io/bits/fcntl2.h
147e83
+++ b/io/bits/fcntl2.h
147e83
@@ -20,7 +20,7 @@
147e83
 # error "Never include <bits/fcntl2.h> directly; use <fcntl.h> instead."
147e83
 #endif
147e83
 
147e83
-/* Check that calls to open and openat with O_CREAT set have an
147e83
+/* Check that calls to open and openat with O_CREAT or O_TMPFILE set have an
147e83
    appropriate third/fourth parameter.  */
147e83
 #ifndef __USE_FILE_OFFSET64
147e83
 extern int __open_2 (const char *__path, int __oflag) __nonnull ((1));
147e83
@@ -35,7 +35,7 @@ extern int __REDIRECT (__open_alias, (co
147e83
 __errordecl (__open_too_many_args,
147e83
 	     "open can be called either with 2 or 3 arguments, not more");
147e83
 __errordecl (__open_missing_mode,
147e83
-	     "open with O_CREAT in second argument needs 3 arguments");
147e83
+	     "open with O_CREAT or O_TMPFILE in second argument needs 3 arguments");
147e83
 
147e83
 __fortify_function int
147e83
 open (const char *__path, int __oflag, ...)
147e83
@@ -45,7 +45,7 @@ open (const char *__path, int __oflag, .
147e83
 
147e83
   if (__builtin_constant_p (__oflag))
147e83
     {
147e83
-      if ((__oflag & O_CREAT) != 0 && __va_arg_pack_len () < 1)
147e83
+      if (__OPEN_NEEDS_MODE (__oflag) && __va_arg_pack_len () < 1)
147e83
 	{
147e83
 	  __open_missing_mode ();
147e83
 	  return __open_2 (__path, __oflag);
147e83
@@ -67,7 +67,7 @@ extern int __REDIRECT (__open64_alias, (
147e83
 __errordecl (__open64_too_many_args,
147e83
 	     "open64 can be called either with 2 or 3 arguments, not more");
147e83
 __errordecl (__open64_missing_mode,
147e83
-	     "open64 with O_CREAT in second argument needs 3 arguments");
147e83
+	     "open64 with O_CREAT or O_TMPFILE in second argument needs 3 arguments");
147e83
 
147e83
 __fortify_function int
147e83
 open64 (const char *__path, int __oflag, ...)
147e83
@@ -77,7 +77,7 @@ open64 (const char *__path, int __oflag,
147e83
 
147e83
   if (__builtin_constant_p (__oflag))
147e83
     {
147e83
-      if ((__oflag & O_CREAT) != 0 && __va_arg_pack_len () < 1)
147e83
+      if (__OPEN_NEEDS_MODE (__oflag) && __va_arg_pack_len () < 1)
147e83
 	{
147e83
 	  __open64_missing_mode ();
147e83
 	  return __open64_2 (__path, __oflag);
147e83
@@ -111,7 +111,7 @@ extern int __REDIRECT (__openat_alias, (
147e83
 __errordecl (__openat_too_many_args,
147e83
 	     "openat can be called either with 3 or 4 arguments, not more");
147e83
 __errordecl (__openat_missing_mode,
147e83
-	     "openat with O_CREAT in third argument needs 4 arguments");
147e83
+	     "openat with O_CREAT or O_TMPFILE in third argument needs 4 arguments");
147e83
 
147e83
 __fortify_function int
147e83
 openat (int __fd, const char *__path, int __oflag, ...)
147e83
@@ -121,7 +121,7 @@ openat (int __fd, const char *__path, in
147e83
 
147e83
   if (__builtin_constant_p (__oflag))
147e83
     {
147e83
-      if ((__oflag & O_CREAT) != 0 && __va_arg_pack_len () < 1)
147e83
+      if (__OPEN_NEEDS_MODE (__oflag) && __va_arg_pack_len () < 1)
147e83
 	{
147e83
 	  __openat_missing_mode ();
147e83
 	  return __openat_2 (__fd, __path, __oflag);
147e83
@@ -145,7 +145,7 @@ extern int __REDIRECT (__openat64_alias,
147e83
 __errordecl (__openat64_too_many_args,
147e83
 	     "openat64 can be called either with 3 or 4 arguments, not more");
147e83
 __errordecl (__openat64_missing_mode,
147e83
-	     "openat64 with O_CREAT in third argument needs 4 arguments");
147e83
+	     "openat64 with O_CREAT or O_TMPFILE in third argument needs 4 arguments");
147e83
 
147e83
 __fortify_function int
147e83
 openat64 (int __fd, const char *__path, int __oflag, ...)
147e83
@@ -155,7 +155,7 @@ openat64 (int __fd, const char *__path,
147e83
 
147e83
   if (__builtin_constant_p (__oflag))
147e83
     {
147e83
-      if ((__oflag & O_CREAT) != 0 && __va_arg_pack_len () < 1)
147e83
+      if (__OPEN_NEEDS_MODE (__oflag) && __va_arg_pack_len () < 1)
147e83
 	{
147e83
 	  __openat64_missing_mode ();
147e83
 	  return __openat64_2 (__fd, __path, __oflag);
147e83
Index: b/io/fcntl.h
147e83
===================================================================
147e83
--- a/io/fcntl.h
147e83
+++ b/io/fcntl.h
147e83
@@ -34,6 +34,15 @@ __BEGIN_DECLS
147e83
    numbers and flag bits for `open', `fcntl', et al.  */
147e83
 #include <bits/fcntl.h>
147e83
 
147e83
+/* Detect if open needs mode as a third argument (or for openat as a fourth
147e83
+   argument).  */
147e83
+#ifdef __O_TMPFILE
147e83
+# define __OPEN_NEEDS_MODE(oflag) \
147e83
+  (((oflag) & O_CREAT) != 0 || ((oflag) & __O_TMPFILE) == __O_TMPFILE)
147e83
+#else
147e83
+# define __OPEN_NEEDS_MODE(oflag) (((oflag) & O_CREAT) != 0)
147e83
+#endif
147e83
+
147e83
 /* POSIX.1-2001 specifies that these types are defined by <fcntl.h>.
147e83
    Earlier POSIX standards permitted any type ending in `_t' to be defined
147e83
    by any POSIX header, so we don't conditionalize the definitions here.  */
147e83
@@ -154,8 +163,9 @@ typedef __pid_t pid_t;
147e83
 extern int fcntl (int __fd, int __cmd, ...);
147e83
 
147e83
 /* Open FILE and return a new file descriptor for it, or -1 on error.
147e83
-   OFLAG determines the type of access used.  If O_CREAT is on OFLAG,
147e83
-   the third argument is taken as a `mode_t', the mode of the created file.
147e83
+   OFLAG determines the type of access used.  If O_CREAT or O_TMPFILE is set
147e83
+   in OFLAG, the third argument is taken as a `mode_t', the mode of the
147e83
+   created file.
147e83
 
147e83
    This function is a cancellation point and therefore not marked with
147e83
    __THROW.  */
147e83
Index: b/io/open.c
147e83
===================================================================
147e83
--- a/io/open.c
147e83
+++ b/io/open.c
147e83
@@ -23,7 +23,7 @@
147e83
 #include <stdio.h>
147e83
 
147e83
 
147e83
-/* Open FILE with access OFLAG.  If OFLAG includes O_CREAT,
147e83
+/* Open FILE with access OFLAG.  If O_CREAT or O_TMPFILE is in OFLAG,
147e83
    a third argument is the file protection.  */
147e83
 int
147e83
 __libc_open (file, oflag)
147e83
@@ -38,7 +38,7 @@ __libc_open (file, oflag)
147e83
       return -1;
147e83
     }
147e83
 
147e83
-  if (oflag & O_CREAT)
147e83
+  if (__OPEN_NEEDS_MODE (oflag))
147e83
     {
147e83
       va_list arg;
147e83
       va_start(arg, oflag);
147e83
Index: b/io/open64.c
147e83
===================================================================
147e83
--- a/io/open64.c
147e83
+++ b/io/open64.c
147e83
@@ -22,7 +22,7 @@
147e83
 #include <stddef.h>
147e83
 #include <stdio.h>
147e83
 
147e83
-/* Open FILE with access OFLAG.  If OFLAG includes O_CREAT,
147e83
+/* Open FILE with access OFLAG.  If O_CREAT or O_TMPFILE is in OFLAG,
147e83
    a third argument is the file protection.  */
147e83
 int
147e83
 __libc_open64 (file, oflag)
147e83
@@ -37,7 +37,7 @@ __libc_open64 (file, oflag)
147e83
       return -1;
147e83
     }
147e83
 
147e83
-  if (oflag & O_CREAT)
147e83
+  if (__OPEN_NEEDS_MODE (oflag))
147e83
     {
147e83
       va_list arg;
147e83
       va_start (arg, oflag);
147e83
Index: b/io/open64_2.c
147e83
===================================================================
147e83
--- a/io/open64_2.c
147e83
+++ b/io/open64_2.c
147e83
@@ -22,8 +22,8 @@
147e83
 int
147e83
 __open64_2 (const char *file, int oflag)
147e83
 {
147e83
-  if (oflag & O_CREAT)
147e83
-    __fortify_fail ("invalid open64 call: O_CREAT without mode");
147e83
+  if (__OPEN_NEEDS_MODE (oflag))
147e83
+    __fortify_fail ("invalid open64 call: O_CREAT or O_TMPFILE without mode");
147e83
 
147e83
   return __open64 (file, oflag);
147e83
 }
147e83
Index: b/io/open_2.c
147e83
===================================================================
147e83
--- a/io/open_2.c
147e83
+++ b/io/open_2.c
147e83
@@ -22,8 +22,8 @@
147e83
 int
147e83
 __open_2 (const char *file, int oflag)
147e83
 {
147e83
-  if (oflag & O_CREAT)
147e83
-    __fortify_fail ("invalid open call: O_CREAT without mode");
147e83
+  if (__OPEN_NEEDS_MODE (oflag))
147e83
+    __fortify_fail ("invalid open call: O_CREAT or O_TMPFILE without mode");
147e83
 
147e83
   return __open (file, oflag);
147e83
 }
147e83
Index: b/io/openat.c
147e83
===================================================================
147e83
--- a/io/openat.c
147e83
+++ b/io/openat.c
147e83
@@ -30,7 +30,7 @@ int __have_atfcts;
147e83
 #endif
147e83
 
147e83
 /* Open FILE with access OFLAG.  Interpret relative paths relative to
147e83
-   the directory associated with FD.  If OFLAG includes O_CREAT, a
147e83
+   the directory associated with FD.  If O_CREAT or O_TMPFILE is in OFLAG, a
147e83
    third argument is the file protection.  */
147e83
 int
147e83
 __openat (fd, file, oflag)
147e83
@@ -60,7 +60,7 @@ __openat (fd, file, oflag)
147e83
 	}
147e83
     }
147e83
 
147e83
-  if (oflag & O_CREAT)
147e83
+  if (__OPEN_NEEDS_MODE (oflag))
147e83
     {
147e83
       va_list arg;
147e83
       va_start (arg, oflag);
147e83
Index: b/io/openat64.c
147e83
===================================================================
147e83
--- a/io/openat64.c
147e83
+++ b/io/openat64.c
147e83
@@ -23,7 +23,7 @@
147e83
 #include <sys/stat.h>
147e83
 
147e83
 /* Open FILE with access OFLAG.  Interpret relative paths relative to
147e83
-   the directory associated with FD.  If OFLAG includes O_CREAT, a
147e83
+   the directory associated with FD.  If O_CREAT or O_TMPFILE is in OFLAG, a
147e83
    third argument is the file protection.  */
147e83
 int
147e83
 __openat64 (fd, file, oflag)
147e83
@@ -53,7 +53,7 @@ __openat64 (fd, file, oflag)
147e83
 	}
147e83
     }
147e83
 
147e83
-  if (oflag & O_CREAT)
147e83
+  if (__OPEN_NEEDS_MODE (oflag))
147e83
     {
147e83
       va_list arg;
147e83
       va_start (arg, oflag);
147e83
Index: b/io/openat64_2.c
147e83
===================================================================
147e83
--- a/io/openat64_2.c
147e83
+++ b/io/openat64_2.c
147e83
@@ -22,8 +22,8 @@
147e83
 int
147e83
 __openat64_2 (int fd, const char *file, int oflag)
147e83
 {
147e83
-  if (oflag & O_CREAT)
147e83
-    __fortify_fail ("invalid openat64 call: O_CREAT without mode");
147e83
+  if (__OPEN_NEEDS_MODE (oflag))
147e83
+    __fortify_fail ("invalid openat64 call: O_CREAT or O_TMPFILE without mode");
147e83
 
147e83
   return __openat64 (fd, file, oflag);
147e83
 }
147e83
Index: b/io/openat_2.c
147e83
===================================================================
147e83
--- a/io/openat_2.c
147e83
+++ b/io/openat_2.c
147e83
@@ -22,8 +22,8 @@
147e83
 int
147e83
 __openat_2 (int fd, const char *file, int oflag)
147e83
 {
147e83
-  if (oflag & O_CREAT)
147e83
-    __fortify_fail ("invalid openat call: O_CREAT without mode");
147e83
+  if (__OPEN_NEEDS_MODE (oflag))
147e83
+    __fortify_fail ("invalid openat call: O_CREAT or O_TMPFILE without mode");
147e83
 
147e83
   return __openat (fd, file, oflag);
147e83
 }
147e83
Index: b/sysdeps/mach/hurd/open.c
147e83
===================================================================
147e83
--- a/sysdeps/mach/hurd/open.c
147e83
+++ b/sysdeps/mach/hurd/open.c
147e83
@@ -22,7 +22,7 @@
147e83
 #include <hurd.h>
147e83
 #include <hurd/fd.h>
147e83
 
147e83
-/* Open FILE with access OFLAG.  If OFLAG includes O_CREAT,
147e83
+/* Open FILE with access OFLAG.  If O_CREAT or O_TMPFILE is in OFLAG,
147e83
    a third argument is the file protection.  */
147e83
 int
147e83
 __libc_open (const char *file, int oflag, ...)
147e83
@@ -30,7 +30,7 @@ __libc_open (const char *file, int oflag
147e83
   mode_t mode;
147e83
   io_t port;
147e83
 
147e83
-  if (oflag & O_CREAT)
147e83
+  if (__OPEN_NEEDS_MODE (oflag))
147e83
     {
147e83
       va_list arg;
147e83
       va_start (arg, oflag);
147e83
Index: b/sysdeps/mach/hurd/openat.c
147e83
===================================================================
147e83
--- a/sysdeps/mach/hurd/openat.c
147e83
+++ b/sysdeps/mach/hurd/openat.c
147e83
@@ -26,7 +26,7 @@
147e83
 #include <hurd/fd.h>
147e83
 
147e83
 /* Open FILE with access OFLAG.  Interpret relative paths relative to
147e83
-   the directory associated with FD.  If OFLAG includes O_CREAT, a
147e83
+   the directory associated with FD.  If O_CREAT or O_TMPFILE is in OFLAG, a
147e83
    third argument is the file protection.  */
147e83
 int
147e83
 __openat (fd, file, oflag)
147e83
@@ -37,7 +37,7 @@ __openat (fd, file, oflag)
147e83
   mode_t mode;
147e83
   io_t port;
147e83
 
147e83
-  if (oflag & O_CREAT)
147e83
+  if (__OPEN_NEEDS_MODE (oflag))
147e83
     {
147e83
       va_list arg;
147e83
       va_start (arg, oflag);
147e83
Index: b/sysdeps/posix/open64.c
147e83
===================================================================
147e83
--- a/sysdeps/posix/open64.c
147e83
+++ b/sysdeps/posix/open64.c
147e83
@@ -20,14 +20,14 @@
147e83
 #include <bp-sym.h>
147e83
 #include <sysdep-cancel.h>
147e83
 
147e83
-/* Open FILE with access OFLAG.  If OFLAG includes O_CREAT,
147e83
+/* Open FILE with access OFLAG.  If O_CREAT or O_TMPFILE is in OFLAG,
147e83
    a third argument is the file protection.  */
147e83
 int
147e83
 __libc_open64 (const char *file, int oflag, ...)
147e83
 {
147e83
   int mode = 0;
147e83
 
147e83
-  if (oflag & O_CREAT)
147e83
+  if (__OPEN_NEEDS_MODE (oflag))
147e83
     {
147e83
       va_list arg;
147e83
       va_start (arg, oflag);
147e83
Index: b/sysdeps/unix/sysv/linux/dl-openat64.c
147e83
===================================================================
147e83
--- a/sysdeps/unix/sysv/linux/dl-openat64.c
147e83
+++ b/sysdeps/unix/sysv/linux/dl-openat64.c
147e83
@@ -28,7 +28,7 @@ openat64 (dfd, file, oflag)
147e83
      const char *file;
147e83
      int oflag;
147e83
 {
147e83
-  assert ((oflag & O_CREAT) == 0);
147e83
+  assert (!__OPEN_NEEDS_MODE (oflag));
147e83
 
147e83
 #ifdef __NR_openat
147e83
   return INLINE_SYSCALL (openat, 3, dfd, file, oflag | O_LARGEFILE);
147e83
Index: b/ports/sysdeps/unix/sysv/linux/generic/open.c
147e83
===================================================================
147e83
--- a/ports/sysdeps/unix/sysv/linux/generic/open.c
147e83
+++ b/ports/sysdeps/unix/sysv/linux/generic/open.c
147e83
@@ -22,14 +22,14 @@
147e83
 #include <stdio.h>
147e83
 #include <sysdep-cancel.h>
147e83
 
147e83
-/* Open FILE with access OFLAG.  If OFLAG includes O_CREAT,
147e83
+/* Open FILE with access OFLAG.  If O_CREAT or O_TMPFILE is in OFLAG,
147e83
    a third argument is the file protection.  */
147e83
 int
147e83
 __libc_open (const char *file, int oflag, ...)
147e83
 {
147e83
   int mode = 0;
147e83
 
147e83
-  if (oflag & O_CREAT)
147e83
+  if (__OPEN_NEEDS_MODE (oflag))
147e83
     {
147e83
       va_list arg;
147e83
       va_start (arg, oflag);
147e83
@@ -59,7 +59,7 @@ __open_nocancel (const char *file, int o
147e83
 {
147e83
   int mode = 0;
147e83
 
147e83
-  if (oflag & O_CREAT)
147e83
+  if (__OPEN_NEEDS_MODE (oflag))
147e83
     {
147e83
       va_list arg;
147e83
       va_start (arg, oflag);
147e83
Index: b/ports/sysdeps/unix/sysv/linux/generic/open64.c
147e83
===================================================================
147e83
--- a/ports/sysdeps/unix/sysv/linux/generic/open64.c
147e83
+++ b/ports/sysdeps/unix/sysv/linux/generic/open64.c
147e83
@@ -22,14 +22,14 @@
147e83
 #include <stdio.h>
147e83
 #include <sysdep-cancel.h>
147e83
 
147e83
-/* Open FILE with access OFLAG.  If OFLAG includes O_CREAT,
147e83
+/* Open FILE with access OFLAG.  If O_CREAT or O_TMPFILE is in OFLAG,
147e83
    a third argument is the file protection.  */
147e83
 int
147e83
 __libc_open64 (const char *file, int oflag, ...)
147e83
 {
147e83
   int mode = 0;
147e83
 
147e83
-  if (oflag & O_CREAT)
147e83
+  if (__OPEN_NEEDS_MODE (oflag))
147e83
     {
147e83
       va_list arg;
147e83
       va_start (arg, oflag);
147e83
Index: b/sysdeps/unix/sysv/linux/open64.c
147e83
===================================================================
147e83
--- a/sysdeps/unix/sysv/linux/open64.c
147e83
+++ b/sysdeps/unix/sysv/linux/open64.c
147e83
@@ -22,14 +22,14 @@
147e83
 #include <stdio.h>
147e83
 #include <sysdep-cancel.h>
147e83
 
147e83
-/* Open FILE with access OFLAG.  If OFLAG includes O_CREAT,
147e83
+/* Open FILE with access OFLAG.  If O_CREAT or O_TMPFILE is in OFLAG,
147e83
    a third argument is the file protection.  */
147e83
 int
147e83
 __libc_open64 (const char *file, int oflag, ...)
147e83
 {
147e83
   int mode = 0;
147e83
 
147e83
-  if (oflag & O_CREAT)
147e83
+  if (__OPEN_NEEDS_MODE (oflag))
147e83
     {
147e83
       va_list arg;
147e83
       va_start (arg, oflag);
147e83
Index: b/sysdeps/unix/sysv/linux/openat.c
147e83
===================================================================
147e83
--- a/sysdeps/unix/sysv/linux/openat.c
147e83
+++ b/sysdeps/unix/sysv/linux/openat.c
147e83
@@ -148,8 +148,8 @@ OPENAT_NOT_CANCEL (fd, file, oflag, mode
147e83
 
147e83
 
147e83
 /* Open FILE with access OFLAG.  Interpret relative paths relative to
147e83
-   the directory associated with FD.  If OFLAG includes O_CREAT, a
147e83
-   third argument is the file protection.  */
147e83
+   the directory associated with FD.  If OFLAG includes O_CREAT or
147e83
+   O_TMPFILE, a fourth argument is the file protection.  */
147e83
 int
147e83
 __OPENAT (fd, file, oflag)
147e83
      int fd;
147e83
@@ -157,7 +157,7 @@ __OPENAT (fd, file, oflag)
147e83
      int oflag;
147e83
 {
147e83
   mode_t mode = 0;
147e83
-  if (oflag & O_CREAT)
147e83
+  if (__OPEN_NEEDS_MODE (oflag))
147e83
     {
147e83
       va_list arg;
147e83
       va_start (arg, oflag);