From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9F831C54EE9 for ; Mon, 19 Sep 2022 15:28:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230006AbiISP2R (ORCPT ); Mon, 19 Sep 2022 11:28:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32794 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229837AbiISP2C (ORCPT ); Mon, 19 Sep 2022 11:28:02 -0400 Received: from out03.mta.xmission.com (out03.mta.xmission.com [166.70.13.233]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A0F4F30C for ; Mon, 19 Sep 2022 08:28:01 -0700 (PDT) Received: from in01.mta.xmission.com ([166.70.13.51]:57352) by out03.mta.xmission.com with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1oaIgi-009wR6-LX; Mon, 19 Sep 2022 09:28:00 -0600 Received: from ip68-110-29-46.om.om.cox.net ([68.110.29.46]:51232 helo=email.froward.int.ebiederm.org.xmission.com) by in01.mta.xmission.com with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1oaIgh-001xfh-Ow; Mon, 19 Sep 2022 09:28:00 -0600 From: "Eric W. Biederman" To: Alexey Gladkov Cc: LKML , Linux Containers , Andrew Morton , Christian Brauner , Kees Cook , Manfred Spraul References: <87wnc1i2wo.fsf@email.froward.int.ebiederm.org> <0e095acd72553868925b116d778357eb019796a2.1660664258.git.legion@kernel.org> Date: Mon, 19 Sep 2022 10:27:53 -0500 In-Reply-To: <0e095acd72553868925b116d778357eb019796a2.1660664258.git.legion@kernel.org> (Alexey Gladkov's message of "Tue, 16 Aug 2022 17:42:44 +0200") Message-ID: <87h7132xl2.fsf@email.froward.int.ebiederm.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-XM-SPF: eid=1oaIgh-001xfh-Ow;;;mid=<87h7132xl2.fsf@email.froward.int.ebiederm.org>;;;hst=in01.mta.xmission.com;;;ip=68.110.29.46;;;frm=ebiederm@xmission.com;;;spf=softfail X-XM-AID: U2FsdGVkX1+6kbp/GAjBNzN409XC+yQuuXQX0PMBISc= X-SA-Exim-Connect-IP: 68.110.29.46 X-SA-Exim-Mail-From: ebiederm@xmission.com Subject: Re: [PATCH v1 2/3] sysctl: Allow to change limits for posix messages queues X-SA-Exim-Version: 4.2.1 (built Sat, 08 Feb 2020 21:53:50 +0000) X-SA-Exim-Scanned: Yes (on in01.mta.xmission.com) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Alexey Gladkov writes: > All parameters of posix messages queues (queues_max/msg_max/msgsize_max) > end up being limited by RLIMIT_MSGQUEUE. The code in mqueue_get_inode is > where that limiting happens. > > The RLIMIT_MSGQUEUE is bound to the user namespace and is counted > hierarchically. > > We can allow root in the user namespace to modify the posix messages > queues parameters. This looks good from 10,000 feet. But the same nits with setting mode in mq_permissions as in ipc_set_permissions in your other patch. Eric > Signed-off-by: Alexey Gladkov > --- > ipc/mq_sysctl.c | 36 ++++++++++++++++++++++++++++++++++++ > 1 file changed, 36 insertions(+) > > diff --git a/ipc/mq_sysctl.c b/ipc/mq_sysctl.c > index fbf6a8b93a26..39dcf086b7c2 100644 > --- a/ipc/mq_sysctl.c > +++ b/ipc/mq_sysctl.c > @@ -12,6 +12,7 @@ > #include > #include > #include > +#include > > static int msg_max_limit_min = MIN_MSGMAX; > static int msg_max_limit_max = HARD_MSGMAX; > @@ -76,8 +77,43 @@ static int set_is_seen(struct ctl_table_set *set) > return ¤t->nsproxy->ipc_ns->mq_set == set; > } > > +static int mq_permissions(struct ctl_table_header *head, struct ctl_table *table) > +{ > + struct ipc_namespace *ns = > + container_of(head->set, struct ipc_namespace, mq_set); > + > + if (ns->user_ns != &init_user_ns) { > + kuid_t ns_root_uid = make_kuid(ns->user_ns, 0); > + kgid_t ns_root_gid = make_kgid(ns->user_ns, 0); > + > + if (uid_valid(ns_root_uid) && uid_eq(current_euid(), ns_root_uid)) > + return table->mode >> 6; > + > + if (gid_valid(ns_root_gid) && in_egroup_p(ns_root_gid)) > + return table->mode >> 3; > + } > + > + return table->mode; > +} > + > +static void mq_set_ownership(struct ctl_table_header *head, > + struct ctl_table *table, > + kuid_t *uid, kgid_t *gid) > +{ > + struct ipc_namespace *ns = > + container_of(head->set, struct ipc_namespace, mq_set); > + > + kuid_t ns_root_uid = make_kuid(ns->user_ns, 0); > + kgid_t ns_root_gid = make_kgid(ns->user_ns, 0); > + > + *uid = uid_valid(ns_root_uid) ? ns_root_uid : GLOBAL_ROOT_UID; > + *gid = gid_valid(ns_root_gid) ? ns_root_gid : GLOBAL_ROOT_GID; > +} > + > static struct ctl_table_root set_root = { > .lookup = set_lookup, > + .permissions = mq_permissions, > + .set_ownership = mq_set_ownership, > }; > > bool setup_mq_sysctls(struct ipc_namespace *ns)