xfs: don't generate selinux audit messages for capability testing
authorDarrick J. Wong <djwong@kernel.org>
Sat, 26 Feb 2022 00:18:30 +0000 (16:18 -0800)
committerDarrick J. Wong <djwong@kernel.org>
Wed, 9 Mar 2022 18:32:06 +0000 (10:32 -0800)
There are a few places where we test the current process' capability set
to decide if we're going to be more or less generous with resource
acquisition for a system call.  If the process doesn't have the
capability, we can continue the call, albeit in a degraded mode.

These are /not/ the actual security decisions, so it's not proper to use
capable(), which (in certain selinux setups) causes audit messages to
get logged.  Switch them to has_capability_noaudit.

Fixes: 7317a03df703f ("xfs: refactor inode ownership change transaction/inode/quota allocation idiom")
Fixes: ea9a46e1c4925 ("xfs: only return detailed fsmap info if the caller has CAP_SYS_ADMIN")
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Cc: Dave Chinner <david@fromorbit.com>
Reviewed-by: Ondrej Mosnacek <omosnace@redhat.com>
Acked-by: Serge Hallyn <serge@hallyn.com>
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
fs/xfs/xfs_fsmap.c
fs/xfs/xfs_ioctl.c
fs/xfs/xfs_iops.c
kernel/capability.c

index 48287caad28b7123064443095961eaa039102eed..10e1cb71439e436a9bbd311148f7387bd171c1d2 100644 (file)
@@ -864,8 +864,8 @@ xfs_getfsmap(
            !xfs_getfsmap_is_valid_device(mp, &head->fmh_keys[1]))
                return -EINVAL;
 
-       use_rmap = capable(CAP_SYS_ADMIN) &&
-                  xfs_has_rmapbt(mp);
+       use_rmap = xfs_has_rmapbt(mp) &&
+                  has_capability_noaudit(current, CAP_SYS_ADMIN);
        head->fmh_entries = 0;
 
        /* Set up our device handlers. */
index 2515fe8299e11485092b511d60725533808e8600..83481005317a40355220066d2059d02d10e3889c 100644 (file)
@@ -1189,7 +1189,7 @@ xfs_ioctl_setattr_get_trans(
                goto out_error;
 
        error = xfs_trans_alloc_ichange(ip, NULL, NULL, pdqp,
-                       capable(CAP_FOWNER), &tp);
+                       has_capability_noaudit(current, CAP_FOWNER), &tp);
        if (error)
                goto out_error;
 
index b79b3846e71be283e54d62eb071870a8b345e0bf..a65217f787cfcf6f7d1a5b523e11792c7224409c 100644 (file)
@@ -723,7 +723,7 @@ xfs_setattr_nonsize(
        }
 
        error = xfs_trans_alloc_ichange(ip, udqp, gdqp, NULL,
-                       capable(CAP_FOWNER), &tp);
+                       has_capability_noaudit(current, CAP_FOWNER), &tp);
        if (error)
                goto out_dqrele;
 
index 46a361dde0421a29e7fdd25386c9e0f1f6e6775a..765194f5d678f1856759522d6aeb6bcac97ba673 100644 (file)
@@ -360,6 +360,7 @@ bool has_capability_noaudit(struct task_struct *t, int cap)
 {
        return has_ns_capability_noaudit(t, &init_user_ns, cap);
 }
+EXPORT_SYMBOL(has_capability_noaudit);
 
 static bool ns_capable_common(struct user_namespace *ns,
                              int cap,