From: Yafang Shao <laoar.shao@gmail.com>
To: akpm@linux-foundation.org, paul@paul-moore.com,
jmorris@namei.org, serge@hallyn.com
Cc: linux-mm@kvack.org, linux-security-module@vger.kernel.org,
bpf@vger.kernel.org, ligang.bdlg@bytedance.com, mhocko@suse.com,
Yafang Shao <laoar.shao@gmail.com>
Subject: [RFC PATCH -mm 1/4] mm, security: Add lsm hook for mbind(2)
Date: Sun, 12 Nov 2023 07:34:21 +0000 [thread overview]
Message-ID: <20231112073424.4216-2-laoar.shao@gmail.com> (raw)
In-Reply-To: <20231112073424.4216-1-laoar.shao@gmail.com>
In container environment, we don't want users to bind their memory to a
specific numa node, while we want to unit control memory resource with
kubelet. Therefore, add a new lsm hook for mbind(2), then we can enforce
fine-grained control over memory policy adjustment by the tasks in a
container.
Signed-off-by: Yafang Shao <laoar.shao@gmail.com>
---
include/linux/lsm_hook_defs.h | 4 ++++
include/linux/security.h | 10 ++++++++++
mm/mempolicy.c | 4 ++++
security/security.c | 7 +++++++
4 files changed, 25 insertions(+)
diff --git a/include/linux/lsm_hook_defs.h b/include/linux/lsm_hook_defs.h
index 99b8176..b1b5e3a 100644
--- a/include/linux/lsm_hook_defs.h
+++ b/include/linux/lsm_hook_defs.h
@@ -419,3 +419,7 @@
LSM_HOOK(int, 0, uring_sqpoll, void)
LSM_HOOK(int, 0, uring_cmd, struct io_uring_cmd *ioucmd)
#endif /* CONFIG_IO_URING */
+
+LSM_HOOK(int, 0, mbind, unsigned long start, unsigned long len,
+ unsigned long mode, const unsigned long __user *nmask,
+ unsigned long maxnode, unsigned int flags)
diff --git a/include/linux/security.h b/include/linux/security.h
index 1d1df326..9f87543 100644
--- a/include/linux/security.h
+++ b/include/linux/security.h
@@ -484,6 +484,9 @@ int security_setprocattr(const char *lsm, const char *name, void *value,
int security_inode_setsecctx(struct dentry *dentry, void *ctx, u32 ctxlen);
int security_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen);
int security_locked_down(enum lockdown_reason what);
+int security_mbind(unsigned long start, unsigned long len,
+ unsigned long mode, const unsigned long __user *nmask,
+ unsigned long maxnode, unsigned int flags);
#else /* CONFIG_SECURITY */
static inline int call_blocking_lsm_notifier(enum lsm_event event, void *data)
@@ -1395,6 +1398,13 @@ static inline int security_locked_down(enum lockdown_reason what)
{
return 0;
}
+
+static inline int security_mbind(unsigned long start, unsigned long len,
+ unsigned long mode, const unsigned long __user *nmask,
+ unsigned long maxnode, unsigned int flags)
+{
+ return 0;
+}
#endif /* CONFIG_SECURITY */
#if defined(CONFIG_SECURITY) && defined(CONFIG_WATCH_QUEUE)
diff --git a/mm/mempolicy.c b/mm/mempolicy.c
index 10a590e..98a378c 100644
--- a/mm/mempolicy.c
+++ b/mm/mempolicy.c
@@ -1483,6 +1483,10 @@ static long kernel_mbind(unsigned long start, unsigned long len,
if (err)
return err;
+ err = security_mbind(start, len, mode, nmask, maxnode, flags);
+ if (err)
+ return err;
+
return do_mbind(start, len, lmode, mode_flags, &nodes, flags);
}
diff --git a/security/security.c b/security/security.c
index dcb3e70..425ec1c 100644
--- a/security/security.c
+++ b/security/security.c
@@ -5337,3 +5337,10 @@ int security_uring_cmd(struct io_uring_cmd *ioucmd)
return call_int_hook(uring_cmd, 0, ioucmd);
}
#endif /* CONFIG_IO_URING */
+
+int security_mbind(unsigned long start, unsigned long len,
+ unsigned long mode, const unsigned long __user *nmask,
+ unsigned long maxnode, unsigned int flags)
+{
+ return call_int_hook(mbind, 0, start, len, mode, nmask, maxnode, flags);
+}
--
1.8.3.1
next prev parent reply other threads:[~2023-11-12 7:35 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-12 7:34 [RFC PATCH -mm 0/4] mm, security, bpf: Fine-grained control over memory policy adjustments with lsm bpf Yafang Shao
2023-11-12 7:34 ` Yafang Shao [this message]
2023-11-12 7:34 ` [RFC PATCH -mm 2/4] mm, security: Add lsm hook for set_mempolicy(2) Yafang Shao
2023-11-12 7:34 ` [RFC PATCH -mm 3/4] mm, security: Add lsm hook for set_mempolicy_home_node(2) Yafang Shao
2023-11-12 7:34 ` [RFC PATCH -mm 4/4] selftests/bpf: Add selftests for mbind(2) with lsm prog Yafang Shao
2023-11-12 16:45 ` [RFC PATCH -mm 0/4] mm, security, bpf: Fine-grained control over memory policy adjustments with lsm bpf Casey Schaufler
2023-11-13 3:15 ` Yafang Shao
2023-11-13 8:50 ` Ondrej Mosnacek
2023-11-13 21:23 ` Casey Schaufler
2023-11-14 2:30 ` Yafang Shao
2023-11-14 10:15 ` Michal Hocko
2023-11-14 11:59 ` Yafang Shao
2023-11-14 16:57 ` Casey Schaufler
2023-11-15 1:52 ` Yafang Shao
2023-11-15 8:45 ` Michal Hocko
2023-11-15 9:33 ` Yafang Shao
2023-11-15 14:26 ` Yafang Shao
2023-11-15 17:09 ` Casey Schaufler
2023-11-16 1:41 ` Yafang Shao
2023-11-15 17:00 ` Michal Hocko
2023-11-16 2:22 ` Yafang Shao
2023-11-12 20:32 ` Paul Moore
2023-11-13 3:17 ` Yafang Shao
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=20231112073424.4216-2-laoar.shao@gmail.com \
--to=laoar.shao@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=bpf@vger.kernel.org \
--cc=jmorris@namei.org \
--cc=ligang.bdlg@bytedance.com \
--cc=linux-mm@kvack.org \
--cc=linux-security-module@vger.kernel.org \
--cc=mhocko@suse.com \
--cc=paul@paul-moore.com \
--cc=serge@hallyn.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