Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp3558209pxb; Fri, 11 Feb 2022 02:36:02 -0800 (PST) X-Google-Smtp-Source: ABdhPJwzz3t4EoDowXfoY1AC/wWGZvshSz+2+AZevWIY3loeFzUjyRHQTG2G31GruhrmkJAkVRNP X-Received: by 2002:a17:902:ab41:: with SMTP id ij1mr857014plb.59.1644575762329; Fri, 11 Feb 2022 02:36:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644575762; cv=none; d=google.com; s=arc-20160816; b=UBD1F7Q/tYgQlg5zHmBErqvB7qGe5UgvZN3hNhUgXFHi90FfpvBHf8S+ROzak/RKUe gs/jqOO0B6vbgXP5IYgSePPVPx3nXpmZzDUZR4D+wq2l3yW4bg+GOjlektkmSHvX04g4 54xicucTBCj90n/6NpTXE/LFNlxE322NhTo1NuF/CKVpQCMb09OWwFMyxdf+Lykhzvul 5kQDWX7IS0bzI8mQnEomZwRh2958jzHyGeKYPb5xdxb5uRl9JJ6ARJ35dWD80/a9ff7X 9AagNqywSrf/wkiw5zb9sm6jdOMkx3Kfj6akXOLurbZuCDmItWelmUWSFgiAT9+osUQl vbbA== 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 :references:in-reply-to:message-id:date:cc:to:from; bh=1oQxlsTuJ2v/SfHJOxJkYMPBBGq6LUt/j2dgpUxWa1w=; b=WCqrw9Re5BrR68QIYxLaikx3DQdHvOSsp+vc+wP16sYiy1I3NiCg3DX1xQziK4eX6p 4I6a7bQ7XItCrBytzL13oIHJCWXm7t+KUStCriz2PnC3+r9LmOj+LmMsM2Q7Gv5PHtOp L2a95mJPU1eJ+sSYpXLevrs0aWq85stU+XVSNi02KfpsuIo+l20wcKyCJ3K1CyOl4jnr f7+rDNkUhQsPEV0UhI6oV5OOJkcD67UWAvYHozgDAOGfS5R5+apaD11JHA7Nuv0oMmdy 9QF9IcFVY/gmblH2dztSfi7S+v+IAglSVnbD0vYX4356eY4u8byIDwgMsniT1K6gqbhR 5BiA== 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 pi6si3791077pjb.156.2022.02.11.02.35.51; Fri, 11 Feb 2022 02:36:02 -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 S1347200AbiBKCOB (ORCPT + 99 others); Thu, 10 Feb 2022 21:14:01 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:34752 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237351AbiBKCOA (ORCPT ); Thu, 10 Feb 2022 21:14:00 -0500 Received: from out01.mta.xmission.com (out01.mta.xmission.com [166.70.13.231]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DDF4E5FB0; Thu, 10 Feb 2022 18:14:00 -0800 (PST) Received: from in01.mta.xmission.com ([166.70.13.51]:56772) by out01.mta.xmission.com with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1nILRe-000fPs-PC; Thu, 10 Feb 2022 19:13:59 -0700 Received: from ip68-227-174-4.om.om.cox.net ([68.227.174.4]:52650 helo=localhost.localdomain) by in01.mta.xmission.com with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1nILRc-00FMXV-OH; Thu, 10 Feb 2022 19:13:58 -0700 From: "Eric W. Biederman" To: linux-kernel@vger.kernel.org Cc: Alexey Gladkov , Kees Cook , Shuah Khan , Christian Brauner , Solar Designer , Ran Xiaokai , containers@lists.linux-foundation.org, =?UTF-8?q?Michal=20Koutn=C3=BD?= , "Eric W. Biederman" , stable@vger.kernel.org Date: Thu, 10 Feb 2022 20:13:17 -0600 Message-Id: <20220211021324.4116773-1-ebiederm@xmission.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <87o83e2mbu.fsf@email.froward.int.ebiederm.org> References: <87o83e2mbu.fsf@email.froward.int.ebiederm.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-XM-SPF: eid=1nILRc-00FMXV-OH;;;mid=<20220211021324.4116773-1-ebiederm@xmission.com>;;;hst=in01.mta.xmission.com;;;ip=68.227.174.4;;;frm=ebiederm@xmission.com;;;spf=neutral X-XM-AID: U2FsdGVkX1/PfBild3s35N2DnDkS1MpwyGk5lTzuMOo= 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: *;linux-kernel@vger.kernel.org X-Spam-Relay-Country: X-Spam-Timing: total 1422 ms - load_scoreonly_sql: 0.04 (0.0%), signal_user_changed: 11 (0.8%), b_tie_ro: 10 (0.7%), parse: 1.03 (0.1%), extract_message_metadata: 16 (1.1%), get_uri_detail_list: 1.89 (0.1%), tests_pri_-1000: 24 (1.7%), tests_pri_-950: 1.29 (0.1%), tests_pri_-900: 1.06 (0.1%), tests_pri_-90: 65 (4.6%), check_bayes: 64 (4.5%), b_tokenize: 10 (0.7%), b_tok_get_all: 9 (0.6%), b_comp_prob: 2.5 (0.2%), b_tok_touch_all: 39 (2.7%), b_finish: 0.85 (0.1%), tests_pri_0: 1285 (90.3%), check_dkim_signature: 0.55 (0.0%), check_dkim_adsp: 2.7 (0.2%), poll_dns_idle: 0.95 (0.1%), tests_pri_10: 2.4 (0.2%), tests_pri_500: 12 (0.9%), rewrite_mail: 0.00 (0.0%) Subject: [PATCH 1/8] ucounts: Fix RLIMIT_NPROC regression 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 Michal Koutný wrote: > It was reported that v5.14 behaves differently when enforcing > RLIMIT_NPROC limit, namely, it allows one more task than previously. > This is consequence of the commit 21d1c5e386bc ("Reimplement > RLIMIT_NPROC on top of ucounts") that missed the sharpness of > equality in the forking path. This can be fixed either by fixing the test or by moving the increment to be before the test. Fix it my moving copy_creds which contains the increment before is_ucounts_overlimit. This is necessary so that in the case of CLONE_NEWUSER the new credential with the new ucounts is available of is_ucounts_overlimit to test. Both the test in fork and the test in set_user were semantically changed when the code moved to ucounts. The change of the test in fork was bad because it was before the increment. The test in set_user was wrong and the change to ucounts fixed it. So this fix is only restore the old behavior in one lcatio not two. Link: https://lkml.kernel.org/r/20220204181144.24462-1-mkoutny@suse.com Cc: stable@vger.kernel.org Reported-by: Michal Koutný Fixes: 21d1c5e386bc ("Reimplement RLIMIT_NPROC on top of ucounts") Signed-off-by: "Eric W. Biederman" --- kernel/fork.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/kernel/fork.c b/kernel/fork.c index d75a528f7b21..17d8a8c85e3b 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -2021,18 +2021,18 @@ static __latent_entropy struct task_struct *copy_process( #ifdef CONFIG_PROVE_LOCKING DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled); #endif + retval = copy_creds(p, clone_flags); + if (retval < 0) + goto bad_fork_free; + retval = -EAGAIN; if (is_ucounts_overlimit(task_ucounts(p), UCOUNT_RLIMIT_NPROC, rlimit(RLIMIT_NPROC))) { if (p->real_cred->user != INIT_USER && !capable(CAP_SYS_RESOURCE) && !capable(CAP_SYS_ADMIN)) - goto bad_fork_free; + goto bad_fork_cleanup_count; } current->flags &= ~PF_NPROC_EXCEEDED; - retval = copy_creds(p, clone_flags); - if (retval < 0) - goto bad_fork_free; - /* * If multiple threads are within copy_process(), then this check * triggers too late. This doesn't hurt, the check is only there -- 2.29.2