Skip to contentSkip to conversation

selinux,smack: don't bypass permissions check in inode_setsecctx hook

PATCH Applied Scott Mayhew 6 participants 12 messages Aug 28, 2024 – Aug 29, 2024

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

cover selinux,smack: don't bypass permissions check in inode_setsecctx hook

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/[email protected]/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/[email protected]/
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(-)
Signature · 1 line
2.46.0
#1 lore raw

PATCH 1/1 selinux,smack: don't bypass permissions check in inode_setsecctx hook

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.

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.

---
 security/selinux/hooks.c   | 4 ++--
 security/smack/smack_lsm.c | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)
security/selinux/hooks.c +2 -2
index bfa61e005aac..400eca4ad0fb 100644
@@ -6660,8 +6660,8 @@ static int selinux_inode_notifysecctx(struct inode *inode, void *ctx, u32 ctxlen
  */
 static int selinux_inode_setsecctx(struct dentry *dentry, void *ctx, u32 ctxlen)
 {
-	return __vfs_setxattr_noperm(&nop_mnt_idmap, dentry, XATTR_NAME_SELINUX,
-				     ctx, ctxlen, 0);
+	return __vfs_setxattr_locked(&nop_mnt_idmap, dentry, XATTR_NAME_SELINUX,
+				     ctx, ctxlen, 0, NULL);
 }
 
 static int selinux_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen)
security/smack/smack_lsm.c +2 -2
index 4164699cd4f6..002a1b9ed83a 100644
@@ -4880,8 +4880,8 @@ static int smack_inode_notifysecctx(struct inode *inode, void *ctx, u32 ctxlen)
 
 static int smack_inode_setsecctx(struct dentry *dentry, void *ctx, u32 ctxlen)
 {
-	return __vfs_setxattr_noperm(&nop_mnt_idmap, dentry, XATTR_NAME_SMACK,
-				     ctx, ctxlen, 0);
+	return __vfs_setxattr_locked(&nop_mnt_idmap, dentry, XATTR_NAME_SMACK,
+				     ctx, ctxlen, 0, NULL);
 }
 
 static int smack_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen)
Signature · 1 line
2.46.0
maintainer Acked-by on v1 1/1
#2 lore raw
Quoted 49 lines · Scott Mayhew

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.

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.

---
 security/selinux/hooks.c   | 4 ++--
 security/smack/smack_lsm.c | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)
security/selinux/hooks.c +2 -2
index bfa61e005aac..400eca4ad0fb 100644
@@ -6660,8 +6660,8 @@ static int selinux_inode_notifysecctx(struct inode *inode, void *ctx, u32 ctxlen
  */
 static int selinux_inode_setsecctx(struct dentry *dentry, void *ctx, u32 ctxlen)
 {
-	return __vfs_setxattr_noperm(&nop_mnt_idmap, dentry, XATTR_NAME_SELINUX,
-				     ctx, ctxlen, 0);
+	return __vfs_setxattr_locked(&nop_mnt_idmap, dentry, XATTR_NAME_SELINUX,
+				     ctx, ctxlen, 0, NULL);
 }
 
 static int selinux_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen)
security/smack/smack_lsm.c +0 -0
index 4164699cd4f6..002a1b9ed83a 100644

security/smack/smack_lsm.c static int smack_inode_notifysecctx(struct inode *inode, void *ctx, u32 ctxlen) · line 4887

Quoted 10 lines
security/smack/smack_lsm.c +2 -2
@@ -4880,8 +4880,8 @@ static int smack_inode_notifysecctx(struct inode *inode, void *ctx, u32 ctxlen)
 
 static int smack_inode_setsecctx(struct dentry *dentry, void *ctx, u32 ctxlen)
 {
-	return __vfs_setxattr_noperm(&nop_mnt_idmap, dentry, XATTR_NAME_SMACK,
-				     ctx, ctxlen, 0);
+	return __vfs_setxattr_locked(&nop_mnt_idmap, dentry, XATTR_NAME_SMACK,
+				     ctx, ctxlen, 0, NULL);
 }
 
 static int smack_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen)
maintainer
#3 lore raw
In reply to Scott Mayhew
Quoted 22 lines · Scott Mayhew

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.

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.

Quoted 7 lines
---
 security/selinux/hooks.c   | 4 ++--
 security/smack/smack_lsm.c | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

Thanks Scott, this looks good to me, but since it touches Smack too I'd also like to get Casey's ACK on this patch; if for some reason we don't hear from Casey after a bit I'll go ahead and merge it. Speaking of merging, since this touches both SELinux and Smack I'll likely pull this in via the LSM tree, with a marking for the stable kernels, if anyone has any objections to that please let me know.

Signature · 1 line
paul-moore.com
maintainer
#4 lore raw
Quoted 29 lines · Paul Moore
Quoted 21 lines · Scott Mayhew

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.

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.

Quoted 7 lines
---
 security/selinux/hooks.c   | 4 ++--
 security/smack/smack_lsm.c | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)
