Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp5330983pxb; Sun, 13 Feb 2022 17:12:20 -0800 (PST) X-Google-Smtp-Source: ABdhPJxkb5AE8lmfcCr5VJJa4PBs48uBz5LaDC8+iGGdhwTXKyAlq7G8BLWGB/F6T7K7EqXyIOK3 X-Received: by 2002:a05:6402:3510:: with SMTP id b16mr13080736edd.79.1644801140392; Sun, 13 Feb 2022 17:12:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644801140; cv=none; d=google.com; s=arc-20160816; b=iOfnB8P6XmkTxMLqGtwVh+1IqKLo8WJIfE73K2onADpNaXrlJ+zGBqKlZl5o0PvrG3 s6lGUuQdJGrPXdgBpcmZ28cwS+if4uLTOEfuZukDXYio9UrAzMhHaK6Q2Lcpbtngdx6e lz5tuVf6X/29ZRVvPMKh1mrodWk0DThLczM7m9zjUPvxizYHRJeON4OjsJanJbGgbF01 96gWfaFweUjJ+gk8DtwU5SSfxhWNoy+D3v96ymInW4JqtekUrqKJz44BWst6LXtkwooR lwCfFrQNc7bnceXK0zY6iwWpbOuXoROgjoNR30xl2yyY/vf7hUzU3WuWAxe4VYoPoNBh 6j6A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:subject:content-transfer-encoding:mime-version :user-agent:message-id:in-reply-to:date:references:cc:to:from; bh=q7FVj9upAq33lKTniBlrpR23uxr78cEoC8guq9zUBYk=; b=tsEnLCiS4mYkGfyukG7LrpE7zRin4vE7me5s0vVSH8vx+ev+Slo1db0FaIIP8vGPh0 0n2gsvnjEAuHZGDdq4Q0TI9MVvGJpPwXoWc8xwQP1toCQBNTxXI5OCWS+UpZXQf1dB+B zFr55tmNYImtl66jPv8pJri07Xn841IK0ElLqB9v3hVDhTM+iFNb73WMRn4xu1NtiZ8K WEx3LONee5FT6RWDR0HnNTeMTlcQXV1Puq/Ne04jG4qX6qtl1MH5PV4kLaCrlf3wXgRh HFd1YSrVlqJ1Z3+NWG8yopAcCgNwgWn0E1+tPvYnNRAkKEwd7brsBpX+b6tldu+ijOkp h9vA== 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=fail (p=NONE sp=NONE dis=NONE) header.from=xmission.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id sc16si16652914ejc.946.2022.02.13.17.11.48; Sun, 13 Feb 2022 17:12:20 -0800 (PST) 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=fail (p=NONE sp=NONE dis=NONE) header.from=xmission.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353231AbiBKUdA convert rfc822-to-8bit (ORCPT + 93 others); Fri, 11 Feb 2022 15:33:00 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:34188 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351880AbiBKUc7 (ORCPT ); Fri, 11 Feb 2022 15:32:59 -0500 Received: from out02.mta.xmission.com (out02.mta.xmission.com [166.70.13.232]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2529CCE4; Fri, 11 Feb 2022 12:32:58 -0800 (PST) Received: from in02.mta.xmission.com ([166.70.13.52]:58500) by out02.mta.xmission.com with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1nIcb8-006sHy-VQ; Fri, 11 Feb 2022 13:32:55 -0700 Received: from ip68-227-174-4.om.om.cox.net ([68.227.174.4]:52036 helo=email.froward.int.ebiederm.org.xmission.com) by in02.mta.xmission.com with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1nIcb7-00A7Qi-RT; Fri, 11 Feb 2022 13:32:54 -0700 From: "Eric W. Biederman" To: Solar Designer Cc: Michal =?utf-8?Q?Koutn=C3=BD?= , Alexey Gladkov , Kees Cook , Shuah Khan , Christian Brauner , Ran Xiaokai , linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, Linux Containers References: <20220207121800.5079-1-mkoutny@suse.com> <20220207121800.5079-2-mkoutny@suse.com> <20220210011405.GA17076@openwall.com> Date: Fri, 11 Feb 2022 14:32:47 -0600 In-Reply-To: <20220210011405.GA17076@openwall.com> (Solar Designer's message of "Thu, 10 Feb 2022 02:14:05 +0100") Message-ID: <87h795xhxs.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; charset=utf-8 Content-Transfer-Encoding: 8BIT X-XM-SPF: eid=1nIcb7-00A7Qi-RT;;;mid=<87h795xhxs.fsf@email.froward.int.ebiederm.org>;;;hst=in02.mta.xmission.com;;;ip=68.227.174.4;;;frm=ebiederm@xmission.com;;;spf=neutral X-XM-AID: U2FsdGVkX1+5Gcs6GFJ0JaUFgYHgyqu37QsE/9if+6I= X-SA-Exim-Connect-IP: 68.227.174.4 X-SA-Exim-Mail-From: ebiederm@xmission.com X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-DCC: XMission; sa06 1397; Body=1 Fuz1=1 Fuz2=1 X-Spam-Combo: *****;Solar Designer X-Spam-Relay-Country: X-Spam-Timing: total 562 ms - load_scoreonly_sql: 0.04 (0.0%), signal_user_changed: 11 (2.0%), b_tie_ro: 10 (1.7%), parse: 0.96 (0.2%), extract_message_metadata: 18 (3.2%), get_uri_detail_list: 1.90 (0.3%), tests_pri_-1000: 14 (2.5%), tests_pri_-950: 1.23 (0.2%), tests_pri_-900: 0.98 (0.2%), tests_pri_-90: 75 (13.3%), check_bayes: 73 (13.0%), b_tokenize: 8 (1.4%), b_tok_get_all: 8 (1.5%), b_comp_prob: 2.4 (0.4%), b_tok_touch_all: 51 (9.1%), b_finish: 0.85 (0.2%), tests_pri_0: 291 (51.9%), check_dkim_signature: 0.61 (0.1%), check_dkim_adsp: 2.7 (0.5%), poll_dns_idle: 134 (23.9%), tests_pri_10: 1.94 (0.3%), tests_pri_500: 145 (25.8%), rewrite_mail: 0.00 (0.0%) Subject: Re: [RFC PATCH 1/6] set_user: Perform RLIMIT_NPROC capability check against new user credentials X-SA-Exim-Version: 4.2.1 (built Sat, 08 Feb 2020 21:53:50 +0000) X-SA-Exim-Scanned: Yes (on in02.mta.xmission.com) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Solar Designer writes: > Hi Michal, > > On Mon, Feb 07, 2022 at 01:17:55PM +0100, Michal Koutný wrote: >> The check is currently against the current->cred but since those are >> going to change and we want to check RLIMIT_NPROC condition after the >> switch, supply the capability check with the new cred. >> But since we're checking new_user being INIT_USER any new cred's >> capability-based allowance may be redundant when the check fails and the >> alternative solution would be revert of the commit 2863643fb8b9 >> ("set_user: add capability check when rlimit(RLIMIT_NPROC) exceeds") >> >> Fixes: 2863643fb8b9 ("set_user: add capability check when rlimit(RLIMIT_NPROC) exceeds") >> >> Cc: Solar Designer >> Cc: Christian Brauner >> Signed-off-by: Michal Koutný >> --- >> kernel/sys.c | 3 ++- >> 1 file changed, 2 insertions(+), 1 deletion(-) >> >> diff --git a/kernel/sys.c b/kernel/sys.c >> index 8ea20912103a..48c90dcceff3 100644 >> --- a/kernel/sys.c >> +++ b/kernel/sys.c >> @@ -481,7 +481,8 @@ static int set_user(struct cred *new) >> */ >> if (ucounts_limit_cmp(new->ucounts, UCOUNT_RLIMIT_NPROC, rlimit(RLIMIT_NPROC)) >= 0 && >> new_user != INIT_USER && >> - !capable(CAP_SYS_RESOURCE) && !capable(CAP_SYS_ADMIN)) >> + !security_capable(new, &init_user_ns, CAP_SYS_RESOURCE, CAP_OPT_NONE) && >> + !security_capable(new, &init_user_ns, CAP_SYS_ADMIN, CAP_OPT_NONE)) >> current->flags |= PF_NPROC_EXCEEDED; >> else >> current->flags &= ~PF_NPROC_EXCEEDED; > > Thank you for working on this and CC'ing me on it. This is related to > the discussion Christian and I had in September: > > https://lore.kernel.org/all/20210913100140.bxqlg47pushoqa3r@wittgenstein/ > > Christian was going to revert 2863643fb8b9, but apparently that never > happened. Back then, I also suggested: > > "Alternatively, we could postpone the set_user() calls until we're > running with the new user's capabilities, but that's an invasive change > that's likely to create its own issues." Back then you mentioned that apache suexec was broken. Do you have any more details? I would like to make certain the apache suexec issue is fixed but without a few details I can't do that. I tried looking but I can't find an public report about apache suexec being broken. My goal is to come up with a very careful and conservative set of patches that fix all of the known issues with RLIMIT_NPROC. Eric