git: e975d1b72507 - stable/14 - linux(4): Return ENOTSUP from listxattr instead of EPERM

From: Dmitry Chagin <dchagin_at_FreeBSD.org>
Date: Mon, 11 Sep 2023 12:00:19 UTC
The branch stable/14 has been updated by dchagin:

URL: https://cgit.FreeBSD.org/src/commit/?id=e975d1b72507def7a699adf1cb38c68b48d80f51

commit e975d1b72507def7a699adf1cb38c68b48d80f51
Author:     Dmitry Chagin <dchagin@FreeBSD.org>
AuthorDate: 2023-09-05 08:52:27 +0000
Commit:     Dmitry Chagin <dchagin@FreeBSD.org>
CommitDate: 2023-09-11 11:59:38 +0000

    linux(4): Return ENOTSUP from listxattr instead of EPERM
    
    FreeBSD does not permits manipulating extended attributes in the system
    namespace by unprivileged accounts, even if account has appropriate
    privileges to access filesystem object.
    In Linux the system namespace is used to preserve posix acls. Some Gnu
    coreutils binaries uses posix acls, eg, install, ls, cp.  And fails if
    we unexpectedly return EPERM error from xattr system calls.
    
    In the other hands, in Linux read and write access to the system
    namespace depend on the policy implemented for each filesystem, so we'll
    mimics we're a filesystem that prohibits this for unpriveleged accounts.
    
    Reported by:            zirias
    Tested by:              zirias
    MFC after:              1 week
    
    (cherry picked from commit 11e37048db35d7fcfc285b867965de1aeefec2c8)
---
 sys/compat/linux/linux_xattr.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/sys/compat/linux/linux_xattr.c b/sys/compat/linux/linux_xattr.c
index 71d7ae58439e..6979fff9c82d 100644
--- a/sys/compat/linux/linux_xattr.c
+++ b/sys/compat/linux/linux_xattr.c
@@ -165,6 +165,8 @@ listxattr(struct thread *td, struct listxattr_args *args)
 			error = kern_extattr_list_fd(td, args->fd,
 			    attrnamespace, &auio);
 		rs = sz - auio.uio_resid;
+		if (error == EPERM)
+			break;
 		if (error != 0 || rs == 0)
 			continue;
 		prefix = extattr_namespace_names[attrnamespace];