All of lore.kernel.org
 help / color / mirror / Atom feed
* ls from coreutils 9.6 doesn't show labels of some files
@ 2025-01-28 15:11 Ondrej Mosnacek
  2025-01-28 15:26 ` Stephen Smalley
  0 siblings, 1 reply; 8+ messages in thread
From: Ondrej Mosnacek @ 2025-01-28 15:11 UTC (permalink / raw)
  To: SElinux list

Hello everyone,

In a recent commit [1] that has already made it into the coreutils
package in Fedora Rawhide, ls changed the way it retrieves security
labels from files, which causes the SELinux label not to be displayed
with -Z for some files. It seems that the key difference is that it
now relies on the result of llistxattr(2) to determine if the label
should be retrieved and if security.selinux is not listed, it just
prints ? as if the file had no label. On some inodes on some
filesystems (e.g. the root inode on tmpfs or most sysfs inodes),
however, security.selinux is not currently returned in *listxattr(2),
so the labels are not shown even though they are there (and would be
returned in a *getxattr(2) call).

We can of course ask coreutils to go back to fetching the label
unconditionally, but perhaps we should also/instead fix the
*listxattr(2) output to be correct? IIUC, in some cases it's a matter
of adding a security_inode_init_security() call, while other ones may
need a hook for listxattr that would inject the security.selinux entry
when it's not returned by the filesystem already.

[1] https://git.savannah.gnu.org/cgit/coreutils.git/commit/?id=4ce432ad8738387f1b2e80e883dc7080df3afabe

-- 
Ondrej Mosnacek
Senior Software Engineer, Linux Security - SELinux kernel
Red Hat, Inc.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: ls from coreutils 9.6 doesn't show labels of some files
  2025-01-28 15:11 ls from coreutils 9.6 doesn't show labels of some files Ondrej Mosnacek
@ 2025-01-28 15:26 ` Stephen Smalley
  2025-01-28 16:08   ` Paul Moore
  0 siblings, 1 reply; 8+ messages in thread
From: Stephen Smalley @ 2025-01-28 15:26 UTC (permalink / raw)
  To: Ondrej Mosnacek; +Cc: SElinux list

On Tue, Jan 28, 2025 at 10:12 AM Ondrej Mosnacek <omosnace@redhat.com> wrote:
>
> Hello everyone,
>
> In a recent commit [1] that has already made it into the coreutils
> package in Fedora Rawhide, ls changed the way it retrieves security
> labels from files, which causes the SELinux label not to be displayed
> with -Z for some files. It seems that the key difference is that it
> now relies on the result of llistxattr(2) to determine if the label
> should be retrieved and if security.selinux is not listed, it just
> prints ? as if the file had no label. On some inodes on some
> filesystems (e.g. the root inode on tmpfs or most sysfs inodes),
> however, security.selinux is not currently returned in *listxattr(2),
> so the labels are not shown even though they are there (and would be
> returned in a *getxattr(2) call).
>
> We can of course ask coreutils to go back to fetching the label
> unconditionally, but perhaps we should also/instead fix the
> *listxattr(2) output to be correct? IIUC, in some cases it's a matter
> of adding a security_inode_init_security() call, while other ones may
> need a hook for listxattr that would inject the security.selinux entry
> when it's not returned by the filesystem already.
>
> [1] https://git.savannah.gnu.org/cgit/coreutils.git/commit/?id=4ce432ad8738387f1b2e80e883dc7080df3afabe

There may be other side effects of that commit, e.g. loss of context
translation if using mcstrans or equivalent.
WRT to returning security.selinux, selinux_inode_listsecurity()
already includes the SELinux xattr name so that should already be
returned,
unless the filesystem implements its own listxattr handler for
security.* _and_ doesn't include the SELinux one.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: ls from coreutils 9.6 doesn't show labels of some files
  2025-01-28 15:26 ` Stephen Smalley
@ 2025-01-28 16:08   ` Paul Moore
  2025-04-22 16:31     ` Rahul Sandhu
  0 siblings, 1 reply; 8+ messages in thread
