From: Alexey Gladkov <legion@kernel.org>
To: LKML <linux-kernel@vger.kernel.org>,
Linux Containers <containers@lists.linux.dev>
Cc: Alexander Mikhalitsyn <alexander.mikhalitsyn@virtuozzo.com>,
Andrew Morton <akpm@linux-foundation.org>,
Christian Brauner <christian.brauner@ubuntu.com>,
Daniel Walsh <dwalsh@redhat.com>,
Davidlohr Bueso <dbueso@suse.de>,
"Eric W . Biederman" <ebiederm@xmission.com>,
Kirill Tkhai <ktkhai@virtuozzo.com>,
Manfred Spraul <manfred@colorfullife.com>,
Serge Hallyn <serge@hallyn.com>,
Varad Gautam <varad.gautam@suse.com>,
Vasily Averin <vvs@virtuozzo.com>
Subject: [RFC PATCH v3 4/4] ipc: Allow to modify ipc/mq sysctls if CAP_SYS_RESOURCE is present
Date: Fri, 21 Jan 2022 14:08:41 +0100 [thread overview]
Message-ID: <9351533c4114f160d7b7d2db32d9636747bdede9.1642769810.git.legion@kernel.org> (raw)
In-Reply-To: <cover.1642769810.git.legion@kernel.org>
The mq_overview(7) says that mq sysctls are available for modification
to a privileged process (CAP_SYS_RESOURCE). Right now, within userns, a
privileged process cannot modify these files. Once the mq and ipc
sysctls have been moved to the ipc namespace we can grant access to
these files.
mqueue sysctls
--------------
The mq sysctls are protected by an upper limit that cannot be exceeded
on the system:
For /proc/sys/fs/mqueue/msg_max the upper limit is HARD_MSGMAX.
For /proc/sys/fs/mqueue/msgsize_max the upper limit is HARD_MSGSIZEMAX.
Also RLIMIT_MSGQUEUE limits all queues used by the process. This limit
is also tied to userns.
ipc sysctls
-----------
The implementation has no specific limits for the per-process maximum
number of shared memory segments. Only SHM_LOCK and SHM_HUGETLB limited
by RLIMIT_MEMLOCK which is also tied to userns.
This patch is RPC only and should not be applied without a security
discussion.
Signed-off-by: Alexey Gladkov <legion@kernel.org>
---
ipc/ipc_sysctl.c | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/ipc/ipc_sysctl.c b/ipc/ipc_sysctl.c
index 9fc8e3e75be7..f1d1c83656f9 100644
--- a/ipc/ipc_sysctl.c
+++ b/ipc/ipc_sysctl.c
@@ -254,6 +254,21 @@ static struct ctl_table mq_sysctls[] = {
{}
};
+static int set_permissions(struct ctl_table_header *head, struct ctl_table *table)
+{
+ struct ipc_namespace *ns = container_of(head->set, struct ipc_namespace, set);
+ int mode;
+
+ /* Allow users with CAP_SYS_RESOURCE unrestrained access */
+ if (ns_capable(ns->user_ns, CAP_SYS_RESOURCE))
+ mode = (table->mode & S_IRWXU) >> 6;
+ else
+ /* Allow all others at most read-only access */
+ mode = table->mode & S_IROTH;
+
+ return (mode << 6) | (mode << 3) | mode;
+}
+
static struct ctl_table_set *set_lookup(struct ctl_table_root *root)
{
return ¤t->nsproxy->ipc_ns->set;
@@ -266,6 +281,7 @@ static int set_is_seen(struct ctl_table_set *set)
static struct ctl_table_root set_root = {
.lookup = set_lookup,
+ .permissions = set_permissions,
};
static bool register_ipc_sysctl_table(struct ipc_namespace *ns)
--
2.33.0
prev parent reply other threads:[~2022-01-21 13:10 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-03 16:04 [PATCH v1] ipc: Store mqueue sysctls in the ipc namespace Alexey Gladkov
2022-01-03 20:41 ` kernel test robot
2022-01-04 5:28 ` kernel test robot
2022-01-04 11:51 ` [PATCH v2] " Alexey Gladkov
2022-01-04 18:13 ` Manfred Spraul
2022-01-04 18:42 ` Eric W. Biederman
2022-01-04 20:48 ` Manfred Spraul
2022-01-04 22:17 ` Eric W. Biederman
2023-09-08 15:47 ` Daniel Walsh
2023-09-10 18:51 ` Andrew Morton
2022-01-10 16:26 ` Eric W. Biederman
2022-01-21 13:08 ` [RFC PATCH v3 0/4] ipc: Store mq and ipc " Alexey Gladkov
2022-01-21 13:08 ` [RFC PATCH v3 1/4] ipc: Store mqueue " Alexey Gladkov
2022-01-21 13:08 ` [RFC PATCH v3 2/4] ipc: Store ipc " Alexey Gladkov
2022-01-21 13:08 ` [RFC PATCH v3 3/4] ipc: Merge ipc_sysctl and mq_sysctl Alexey Gladkov
2022-01-21 13:08 ` Alexey Gladkov [this message]
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=9351533c4114f160d7b7d2db32d9636747bdede9.1642769810.git.legion@kernel.org \
--to=legion@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=alexander.mikhalitsyn@virtuozzo.com \
--cc=christian.brauner@ubuntu.com \
--cc=containers@lists.linux.dev \
--cc=dbueso@suse.de \
--cc=dwalsh@redhat.com \
--cc=ebiederm@xmission.com \
--cc=ktkhai@virtuozzo.com \
--cc=linux-kernel@vger.kernel.org \
--cc=manfred@colorfullife.com \
--cc=serge@hallyn.com \
--cc=varad.gautam@suse.com \
--cc=vvs@virtuozzo.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
all inboxes | Powered by JetHome®