From: Scott Mayhew <smayhew@redhat.com>
To: paul@paul-moore.com, stephen.smalley.work@gmail.com,
casey@schaufler-ca.com
Cc: chuck.lever@oracle.com, marek.gresko@protonmail.com,
selinux@vger.kernel.org, linux-security-module@vger.kernel.org,
linux-nfs@vger.kernel.org
Subject: [PATCH 0/1] selinux,smack: don't bypass permissions check in inode_setsecctx hook
Date: Wed, 28 Aug 2024 15:51:28 -0400 [thread overview]
Message-ID: <20240828195129.223395-1-smayhew@redhat.com> (raw)
Marek Gresko reports that the root user on an NFS client is able to
change the security labels on files on an NFS filesystem that is
exported with root squashing enabled.
I wasn't able to do a bisect on this issue... partially because when I
go back far enough I have trouble building a kernel that actually boots
in a KVM guest, but also because not all of the related code landed in
mainline at the same time (more on that in a bit).
Although I wasn't able to do a bisect, I do believe this behavior goes
all the way back to the introduction of labeled NFS. I was able to
reproduce this behavior on all versions of RHEL, going all the way back
to RHEL 7.0, which was based on a 3.10 kernel with post-3.10 code
(including the labeled NFS code) backported on top.
The v1 posting of the labeled NFS patchset actually mentions a similar
issue related to root squashing:
https://lore.kernel.org/lkml/7e0fb38c0802280622o75a474deg38157ff6aace16b@mail.gmail.com/t/
There is no mention of root squashing issues (fixed or otherwise) in
subsequent postings.
The inode_setsecctx hooks first appear in v2:
https://lore.kernel.org/all/1221511278-28051-1-git-send-email-dpquigl@tycho.nsa.gov/
The posting mentions other mailing list discussions related to the
hooks, but I'm not really able to find anything specific on why the
caller of the setsecctx hook would be expected to perform the
permissions checking rather than doing it in the hook itself.
The inode_setsecctx hook was merged in September 2009 (merge commit
f6f79190866d). It looks like this was for labeling support on sysfs,
which used the inode_getsecctx and inode_notifysecctx hooks, but not the
inode_setsecctx hook. It doesn't look like there was any user of the
inode_setsecctx hook until the labeled NFS code was merged in July 2013
(merge commit 0ff08ba5d066).
The end of the kerneldoc comment for __vfs_setxattr_noperm() states:
* This function requires the caller to lock the inode's i_mutex before it
* is executed. It also assumes that the caller will make the appropriate
* permission checks.
nfsd_setattr() does do permissions checking via fh_verify() and
nfsd_permission(), but those don't do all the same permissions checks
that are done by security_inode_setxattr() and its related LSM hooks do.
Since nfsd_setattr() is the only consumer of security_inode_setsecctx(),
simplest solution appears to be to replace the call to
__vfs_setxattr_noperm() with a call to __vfs_setxattr_locked(). This
fixes the above issue and has the added benefit of causing nfsd to
recall conflicting delegations on a file when a client tries to change
its security label.
I guess it's also worth mentioning that when nfsd rejects root's attempt
to set a label on a file on a root squashed export, the error on the
wire is NFS4ERR_PERM rather than NFS4ERR_ACCESS.
-Scott
Scott Mayhew (1):
selinux,smack: don't bypass permissions check in inode_setsecctx hook
security/selinux/hooks.c | 4 ++--
security/smack/smack_lsm.c | 4 ++--
2 files changed, 4 insertions(+), 4 deletions(-)
--
2.46.0
next reply other threads:[~2024-08-28 19:51 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-28 19:51 Scott Mayhew [this message]
2024-08-28 19:51 ` [PATCH 1/1] selinux,smack: don't bypass permissions check in inode_setsecctx hook Scott Mayhew
2024-08-28 20:03 ` Jeff Layton
2024-08-28 21:05 ` Paul Moore
2024-08-28 21:28 ` Casey Schaufler
2024-08-28 23:08 ` Paul Moore
2024-08-28 23:19 ` Paul Moore
2024-08-29 14:16 ` Chuck Lever III
2024-08-29 14:51 ` Paul Moore
2024-08-28 21:08 ` Chuck Lever
2024-08-29 11:15 ` Jeff Layton
2024-08-29 13:03 ` Stephen Smalley
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240828195129.223395-1-smayhew@redhat.com \
--to=smayhew@redhat.com \
--cc=casey@schaufler-ca.com \
--cc=chuck.lever@oracle.com \
--cc=linux-nfs@vger.kernel.org \
--cc=linux-security-module@vger.kernel.org \
--cc=marek.gresko@protonmail.com \
--cc=paul@paul-moore.com \
--cc=selinux@vger.kernel.org \
--cc=stephen.smalley.work@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox