Skip to content
Permalink
Browse files
NFSv4 account for selinux security context when deciding to share sup…
…erblock

Keep track of whether or not there was an selinux context mount
options during the mount. While deciding if the superblock can be
shared for the new mount, check for if we had selinux context on
the existing mount and call into selinux to tell if new passed
in selinux context is compatible with the existing mount's options.

Previously, NFS wasn't able to do the following 2mounts:
mount -o vers=4.2,sec=sys,context=system_u:object_r:root_t:s0
<serverip>:/ /mnt
mount -o vers=4.2,sec=sys,context=system_u:object_r:swapfile_t:s0
<serverip>:/scratch /scratch

2nd mount would fail with "mount.nfs: an incorrect mount option was
specified" and var log messages would have:
"SElinux: mount invalid. Same superblock, different security
settings for.."

Signed-off-by: Olga Kornievskaia <kolga@netapp.com>
  • Loading branch information
Olga Kornievskaia authored and intel-lab-lkp committed Feb 12, 2021
1 parent 19fcad7 commit ff69e0bcc99716695e11ed2741b2e01d6014f960
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 0 deletions.
@@ -448,6 +448,9 @@ static int nfs_fs_context_parse_param(struct fs_context *fc,
if (opt < 0)
return ctx->sloppy ? 1 : opt;

if (fc->security)
ctx->has_sec_mnt_opts = 1;

switch (opt) {
case Opt_source:
if (fc->source)
@@ -96,6 +96,7 @@ struct nfs_fs_context {
char *fscache_uniq;
unsigned short protofamily;
unsigned short mountfamily;
bool has_sec_mnt_opts;

struct {
union {
@@ -1058,6 +1058,7 @@ static void nfs_fill_super(struct super_block *sb, struct nfs_fs_context *ctx)
&sb->s_blocksize_bits);

nfs_super_set_maxbytes(sb, server->maxfilesize);
server->has_sec_mnt_opts = ctx->has_sec_mnt_opts;
}

static int nfs_compare_mount_options(const struct super_block *s, const struct nfs_server *b,
@@ -1174,6 +1175,9 @@ static int nfs_compare_super(struct super_block *sb, struct fs_context *fc)
return 0;
if (!nfs_compare_userns(old, server))
return 0;
if ((old->has_sec_mnt_opts || fc->security) &&
!security_sb_do_mnt_opts_match(sb, fc->security))
return 0;
return nfs_compare_mount_options(sb, server, fc);
}

@@ -254,6 +254,7 @@ struct nfs_server {

/* User namespace info */
const struct cred *cred;
bool has_sec_mnt_opts;
};

/* Server capabilities */

0 comments on commit ff69e0b

Please sign in to comment.