]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
nohup: avoid FORTIFY runtime failure on Bionic libc
authorPádraig Brady <P@draigBrady.com>
Tue, 9 Sep 2025 11:11:00 +0000 (12:11 +0100)
committerPádraig Brady <P@draigBrady.com>
Tue, 9 Sep 2025 11:21:41 +0000 (12:21 +0100)
The meaning of non-file permission umask bits is implementation defined.
On Bionic libc, attempting to set them triggers a FORTIFY runtime check.

  $ nohup true
  FORTIFY: umask: called with invalid mask -601
  Aborted                    nohup true

* src/nohup.c: (main) Avoid setting non-permission bits in umask.
Just clear the umask to ensure we create nohup.out with u+rw,
as we restore the original umask before the exec().
* tests/misc/nohup.sh: Add a test case.
* NEWS: Mention the bug fix.

NEWS
src/nohup.c
tests/misc/nohup.sh

diff --git a/NEWS b/NEWS
index 283d8046d527b396846f21c717a2b98bced63ce8..392129dad24a5cbf3b269b631bacd6e300c59fea 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -47,6 +47,10 @@ GNU coreutils NEWS                                    -*- outline -*-
   with multi-byte thousands grouping characters.
   [This bug was present in "the beginning".]
 
+  'nohup' avoids implementation defined behavior setting umask,
+  avoiding a FORTIFY runtime failure on Bionic libc.
+  [This bug was present in "the beginning".]
+
   'od --strings' with '-N' now works correctly.  Previously od might
   write a NUL byte after a heap buffer, or output invalid addresses.
   [These bugs were present in "the beginning".]
index d58fcc53f05aa21143dfe69c95034e9e94550b2a..6218986cb54eec70bde8f6e024a27fdb03059795 100644 (file)
@@ -141,7 +141,7 @@ main (int argc, char **argv)
       char const *file = "nohup.out";
       int flags = O_CREAT | O_WRONLY | O_APPEND;
       mode_t mode = S_IRUSR | S_IWUSR;
-      mode_t umask_value = umask (~mode);
+      mode_t umask_value = umask (0);
       out_fd = (redirecting_stdout
                 ? fd_reopen (STDOUT_FILENO, file, flags, mode)
                 : open (file, flags, mode));
index 917d2a3893e32a01feefd973908cd8b19e0b8d36..f49997f2693a22666a602d4d54cd0c0bf54d9b77 100755 (executable)
@@ -122,4 +122,24 @@ export POSIXLY_CORRECT=1
 returns_ 127 nohup >/dev/null 2>&1 || fail=1
 unset POSIXLY_CORRECT
 
+# Make sure we create nohup.out with u+rw permissions
+(
+  rm -f nohup.out
+
+  # POSIX shells immediately exit the subshell on exec error.
+  # So check we can write to /dev/tty before the exec, which
+  # isn't possible if we've no controlling tty for example.
+  test -c /dev/tty && >/dev/tty || exit 0
+  exec >/dev/tty
+  test -t 1 || exit 0
+
+  umask 600 # Ensure nohup undoes this
+
+  nohup echo hi || fail=1
+  test "$(stat -c %a nohup.out)" = 600 || fail=1
+
+  rm -f nohup.out
+  exit $fail
+) || fail=1
+
 Exit $fail