]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
ls: fix crash printing SELinux context for unstatable files
authorPádraig Brady <P@draigBrady.com>
Wed, 11 Nov 2020 17:22:33 +0000 (17:22 +0000)
committerPádraig Brady <P@draigBrady.com>
Wed, 11 Nov 2020 17:28:54 +0000 (17:28 +0000)
This crash was identified by Cyber Independent Testing Lab:
https://cyber-itl.org/2020/10/28/citl-7000-defects.html
and was introduced with commit v6.9.90-11-g4245876e2

* src/ls.c (gobble_file): Ensure scontext is initialized
in the case where files are not statable.
* tests/ls/selinux-segfault.sh: Renamed from proc-selinux-segfault.sh,
and added test case for broken symlinks.
* tests/local.mk: Adjust for the renamed test.
* NEWS: Mention the bug fix.

NEWS
src/ls.c
tests/local.mk
tests/ls/selinux-segfault.sh [moved from tests/ls/proc-selinux-segfault.sh with 77% similarity]

diff --git a/NEWS b/NEWS
index 392d0ce1e2eb95e672d2efe44c72200903f7be05..657477ac7ab32057023a42f3771691f4ad18c21c 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -17,6 +17,9 @@ GNU coreutils NEWS                                    -*- outline -*-
   heavily changed during the run.
   [bug introduced in coreutils-8.25]
 
+  ls no longer crashes when printing the SELinux context for unstatable files.
+  [bug introduced in coreutils-6.9.91]
+
 ** Changes in behavior
 
   cp and install now default to copy-on-write (COW) if available.
index 1f6afbc0eb0ab0b317539e85cda789f94338ec5c..1b4834cec2441bf92c6d24cfcf80edc262c08a1a 100644 (file)
--- a/src/ls.c
+++ b/src/ls.c
@@ -3424,6 +3424,9 @@ gobble_file (char const *name, enum filetype type, ino_t inode,
              provokes an exit status of 1.  */
           file_failure (command_line_arg,
                         _("cannot access %s"), full_name);
+
+          f->scontext = UNKNOWN_SECURITY_CONTEXT;
+
           if (command_line_arg)
             return 0;
 
index 7992003938f8a0667209dbdabd6267496550dbf5..e1c4675c23b269e8218b1580091d0afd00e0ba3e 100644 (file)
@@ -613,7 +613,7 @@ all_tests =                                 \
   tests/ls/multihardlink.sh                    \
   tests/ls/no-arg.sh                           \
   tests/ls/no-cap.sh                           \
-  tests/ls/proc-selinux-segfault.sh            \
+  tests/ls/selinux-segfault.sh                 \
   tests/ls/quote-align.sh                      \
   tests/ls/readdir-mountpoint-inode.sh         \
   tests/ls/recursive.sh                                \
similarity index 77%
rename from tests/ls/proc-selinux-segfault.sh
rename to tests/ls/selinux-segfault.sh
index 831a00e17594d00cc237896d935b90585c25c19c..e2b7ef6381f49e59a4efca18ad39e1e60161856e 100755 (executable)
@@ -1,5 +1,5 @@
 #!/bin/sh
-# ls -l /proc/sys would segfault when built against libselinux1 2.0.15-2+b1
+# Ensure we don't segfault in selinux handling
 
 # Copyright (C) 2008-2020 Free Software Foundation, Inc.
 
 . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
 print_ver_ ls
 
+# ls -l /proc/sys would segfault when built against libselinux1 2.0.15-2+b1
 f=/proc/sys
 test -r $f || f=.
-
 ls -l $f > out || fail=1
 
+# ls <= 8.32 would segfault when printing
+# the security context of broken symlink targets
+mkdir sedir || framework_failure_
+ln -sf missing sedir/broken || framework_failure_
+returns_ 1 ls -L -R -Z -m sedir > out || fail=1
+
 Exit $fail