Quoted 2 lines

Thanks Scott, this looks good to me, but since it touches Smack too I'd also like to get Casey's ACK on this patch;

Testing labeled NFS has always been a challenge for the somewhat limited resources available to the Smack project. I'll Ack the patch, but won't claim to have tested it.

Quoted 6 lines

if for some reason we
don't hear from Casey after a bit I'll go ahead and merge it. Speaking of merging, since this touches both SELinux and Smack I'll likely pull this in via the LSM tree, with a marking for the stable kernels, if anyone has any objections to that please let me know.

maintainer
#5 lore raw
Quoted 30 lines · Casey Schaufler
Quoted 29 lines · Paul Moore
Quoted 28 lines · Scott Mayhew

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.

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.

---
 security/selinux/hooks.c   | 4 ++--
 security/smack/smack_lsm.c | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)
Quoted 6 lines
Quoted 2 lines

Thanks Scott, this looks good to me, but since it touches Smack too I'd also like to get Casey's ACK on this patch;

Testing labeled NFS has always been a challenge for the somewhat limited resources available to the Smack project. I'll Ack the patch, but won't claim to have tested it.

Understood, thanks for the quick reply.

Signature · 1 line
paul-moore.com
maintainer Applied
#6 lore raw
In reply to Paul Moore
Quoted 31 lines · Paul Moore
Quoted 22 lines · Scott Mayhew

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.

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.

Quoted 7 lines
---
 security/selinux/hooks.c   | 4 ++--
 security/smack/smack_lsm.c | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)
Quoted 6 lines

Thanks Scott, this looks good to me, but since it touches Smack too I'd also like to get Casey's ACK on this patch; if for some reason we don't hear from Casey after a bit I'll go ahead and merge it. Speaking of merging, since this touches both SELinux and Smack I'll likely pull this in via the LSM tree, with a marking for the stable kernels, if anyone has any objections to that please let me know.

Merged into lsm/stable-6.11 so we can get this into linux-next and the automated SELinux testing, assuming all goes we'll I'll send this up to Linus later this week. Thanks all!

Signature · 1 line
paul-moore.com
#7 lore raw
Quoted 43 lines · Paul Moore
Quoted 31 lines · Paul Moore
Quoted 22 lines · Scott Mayhew

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.

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.

Quoted 7 lines

---
security/selinux/hooks.c | 4 ++--
security/smack/smack_lsm.c | 4 ++--

2 files changed, 4 insertions(+), 4 deletions(-)
Quoted 6 lines

Thanks Scott, this looks good to me, but since it touches Smack too I'd also like to get Casey's ACK on this patch; if for some reason we don't hear from Casey after a bit I'll go ahead and merge it. Speaking of merging, since this touches both SELinux and Smack I'll likely pull this in via the LSM tree, with a marking for the stable kernels, if anyone has any objections to that please let me know.

Quoted 3 lines

Merged into lsm/stable-6.11 so we can get this into linux-next and the automated SELinux testing, assuming all goes we'll I'll send this up to Linus later this week. Thanks all!

Paul, may I recommend adding Cc: stable once your testing passes?

--
Chuck Lever

maintainer
#8 lore raw
Quoted 7 lines · Chuck Lever III
Quoted 5 lines · Paul Moore

Merged into lsm/stable-6.11 so we can get this into linux-next and the automated SELinux testing, assuming all goes we'll I'll send this up to Linus later this week. Thanks all!

Paul, may I recommend adding Cc: stable once your testing passes?

Yep, I did that yesterday before merging. Typically if I merge anything into one of the stable-X.Y branches it gets a stable too. I'll update the commit in a few minutes with the tags from Jeff and Stephen.

https://git.kernel.org/pub/scm/linux/kernel/git/pcmoore/lsm.git/log/?h=stable-6.11

Signature · 1 line
paul-moore.com
Reviewed-by on v1 1/1
#9 lore raw
In reply to Scott Mayhew
Quoted 62 lines · Scott Mayhew

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.

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.

---
 security/selinux/hooks.c   | 4 ++--
 security/smack/smack_lsm.c | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)
security/selinux/hooks.c +2 -2
index bfa61e005aac..400eca4ad0fb 100644
@@ -6660,8 +6660,8 @@ static int selinux_inode_notifysecctx(struct inode *inode, void *ctx, u32 ctxlen
  */
 static int selinux_inode_setsecctx(struct dentry *dentry, void *ctx, u32 ctxlen)
 {
-	return __vfs_setxattr_noperm(&nop_mnt_idmap, dentry, XATTR_NAME_SELINUX,
-				     ctx, ctxlen, 0);
+	return __vfs_setxattr_locked(&nop_mnt_idmap, dentry, XATTR_NAME_SELINUX,
+				     ctx, ctxlen, 0, NULL);
 }
 
 static int selinux_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen)