From: Paul Moore @ 2025-01-28 16:08 UTC (permalink / raw)
  To: Ondrej Mosnacek, Stephen Smalley; +Cc: SElinux list

On Tue, Jan 28, 2025 at 10:27 AM Stephen Smalley
<stephen.smalley.work@gmail.com> wrote:
> On Tue, Jan 28, 2025 at 10:12 AM Ondrej Mosnacek <omosnace@redhat.com> wrote:
> >
> > Hello everyone,
> >
> > In a recent commit [1] that has already made it into the coreutils
> > package in Fedora Rawhide, ls changed the way it retrieves security
> > labels from files, which causes the SELinux label not to be displayed
> > with -Z for some files. It seems that the key difference is that it
> > now relies on the result of llistxattr(2) to determine if the label
> > should be retrieved and if security.selinux is not listed, it just
> > prints ? as if the file had no label. On some inodes on some
> > filesystems (e.g. the root inode on tmpfs or most sysfs inodes),
> > however, security.selinux is not currently returned in *listxattr(2),
> > so the labels are not shown even though they are there (and would be
> > returned in a *getxattr(2) call).
> >
> > We can of course ask coreutils to go back to fetching the label
> > unconditionally, but perhaps we should also/instead fix the
> > *listxattr(2) output to be correct? IIUC, in some cases it's a matter
> > of adding a security_inode_init_security() call, while other ones may
> > need a hook for listxattr that would inject the security.selinux entry
> > when it's not returned by the filesystem already.
> >
> > [1] https://git.savannah.gnu.org/cgit/coreutils.git/commit/?id=4ce432ad8738387f1b2e80e883dc7080df3afabe
>
> There may be other side effects of that commit, e.g. loss of context
> translation if using mcstrans or equivalent.

Out of curiosity, do we have any idea of the motivation behind that
change?  The commit description is poorly formatted, but it looks like
a number of changes that are only loosely related around xattrs with
the only motivation appearing to be in the subject: "use fewer
xattr-related syscalls".

Regardless, I think Stephen has a good point with the potential for a
loss of translation surprising some users.

> WRT to returning security.selinux, selinux_inode_listsecurity()
> already includes the SELinux xattr name so that should already be
> returned,
> unless the filesystem implements its own listxattr handler for
> security.* _and_ doesn't include the SELinux one.

I can't think of a good reason why we would ever want the *listxattr()
syscalls to not provide security.selinux, if there is an individual
filesystem that is different/broken in this regard it should be
treated as a BUG and fixed.

-- 
paul-moore.com

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: ls from coreutils 9.6 doesn't show labels of some files
  2025-01-28 16:08   ` Paul Moore
@ 2025-04-22 16:31     ` Rahul Sandhu
  2025-04-22 17:28       ` Stephen Smalley
  2025-04-22 18:06       ` Casey Schaufler
  0 siblings, 2 replies; 8+ messages in thread
From: Rahul Sandhu @ 2025-04-22 16:31 UTC (permalink / raw)
  To: paul; +Cc: omosnace, selinux, stephen.smalley.work

Hey,

> I can't think of a good reason why we would ever want the *listxattr()
> syscalls to not provide security.selinux, if there is an individual
> filesystem that is different/broken in this regard it should be
> treated as a BUG and fixed.

I've spoken to coreutils upstream[1], and they also seem to see this as
something which should be fixed in the kernel too[2][3], and appear to
want a soloution in the kernel rather than working around it in ls(1).

Thanks,
Rahul

[1] https://lists.gnu.org/archive/html/bug-coreutils/2025-04/msg00011.html
[2] https://lists.gnu.org/archive/html/bug-coreutils/2025-04/msg00025.html
[3] https://lists.gnu.org/archive/html/bug-coreutils/2025-04/msg00031.html

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: ls from coreutils 9.6 doesn't show labels of some files
  2025-04-22 16:31     ` Rahul Sandhu
@ 2025-04-22 17:28       ` Stephen Smalley
  2025-04-22 17:35         ` Dominick Grift
  2025-04-22 18:06       ` Casey Schaufler
  1 sibling, 1 reply; 8+ messages in thread
