Skip to content

Commit ec1ade6

Browse files
olgakorn1pcmoore
authored andcommitted
nfs: account for selinux security context when deciding to share superblock
Keep track of whether or not there were LSM security context options passed during mount (ie creation of the superblock). Then, while deciding if the superblock can be shared for the new mount, check if the newly passed in LSM security context options are compatible with the existing superblock's ones by calling security_sb_mnt_opts_compat(). Previously, with selinux enabled, 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> [PM: tweak subject line] Signed-off-by: Paul Moore <paul@paul-moore.com>
1 parent 8c6d76a commit ec1ade6

4 files changed

Lines changed: 9 additions & 0 deletions

File tree

fs/nfs/fs_context.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,9 @@ static int nfs_fs_context_parse_param(struct fs_context *fc,
463463
if (opt < 0)
464464
return ctx->sloppy ? 1 : opt;
465465

466+
if (fc->security)
467+
ctx->has_sec_mnt_opts = 1;
468+
466469
switch (opt) {
467470
case Opt_source:
468471
if (fc->source)

fs/nfs/internal.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ struct nfs_fs_context {
9696
char *fscache_uniq;
9797
unsigned short protofamily;
9898
unsigned short mountfamily;
99+
bool has_sec_mnt_opts;
99100

100101
struct {
101102
union {

fs/nfs/super.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1077,6 +1077,7 @@ static void nfs_fill_super(struct super_block *sb, struct nfs_fs_context *ctx)
10771077
&sb->s_blocksize_bits);
10781078

10791079
nfs_super_set_maxbytes(sb, server->maxfilesize);
1080+
server->has_sec_mnt_opts = ctx->has_sec_mnt_opts;
10801081
}
10811082

10821083
static int nfs_compare_mount_options(const struct super_block *s, const struct nfs_server *b,
@@ -1193,6 +1194,9 @@ static int nfs_compare_super(struct super_block *sb, struct fs_context *fc)
11931194
return 0;
11941195
if (!nfs_compare_userns(old, server))
11951196
return 0;
1197+
if ((old->has_sec_mnt_opts || fc->security) &&
1198+
security_sb_mnt_opts_compat(sb, fc->security))
1199+
return 0;
11961200
return nfs_compare_mount_options(sb, server, fc);
11971201
}
11981202

include/linux/nfs_fs_sb.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ struct nfs_server {
256256

257257
/* User namespace info */
258258
const struct cred *cred;
259+
bool has_sec_mnt_opts;
259260
};
260261

261262
/* Server capabilities */

0 commit comments

Comments
 (0)