From patchwork Tue Mar 16 17:32:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ondrej Mosnacek X-Patchwork-Id: 12143301 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 842A6C433E0 for ; Tue, 16 Mar 2021 17:33:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 58F1B6511D for ; Tue, 16 Mar 2021 17:33:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229559AbhCPRct (ORCPT ); Tue, 16 Mar 2021 13:32:49 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:48550 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238794AbhCPRcc (ORCPT ); Tue, 16 Mar 2021 13:32:32 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1615915951; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=5AId5vG2TVOeo8m549ZwO+E0JsBnovD7rLmlFTc7A5s=; b=Y23PPJ703Tw8r6zHod5MO65J9hrsGHmYzHvfehJ5YIS8xhl8HrIhVvjWOG/Lxvet0apufa vzf8CzZAegp8t4K7IW4T+l/nZXJLEJBf7HV+/tl6cVMxkCo+lOK8h8oN4p/QzkdW3e3GpA Uo7iI5XFLYXfr8pVwC3BO0IXUDoPb68= Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com [209.85.208.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-537-vqM_UV6jOGi4HMLVUdQejQ-1; Tue, 16 Mar 2021 13:32:30 -0400 X-MC-Unique: vqM_UV6jOGi4HMLVUdQejQ-1 Received: by mail-ed1-f72.google.com with SMTP id y10so5679155edr.20 for ; Tue, 16 Mar 2021 10:32:30 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=5AId5vG2TVOeo8m549ZwO+E0JsBnovD7rLmlFTc7A5s=; b=oLdtMRjk3qc8BE29m2HM0i8uByfT6U7oRTmWnPMBj63xazCtCHGYXt0D+HlQiDLr+D P7t1LPjRjQ5ShSBkHYKNnafoA3fmafT1GfDctq2654orr2GzjYUaY89WYqF6mGwESsTb UEFOPQJdnamCCpWxS9TShUIIswiuSW7rNNEqQQyYoFUah2nlNWwOxzvr+etfMz6JB8aT mcsbokuARaA2X+Gv5zQY6xVhHeOYsyBqyRY55ebzbhtgVrI/Lk5RTDYIDTmyhZj9FJe0 ibWgHIzyK+Q7geJNAYrpnwcRDq6S6kQuGReL1S5b+GLyZYdCZ/MqmXiSYJe9Hj+tBJe/ uokA== X-Gm-Message-State: AOAM532ft2IkMQVORxPknmivDRoAIrOweoxXuWOr/bHNN3KtCDazY1Yi 7Row81n+6kQNsyjO+qGNNtzBJ8/qFjd0VRmnP+TLF9k4VUiLz0JFbYmfjxPn6efZdnFeyv3LZRO ZBoz8t1WPlzF8YHqcHoa8F8KSeyF5zmC0Z/rF X-Received: by 2002:a17:906:4107:: with SMTP id j7mr14812376ejk.185.1615915948780; Tue, 16 Mar 2021 10:32:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxy72OaCt395g1j1vbcWykD2mZ7XNXhxeIpmOZq445d0B0Zjj/QF98NlqH/ld16pJ+Jex7WpA== X-Received: by 2002:a17:906:4107:: with SMTP id j7mr14812361ejk.185.1615915948621; Tue, 16 Mar 2021 10:32:28 -0700 (PDT) Received: from omos.redhat.com ([2a02:8308:b105:dd00:277b:6436:24db:9466]) by smtp.gmail.com with ESMTPSA id bt14sm11175862edb.92.2021.03.16.10.32.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Mar 2021 10:32:28 -0700 (PDT) From: Ondrej Mosnacek To: "Darrick J . Wong" , linux-xfs@vger.kernel.org Cc: linux-security-module@vger.kernel.org, selinux@vger.kernel.org Subject: [PATCH] xfs: use has_capability_noaudit() instead of capable() where appropriate Date: Tue, 16 Mar 2021 18:32:26 +0100 Message-Id: <20210316173226.2220046-1-omosnace@redhat.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=omosnace@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Precedence: bulk List-ID: In cases when a negative result of a capability check doesn't lead to an immediate, user-visible error, only a subtle difference in behavior, it is better to use has_capability_noaudit(current, ...), so that LSMs (e.g. SELinux) don't generate a denial record in the audit log each time the capability status is queried. This patch should cover all such cases in fs/xfs/. Note that I kept the capable(CAP_FSETID) checks, since these will only be executed if the user explicitly tries to set the SUID/SGID bit, and it likely makes sense to log such attempts even if the syscall doesn't fail and just ignores the bits. Signed-off-by: Ondrej Mosnacek --- fs/xfs/xfs_fsmap.c | 4 ++-- fs/xfs/xfs_ioctl.c | 5 ++++- fs/xfs/xfs_iops.c | 6 ++++-- fs/xfs/xfs_xattr.c | 2 +- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/fs/xfs/xfs_fsmap.c b/fs/xfs/xfs_fsmap.c index 9ce5e7d5bf8f..14672e7ee535 100644 --- a/fs/xfs/xfs_fsmap.c +++ b/fs/xfs/xfs_fsmap.c @@ -842,8 +842,8 @@ xfs_getfsmap( !xfs_getfsmap_is_valid_device(mp, &head->fmh_keys[1])) return -EINVAL; - use_rmap = capable(CAP_SYS_ADMIN) && - xfs_sb_version_hasrmapbt(&mp->m_sb); + use_rmap = xfs_sb_version_hasrmapbt(&mp->m_sb) && + has_capability_noaudit(current, CAP_SYS_ADMIN); head->fmh_entries = 0; /* Set up our device handlers. */ diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c index 3fbd98f61ea5..3cfc1a25069c 100644 --- a/fs/xfs/xfs_ioctl.c +++ b/fs/xfs/xfs_ioctl.c @@ -1470,8 +1470,11 @@ xfs_ioctl_setattr( if (XFS_IS_QUOTA_RUNNING(mp) && XFS_IS_PQUOTA_ON(mp) && ip->i_d.di_projid != fa->fsx_projid) { + int flags = has_capability_noaudit(current, CAP_FOWNER) ? + XFS_QMOPT_FORCE_RES : 0; + code = xfs_qm_vop_chown_reserve(tp, ip, NULL, NULL, pdqp, - capable(CAP_FOWNER) ? XFS_QMOPT_FORCE_RES : 0); + flags); if (code) /* out of quota */ goto error_trans_cancel; } diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c index 67c8dc9de8aa..abbb417c4fbd 100644 --- a/fs/xfs/xfs_iops.c +++ b/fs/xfs/xfs_iops.c @@ -729,10 +729,12 @@ xfs_setattr_nonsize( if (XFS_IS_QUOTA_RUNNING(mp) && ((XFS_IS_UQUOTA_ON(mp) && !uid_eq(iuid, uid)) || (XFS_IS_GQUOTA_ON(mp) && !gid_eq(igid, gid)))) { + int flags = has_capability_noaudit(current, CAP_FOWNER) ? + XFS_QMOPT_FORCE_RES : 0; + ASSERT(tp); error = xfs_qm_vop_chown_reserve(tp, ip, udqp, gdqp, - NULL, capable(CAP_FOWNER) ? - XFS_QMOPT_FORCE_RES : 0); + NULL, flags); if (error) /* out of quota */ goto out_cancel; } diff --git a/fs/xfs/xfs_xattr.c b/fs/xfs/xfs_xattr.c index bca48b308c02..a99d19c2c11f 100644 --- a/fs/xfs/xfs_xattr.c +++ b/fs/xfs/xfs_xattr.c @@ -164,7 +164,7 @@ xfs_xattr_put_listent( * Only show root namespace entries if we are actually allowed to * see them. */ - if (!capable(CAP_SYS_ADMIN)) + if (!has_capability_noaudit(current, CAP_SYS_ADMIN)) return; prefix = XATTR_TRUSTED_PREFIX;