From: Stephen Smalley @ 2025-04-22 17:28 UTC (permalink / raw)
  To: Rahul Sandhu; +Cc: paul, omosnace, selinux

On Tue, Apr 22, 2025 at 12:31 PM Rahul Sandhu <nvraxn@gmail.com> wrote:
>
> Hey,
>
> > I can't think of a good reason why we would ever want the *listxattr()
> > syscalls to not provide security.selinux, if there is an individual
> > filesystem that is different/broken in this regard it should be
> > treated as a BUG and fixed.
>
> I've spoken to coreutils upstream[1], and they also seem to see this as
> something which should be fixed in the kernel too[2][3], and appear to
> want a solution in the kernel rather than working around it in ls(1).

So I assume this was introduced when tmpfs/shmem grew its own xattr
handlers, since previously it would just fall back to the LSM
security_inode_listsecurity() hook and return the SELinux ones
unconditionally. shmem_mknod() calls security_inode_init_security(),
so inodes created after policy is loaded get their security.selinux
xattrs set and returned via listxattr. Root directory of tmpfs mount
and any tmpfs mount that precedes policy load (e.g. initramfs) would
be the exceptions. Could modify shmem_listxattr() to call
security_inode_listsecurity() and combine with its own list before
returning.

>
> Thanks,
> Rahul
>
> [1] https://lists.gnu.org/archive/html/bug-coreutils/2025-04/msg00011.html
> [2] https://lists.gnu.org/archive/html/bug-coreutils/2025-04/msg00025.html
> [3] https://lists.gnu.org/archive/html/bug-coreutils/2025-04/msg00031.html

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: ls from coreutils 9.6 doesn't show labels of some files
  2025-04-22 17:28       ` Stephen Smalley
@ 2025-04-22 17:35         ` Dominick Grift
  0 siblings, 0 replies; 8+ messages in thread
From: Dominick Grift @ 2025-04-22 17:35 UTC (permalink / raw)
  To: Stephen Smalley; +Cc: Rahul Sandhu, paul, omosnace, selinux

Stephen Smalley <stephen.smalley.work@gmail.com> writes:

> On Tue, Apr 22, 2025 at 12:31 PM Rahul Sandhu <nvraxn@gmail.com> wrote:
>>
>> Hey,
>>
>> > I can't think of a good reason why we would ever want the *listxattr()
>> > syscalls to not provide security.selinux, if there is an individual
>> > filesystem that is different/broken in this regard it should be
>> > treated as a BUG and fixed.
>>
>> I've spoken to coreutils upstream[1], and they also seem to see this as
>> something which should be fixed in the kernel too[2][3], and appear to
>> want a solution in the kernel rather than working around it in ls(1).
>
> So I assume this was introduced when tmpfs/shmem grew its own xattr
> handlers, since previously it would just fall back to the LSM
> security_inode_listsecurity() hook and return the SELinux ones
> unconditionally. shmem_mknod() calls security_inode_init_security(),
> so inodes created after policy is loaded get their security.selinux
> xattrs set and returned via listxattr. Root directory of tmpfs mount
> and any tmpfs mount that precedes policy load (e.g. initramfs) would
> be the exceptions. Could modify shmem_listxattr() to call
> security_inode_listsecurity() and combine with its own list before
> returning.
>

This also happens when you mount an unlabeled fs:

mkdir /media/foo && mount /dev/sda1 /media/foo && ls -alZ /media

when you label it the issue goes away:

chcon sys.id:sys.role:media.file:s0 /media/foo && ls -alZ /media

>>
>> Thanks,
>> Rahul
>>
>> [1] https://lists.gnu.org/archive/html/bug-coreutils/2025-04/msg00011.html
>> [2] https://lists.gnu.org/archive/html/bug-coreutils/2025-04/msg00025.html
>> [3] https://lists.gnu.org/archive/html/bug-coreutils/2025-04/msg00031.html
>

