All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 1/2] [security] Add new hook to compare new mount to an existing mount
@ 2021-02-18 19:50 Olga Kornievskaia
  2021-02-18 19:50 ` [PATCH v2 2/2] NFSv4 account for selinux security context when deciding to share superblock Olga Kornievskaia
  2021-02-18 21:57 ` [PATCH v2 1/2] [security] Add new hook to compare new mount to an existing mount Casey Schaufler
  0 siblings, 2 replies; 15+ messages in thread
From: Olga Kornievskaia @ 2021-02-18 19:50 UTC (permalink / raw)
  To: trond.myklebust, anna.schumaker; +Cc: linux-nfs, linux-security-module, selinux

From: Olga Kornievskaia <kolga@netapp.com>

Add a new hook that takes an existing super block and a new mount
with new options and determines if new options confict with an
existing mount or not.

Signed-off-by: Olga Kornievskaia <kolga@netapp.com>
`
---
 include/linux/lsm_hook_defs.h |  1 +
 include/linux/lsm_hooks.h     |  6 ++++
 include/linux/security.h      |  8 ++++++
 security/security.c           |  7 +++++
 security/selinux/hooks.c      | 54 +++++++++++++++++++++++++++++++++++
 5 files changed, 76 insertions(+)

diff --git a/include/linux/lsm_hook_defs.h b/include/linux/lsm_hook_defs.h
index 7aaa753b8608..1b12a5266a51 100644
--- a/include/linux/lsm_hook_defs.h
+++ b/include/linux/lsm_hook_defs.h
@@ -62,6 +62,7 @@ LSM_HOOK(int, 0, sb_alloc_security, struct super_block *sb)
 LSM_HOOK(void, LSM_RET_VOID, sb_free_security, struct super_block *sb)
 LSM_HOOK(void, LSM_RET_VOID, sb_free_mnt_opts, void *mnt_opts)
 LSM_HOOK(int, 0, sb_eat_lsm_opts, char *orig, void **mnt_opts)
+LSM_HOOK(int, 0, sb_mnt_opts_compat, struct super_block *sb, void *mnt_opts)
 LSM_HOOK(int, 0, sb_remount, struct super_block *sb, void *mnt_opts)
 LSM_HOOK(int, 0, sb_kern_mount, struct super_block *sb)
 LSM_HOOK(int, 0, sb_show_options, struct seq_file *m, struct super_block *sb)
diff --git a/include/linux/lsm_hooks.h b/include/linux/lsm_hooks.h
index a19adef1f088..77c1e9cdeaca 100644
--- a/include/linux/lsm_hooks.h
+++ b/include/linux/lsm_hooks.h
@@ -142,6 +142,12 @@
  *	@orig the original mount data copied from userspace.
  *	@copy copied data which will be passed to the security module.
  *	Returns 0 if the copy was successful.
+ * @sb_mnt_opts_compat:
+ *	Determine if the existing mount options are compatible with the new
+ *	mount options being used.
+ *	@sb superblock being compared
+ *	@mnt_opts new mount options
+ *	Return 0 if options are the same.
  * @sb_remount:
  *	Extracts security system specific mount options and verifies no changes
  *	are being made to those options.
diff --git a/include/linux/security.h b/include/linux/security.h
index c35ea0ffccd9..50db3d5d1608 100644
--- a/include/linux/security.h
+++ b/include/linux/security.h
@@ -291,6 +291,7 @@ int security_sb_alloc(struct super_block *sb);
 void security_sb_free(struct super_block *sb);
 void security_free_mnt_opts(void **mnt_opts);
 int security_sb_eat_lsm_opts(char *options, void **mnt_opts);
+int security_sb_mnt_opts_compat(struct super_block *sb, void *mnt_opts);
 int security_sb_remount(struct super_block *sb, void *mnt_opts);
 int security_sb_kern_mount(struct super_block *sb);
 int security_sb_show_options(struct seq_file *m, struct super_block *sb);
@@ -635,6 +636,13 @@ static inline int security_sb_remount(struct super_block *sb,
 	return 0;
 }
 
+static inline int security_sb_mnt_opts_compat(struct super_block *sb,
+					      void *mnt_opts)
+{
+	return 0;
+}
+
+
 static inline int security_sb_kern_mount(struct super_block *sb)
 {
 	return 0;
diff --git a/security/security.c b/security/security.c
index 7b09cfbae94f..56cf5563efde 100644
--- a/security/security.c
+++ b/security/security.c
@@ -890,6 +890,13 @@ int security_sb_eat_lsm_opts(char *options, void **mnt_opts)
 }
 EXPORT_SYMBOL(security_sb_eat_lsm_opts);
 
+int security_sb_mnt_opts_compat(struct super_block *sb,
+				void *mnt_opts)
+{
+	return call_int_hook(sb_mnt_opts_compat, 0, sb, mnt_opts);
+}
+EXPORT_SYMBOL(security_sb_mnt_opts_compat);
+
 int security_sb_remount(struct super_block *sb,
 			void *mnt_opts)
 {
diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
index 644b17ec9e63..f0b8ebc1e2c2 100644
--- a/security/selinux/hooks.c
+++ b/security/selinux/hooks.c
@@ -2656,6 +2656,59 @@ static int selinux_sb_eat_lsm_opts(char *options, void **mnt_opts)
 	return rc;
 }
 
+static int selinux_sb_mnt_opts_compat(struct super_block *sb, void *mnt_opts)
+{
+	struct selinux_mnt_opts *opts = mnt_opts;
+	struct superblock_security_struct *sbsec = sb->s_security;
+	u32 sid;
+	int rc;
+
+	/* superblock not initialized (i.e. no options) - reject if any
+	 * options specified, otherwise accept
+	 */
+	if (!(sbsec->flags & SE_SBINITIALIZED))
+		return opts ? 1 : 0;
+
+	/* superblock initialized and no options specified - reject if
+	 * superblock has any options set, otherwise accept
+	 */
+	if (!opts)
+		return (sbsec->flags & SE_MNTMASK) ? 1 : 0;
+
+	if (opts->fscontext) {
+		rc = parse_sid(sb, opts->fscontext, &sid);
+		if (rc)
+			return 1;
+		if (bad_option(sbsec, FSCONTEXT_MNT, sbsec->sid, sid))
+			return 1;
+	}
+	if (opts->context) {
+		rc = parse_sid(sb, opts->context, &sid);
+		if (rc)
+			return 1;
+		if (bad_option(sbsec, CONTEXT_MNT, sbsec->mntpoint_sid, sid))
+			return 1;
+	}
+	if (opts->rootcontext) {
+		struct inode_security_struct *root_isec;
+
+		root_isec = backing_inode_security(sb->s_root);
+		rc = parse_sid(sb, opts->rootcontext, &sid);
+		if (rc)
+			return 1;
+		if (bad_option(sbsec, ROOTCONTEXT_MNT, root_isec->sid, sid))
+			return 1;
+	}
+	if (opts->defcontext) {
+		rc = parse_sid(sb, opts->defcontext, &sid);
+		if (rc)
+			return 1;
+		if (bad_option(sbsec, DEFCONTEXT_MNT, sbsec->def_sid, sid))
+			return 1;
+	}
+	return 0;
+}
+
 static int selinux_sb_remount(struct super_block *sb, void *mnt_opts)
 {
 	struct selinux_mnt_opts *opts = mnt_opts;
@@ -6984,6 +7037,7 @@ static struct security_hook_list selinux_hooks[] __lsm_ro_after_init = {
 
 	LSM_HOOK_INIT(sb_free_security, selinux_sb_free_security),
 	LSM_HOOK_INIT(sb_free_mnt_opts, selinux_free_mnt_opts),
+	LSM_HOOK_INIT(sb_mnt_opts_compat, selinux_sb_mnt_opts_compat),
 	LSM_HOOK_INIT(sb_remount, selinux_sb_remount),
 	LSM_HOOK_INIT(sb_kern_mount, selinux_sb_kern_mount),
 	LSM_HOOK_INIT(sb_show_options, selinux_sb_show_options),
-- 
2.27.0


^ permalink raw reply related	[flat|nested] 15+ messages in thread
* Re: [PATCH v2 2/2] NFSv4 account for selinux security context when deciding to share superblock
@ 2021-02-19  0:22 kernel test robot
  0 siblings, 0 replies; 15+ messages in thread
From: kernel test robot @ 2021-02-19  0:22 UTC (permalink / raw)
  To: kbuild

[-- Attachment #1: Type: text/plain, Size: 5343 bytes --]

CC: kbuild-all(a)lists.01.org
In-Reply-To: <20210218195046.19280-2-olga.kornievskaia@gmail.com>
References: <20210218195046.19280-2-olga.kornievskaia@gmail.com>
TO: Olga Kornievskaia <olga.kornievskaia@gmail.com>
TO: trond.myklebust(a)hammerspace.com
TO: anna.schumaker(a)netapp.com
CC: linux-nfs(a)vger.kernel.org
CC: linux-security-module(a)vger.kernel.org
CC: selinux(a)vger.kernel.org

Hi Olga,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on nfs/linux-next]
[also build test WARNING on pcmoore-selinux/next linus/master security/next-testing v5.11 next-20210218]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Olga-Kornievskaia/Add-new-hook-to-compare-new-mount-to-an-existing-mount/20210219-035957
base:   git://git.linux-nfs.org/projects/trondmy/linux-nfs.git linux-next
:::::: branch date: 4 hours ago
:::::: commit date: 4 hours ago
config: i386-randconfig-m021-20210215 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-15) 9.3.0

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>

smatch warnings:
fs/nfs/super.c:1061 nfs_fill_super() error: we previously assumed 'ctx' could be null (see line 1029)

vim +/ctx +1061 fs/nfs/super.c

48b605f83c920d Jeff Layton       2008-06-10  1017  
f7b422b17ee5ee David Howells     2006-06-09  1018  /*
ab88dca311a372 Al Viro           2019-12-10  1019   * Finish setting up an NFS superblock
f7b422b17ee5ee David Howells     2006-06-09  1020   */
62a55d088cd87d Scott Mayhew      2019-12-10  1021  static void nfs_fill_super(struct super_block *sb, struct nfs_fs_context *ctx)
f7b422b17ee5ee David Howells     2006-06-09  1022  {
54ceac45159860 David Howells     2006-08-22  1023  	struct nfs_server *server = NFS_SB(sb);
f7b422b17ee5ee David Howells     2006-06-09  1024  
f7b422b17ee5ee David Howells     2006-06-09  1025  	sb->s_blocksize_bits = 0;
f7b422b17ee5ee David Howells     2006-06-09  1026  	sb->s_blocksize = 0;
6a74490dca8974 Bryan Schumaker   2012-07-30  1027  	sb->s_xattr = server->nfs_client->cl_nfs_mod->xattr;
6a74490dca8974 Bryan Schumaker   2012-07-30  1028  	sb->s_op = server->nfs_client->cl_nfs_mod->sops;
5eb005caf5383d David Howells     2019-12-10 @1029  	if (ctx && ctx->bsize)
5eb005caf5383d David Howells     2019-12-10  1030  		sb->s_blocksize = nfs_block_size(ctx->bsize, &sb->s_blocksize_bits);
f7b422b17ee5ee David Howells     2006-06-09  1031  
6a74490dca8974 Bryan Schumaker   2012-07-30  1032  	if (server->nfs_client->rpc_ops->version != 2) {
54ceac45159860 David Howells     2006-08-22  1033  		/* The VFS shouldn't apply the umask to mode bits. We will do
54ceac45159860 David Howells     2006-08-22  1034  		 * so ourselves when necessary.
54ceac45159860 David Howells     2006-08-22  1035  		 */
1751e8a6cb935e Linus Torvalds    2017-11-27  1036  		sb->s_flags |= SB_POSIXACL;
54ceac45159860 David Howells     2006-08-22  1037  		sb->s_time_gran = 1;
20fa1902728698 Peng Tao          2017-06-29  1038  		sb->s_export_op = &nfs_export_ops;
1fcb79c1b21801 Deepa Dinamani    2019-03-26  1039  	} else
1fcb79c1b21801 Deepa Dinamani    2019-03-26  1040  		sb->s_time_gran = 1000;
1fcb79c1b21801 Deepa Dinamani    2019-03-26  1041  
1fcb79c1b21801 Deepa Dinamani    2019-03-26  1042  	if (server->nfs_client->rpc_ops->version != 4) {
1fcb79c1b21801 Deepa Dinamani    2019-03-26  1043  		sb->s_time_min = 0;
1fcb79c1b21801 Deepa Dinamani    2019-03-26  1044  		sb->s_time_max = U32_MAX;
1fcb79c1b21801 Deepa Dinamani    2019-03-26  1045  	} else {
1fcb79c1b21801 Deepa Dinamani    2019-03-26  1046  		sb->s_time_min = S64_MIN;
1fcb79c1b21801 Deepa Dinamani    2019-03-26  1047  		sb->s_time_max = S64_MAX;
54ceac45159860 David Howells     2006-08-22  1048  	}
f7b422b17ee5ee David Howells     2006-06-09  1049  
ab88dca311a372 Al Viro           2019-12-10  1050  	sb->s_magic = NFS_SUPER_MAGIC;
54ceac45159860 David Howells     2006-08-22  1051  
ab88dca311a372 Al Viro           2019-12-10  1052  	/* We probably want something more informative here */
ab88dca311a372 Al Viro           2019-12-10  1053  	snprintf(sb->s_id, sizeof(sb->s_id),
ab88dca311a372 Al Viro           2019-12-10  1054  		 "%u:%u", MAJOR(sb->s_dev), MINOR(sb->s_dev));
1fcb79c1b21801 Deepa Dinamani    2019-03-26  1055  
ab88dca311a372 Al Viro           2019-12-10  1056  	if (sb->s_blocksize == 0)
ab88dca311a372 Al Viro           2019-12-10  1057  		sb->s_blocksize = nfs_block_bits(server->wsize,
ab88dca311a372 Al Viro           2019-12-10  1058  						 &sb->s_blocksize_bits);
f7b422b17ee5ee David Howells     2006-06-09  1059  
ab88dca311a372 Al Viro           2019-12-10  1060  	nfs_super_set_maxbytes(sb, server->maxfilesize);
52a2a3a4af9af7 Olga Kornievskaia 2021-02-18 @1061  	server->has_sec_mnt_opts = ctx->has_sec_mnt_opts;
f7b422b17ee5ee David Howells     2006-06-09  1062  }
f7b422b17ee5ee David Howells     2006-06-09  1063  

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

[-- Attachment #2: config.gz --]
[-- Type: application/gzip, Size: 38051 bytes --]

^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2021-02-19 20:08 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-02-18 19:50 [PATCH v2 1/2] [security] Add new hook to compare new mount to an existing mount Olga Kornievskaia
2021-02-18 19:50 ` [PATCH v2 2/2] NFSv4 account for selinux security context when deciding to share superblock Olga Kornievskaia
2021-02-18 22:07   ` Casey Schaufler
2021-02-18 22:39     ` Olga Kornievskaia
2021-02-18 23:17       ` Casey Schaufler
2021-02-19 17:11         ` Olga Kornievskaia
2021-02-19  8:19   ` Dan Carpenter
2021-02-19  8:19     ` Dan Carpenter
2021-02-19  8:19     ` Dan Carpenter
2021-02-19 17:20     ` Olga Kornievskaia
2021-02-19 20:07       ` Trond Myklebust
2021-02-18 21:57 ` [PATCH v2 1/2] [security] Add new hook to compare new mount to an existing mount Casey Schaufler
2021-02-19 16:25   ` Olga Kornievskaia
2021-02-19 16:45     ` Casey Schaufler
  -- strict thread matches above, loose matches on Subject: below --
2021-02-19  0:22 [PATCH v2 2/2] NFSv4 account for selinux security context when deciding to share superblock kernel test robot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.