security/smack/smack_lsm.c +2 -2
index 4164699cd4f6..002a1b9ed83a 100644
@@ -4880,8 +4880,8 @@ static int smack_inode_notifysecctx(struct inode *inode, void *ctx, u32 ctxlen)
 
 static int smack_inode_setsecctx(struct dentry *dentry, void *ctx, u32 ctxlen)
 {
-	return __vfs_setxattr_noperm(&nop_mnt_idmap, dentry, XATTR_NAME_SMACK,
-				     ctx, ctxlen, 0);
+	return __vfs_setxattr_locked(&nop_mnt_idmap, dentry, XATTR_NAME_SMACK,
+				     ctx, ctxlen, 0, NULL);
 }
 
 static int smack_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen)
Signature · 1 line
2.46.0

Nice, thorough work, Scott.

Signature · 1 line
Chuck Lever
maintainer Reviewed-by on v1 1/1
#10 lore raw
In reply to Scott Mayhew
Quoted 49 lines · Scott Mayhew

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.

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.

---
 security/selinux/hooks.c   | 4 ++--
 security/smack/smack_lsm.c | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)
security/selinux/hooks.c +2 -2
index bfa61e005aac..400eca4ad0fb 100644
@@ -6660,8 +6660,8 @@ static int selinux_inode_notifysecctx(struct inode *inode, void *ctx, u32 ctxlen
  */
 static int selinux_inode_setsecctx(struct dentry *dentry, void *ctx, u32 ctxlen)
 {
-	return __vfs_setxattr_noperm(&nop_mnt_idmap, dentry, XATTR_NAME_SELINUX,
-				     ctx, ctxlen, 0);
+	return __vfs_setxattr_locked(&nop_mnt_idmap, dentry, XATTR_NAME_SELINUX,
+				     ctx, ctxlen, 0, NULL);
 }
 
 static int selinux_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen)
security/smack/smack_lsm.c +0 -0
index 4164699cd4f6..002a1b9ed83a 100644

security/smack/smack_lsm.c static int smack_inode_notifysecctx(struct inode *inode, void *ctx, u32 ctxlen) · line 4887

Quoted 10 lines
security/smack/smack_lsm.c +2 -2
@@ -4880,8 +4880,8 @@ static int smack_inode_notifysecctx(struct inode *inode, void *ctx, u32 ctxlen)
 
 static int smack_inode_setsecctx(struct dentry *dentry, void *ctx, u32 ctxlen)
 {
-	return __vfs_setxattr_noperm(&nop_mnt_idmap, dentry, XATTR_NAME_SMACK,
-				     ctx, ctxlen, 0);
+	return __vfs_setxattr_locked(&nop_mnt_idmap, dentry, XATTR_NAME_SMACK,
+				     ctx, ctxlen, 0, NULL);
 }
 
 static int smack_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen)
maintainer Reviewed-by Tested-by
#11 lore raw
Quoted 60 lines · Jeff Layton
Quoted 58 lines · Scott Mayhew

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.

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.

---
 security/selinux/hooks.c   | 4 ++--
 security/smack/smack_lsm.c | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)
security/selinux/hooks.c +2 -2
index bfa61e005aac..400eca4ad0fb 100644
@@ -6660,8 +6660,8 @@ static int selinux_inode_notifysecctx(struct inode *inode, void *ctx, u32 ctxlen
  */
 static int selinux_inode_setsecctx(struct dentry *dentry, void *ctx, u32 ctxlen)
 {
-     return __vfs_setxattr_noperm(&nop_mnt_idmap, dentry, XATTR_NAME_SELINUX,
-                                  ctx, ctxlen, 0);
+     return __vfs_setxattr_locked(&nop_mnt_idmap, dentry, XATTR_NAME_SELINUX,
+                                  ctx, ctxlen, 0, NULL);
 }
 
 static int selinux_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen)
security/smack/smack_lsm.c +2 -2
index 4164699cd4f6..002a1b9ed83a 100644
@@ -4880,8 +4880,8 @@ static int smack_inode_notifysecctx(struct inode *inode, void *ctx, u32 ctxlen)
 
 static int smack_inode_setsecctx(struct dentry *dentry, void *ctx, u32 ctxlen)
 {
-     return __vfs_setxattr_noperm(&nop_mnt_idmap, dentry, XATTR_NAME_SMACK,
-                                  ctx, ctxlen, 0);
+     return __vfs_setxattr_locked(&nop_mnt_idmap, dentry, XATTR_NAME_SMACK,
+                                  ctx, ctxlen, 0, NULL);
 }
 
Quoted 3 lines

security/smack/smack_lsm.c static int smack_inode_notifysecctx(struct inode *inode, void *ctx, u32 ctxlen) · line 4887

Quoted 1 line
security/smack/smack_lsm.c +0 -0
 static int smack_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen)

Passes all the NFS tests in the selinux-testsuite, and also correctly denies root the ability to relabel a file on a root_squash mount but allows a normal user to do so (as expected).