Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp3858162rwb; Tue, 16 Aug 2022 09:53:47 -0700 (PDT) X-Google-Smtp-Source: AA6agR6xSbBsnti0ZDX8f6EbjGQAVb/fG7uW19lUK2/KS8mFWuMvtp3YnUiasnyaIQoAUH9gOVqJ X-Received: by 2002:a17:903:2601:b0:16d:b055:2985 with SMTP id jd1-20020a170903260100b0016db0552985mr22713403plb.161.1660668826771; Tue, 16 Aug 2022 09:53:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660668826; cv=none; d=google.com; s=arc-20160816; b=va+wxGz+XT3FD4zB2ShI9tNjp2Fwp2JfxJPt6P2NC6FSM+HXUa0cdvmtUf5mVeRHFE NQDY/aM67Qnt+1pdkIeUB+Pb55ZAnhAk4w2a9IkDAcVfwcYX304WpvpeoO1tlBMCDgIf y1toZO/bu3WV9F3zj5aMN2FWuc9pv4dBA9x/Yati1CdJ8fOcUxj0jYaxxgpXBsBpaieB FkBPIfm7Xx9JIXq5n//c5QTMi/QE5FvHhVj30yzEVczVoZvl9Ny++ehPAHCOJxtPuMNf sA1LpkaL5s8yWasvb9nRj/LDjeMAwcxj3TIn5AO5o/5oPRDUZ+HN3uiXCFSjjE4bL/Gl O+rg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=9WXBzJMyw2FIuM6pyLRZXDb1m8g41lYlIbp3QTzSbqk=; b=fYdvR0x1Cu/pB3UQtwY70BEcVgx0Zd8gWV+FwjR3sDkJSAmBq+xApzc/bLyw1ioL7/ kLAbF8Xh+wz0aaHDnPedtzO8g7iiasRMZmZFEMPqEgWz4/3ViHl3m2EugMs3V3FzBoeI i09dleKK/7PFMCIHIKoZ569JT3+v//XNEwjfNngZPC6zWzkpd2MeQNDE6zcM+GQpk1ID XNidjra66ynVcfqd2pRX+9IuDkddbHios0VC2WBzBoIcFbCz+n+FZet7QVadQnFrBgGJ MEJuQcMgWUqMNX6To7I77oYMOEOgoYg2B8yWbnspw47unPny8RahtEyzReNy7Vv9gRRy suww== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l8-20020a654488000000b0040d9ebed1c6si14229849pgq.806.2022.08.16.09.53.34; Tue, 16 Aug 2022 09:53:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232604AbiHPPrv (ORCPT + 99 others); Tue, 16 Aug 2022 11:47:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41210 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229607AbiHPPra (ORCPT ); Tue, 16 Aug 2022 11:47:30 -0400 Received: from us-smtp-delivery-44.mimecast.com (us-smtp-delivery-44.mimecast.com [205.139.111.44]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E325545063 for ; Tue, 16 Aug 2022 08:44:01 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-654-tOBIA_5-OvaFM29i4NZM_g-1; Tue, 16 Aug 2022 11:43:55 -0400 X-MC-Unique: tOBIA_5-OvaFM29i4NZM_g-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 168D5811E76; Tue, 16 Aug 2022 15:43:55 +0000 (UTC) Received: from comp-core-i7-2640m-0182e6.redhat.com (unknown [10.40.208.6]) by smtp.corp.redhat.com (Postfix) with ESMTP id AAEB52166B26; Tue, 16 Aug 2022 15:43:53 +0000 (UTC) From: Alexey Gladkov To: LKML , Linux Containers Cc: Andrew Morton , Christian Brauner , "Eric W . Biederman" , Kees Cook , Manfred Spraul Subject: [PATCH v1 2/3] sysctl: Allow to change limits for posix messages queues Date: Tue, 16 Aug 2022 17:42:44 +0200 Message-Id: <0e095acd72553868925b116d778357eb019796a2.1660664258.git.legion@kernel.org> In-Reply-To: References: <87wnc1i2wo.fsf@email.froward.int.ebiederm.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,SPF_SOFTFAIL,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. 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) -- 2.33.4