-- 
gpg --locate-keys dominick.grift@defensec.nl (wkd)
Key fingerprint = FCD2 3660 5D6B 9D27 7FC6  E0FF DA7E 521F 10F6 4098
Dominick Grift
Mastodon: @kcinimod@defensec.nl

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: ls from coreutils 9.6 doesn't show labels of some files
  2025-04-22 16:31     ` Rahul Sandhu
  2025-04-22 17:28       ` Stephen Smalley
@ 2025-04-22 18:06       ` Casey Schaufler
  2025-04-22 18:57         ` Stephen Smalley
  1 sibling, 1 reply; 8+ messages in thread
From: Casey Schaufler @ 2025-04-22 18:06 UTC (permalink / raw)
  To: Rahul Sandhu, paul
  Cc: omosnace, selinux, stephen.smalley.work, Casey Schaufler

On 4/22/2025 9:31 AM, Rahul Sandhu wrote:
> Hey,
>
>> I can't think of a good reason why we would ever want the *listxattr()
>> syscalls to not provide security.selinux,

If you're using Smack instead of SELinux as an LSM you want to see
security.SMACK64, not security.selinux. Returning a value for security.selinux
makes no sense in this case.

>>  if there is an individual
>> filesystem that is different/broken in this regard it should be
>> treated as a BUG and fixed.
> I've spoken to coreutils upstream[1], and they also seem to see this as
> something which should be fixed in the kernel too[2][3], and appear to
> want a soloution in the kernel rather than working around it in ls(1).
>
> Thanks,
> Rahul
>
> [1] https://lists.gnu.org/archive/html/bug-coreutils/2025-04/msg00011.html
> [2] https://lists.gnu.org/archive/html/bug-coreutils/2025-04/msg00025.html
> [3] https://lists.gnu.org/archive/html/bug-coreutils/2025-04/msg00031.html
>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: ls from coreutils 9.6 doesn't show labels of some files
  2025-04-22 18:06       ` Casey Schaufler
@ 2025-04-22 18:57         ` Stephen Smalley
  0 siblings, 0 replies; 8+ messages in thread
From: Stephen Smalley @ 2025-04-22 18:57 UTC (permalink / raw)
  To: Casey Schaufler; +Cc: Rahul Sandhu, paul, omosnace, selinux

On Tue, Apr 22, 2025 at 2:07 PM Casey Schaufler <casey@schaufler-ca.com> wrote:
>
> On 4/22/2025 9:31 AM, Rahul Sandhu wrote:
> > Hey,
> >
> >> I can't think of a good reason why we would ever want the *listxattr()
> >> syscalls to not provide security.selinux,
>
> If you're using Smack instead of SELinux as an LSM you want to see
> security.SMACK64, not security.selinux. Returning a value for security.selinux
> makes no sense in this case.

As long as they use the security_inode_listsecurity() hook or similar
to fetch the xattr name, it should handle Smack correctly.

>
> >>  if there is an individual
> >> filesystem that is different/broken in this regard it should be
> >> treated as a BUG and fixed.
> > I've spoken to coreutils upstream[1], and they also seem to see this as
> > something which should be fixed in the kernel too[2][3], and appear to
> > want a soloution in the kernel rather than working around it in ls(1).
> >
> > Thanks,
> > Rahul
> >
> > [1] https://lists.gnu.org/archive/html/bug-coreutils/2025-04/msg00011.html
> > [2] https://lists.gnu.org/archive/html/bug-coreutils/2025-04/msg00025.html
> > [3] https://lists.gnu.org/archive/html/bug-coreutils/2025-04/msg00031.html
> >

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2025-04-22 18:57 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-01-28 15:11 ls from coreutils 9.6 doesn't show labels of some files Ondrej Mosnacek
2025-01-28 15:26 ` Stephen Smalley
2025-01-28 16:08   ` Paul Moore
2025-04-22 16:31     ` Rahul Sandhu
2025-04-22 17:28       ` Stephen Smalley
2025-04-22 17:35         ` Dominick Grift
2025-04-22 18:06       ` Casey Schaufler
2025-04-22 18:57         ` Stephen Smalley

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.