From: Pádraig Brady
Date: Thu, 20 Mar 2025 18:40:01 +0000 (+0000) Subject: ls: fix crash on systems with SELinux but without xattr support X-Git-Tag: v9.7~23 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cb2abbac7f9e40e0f0d6183bf9b11e80b0cad8ef;p=thirdparty%2Fcoreutils.git ls: fix crash on systems with SELinux but without xattr support This was seen on termux on Android with ./configure --disable-xattr where listxattr() and getxattr() returned ENOTSUP. Then the valid security context obtained by file_has_aclinfo() was discounted, and problematically then freed multiple times. Reported at https://github.com/termux/termux-packages/issues/23752 * src/ls.c (file_has_aclinfo_cache): Only discount the returned acl info when all components are defaulted due to being unsupported. --- diff --git a/NEWS b/NEWS index 902bdaf0e3..dfafa8ab22 100644 --- a/NEWS +++ b/NEWS @@ -15,7 +15,8 @@ GNU coreutils NEWS -*- outline -*- cache for the whole file. Previously it may have erroneously succeeded. [bug introduced with the "nocache" feature in coreutils-8.11] - 'ls -Z dir' would crash. + 'ls -Z dir' would crash on all systems, and 'ls -l' could crash + on systems like Android with SELinux but without xattr support. [bug introduced in coreutils-9.6] 'who -m' now outputs entries for remote logins. Previously login diff --git a/src/ls.c b/src/ls.c index 23309b8126..244484439f 100644 --- a/src/ls.c +++ b/src/ls.c @@ -3327,7 +3327,8 @@ file_has_aclinfo_cache (char const *file, struct fileinfo *f, errno = 0; int n = file_has_aclinfo (file, ai, flags); int err = errno; - if (f->stat_ok && n <= 0 && !acl_errno_valid (err)) + if (f->stat_ok && n <= 0 && !acl_errno_valid (err) + && (!(flags & ACL_GET_SCONTEXT) || !acl_errno_valid (ai->scontext_err))) { unsupported_return = n; unsupported_scontext = ai->scontext;