Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp1582300pxb; Tue, 8 Feb 2022 23:04:54 -0800 (PST) X-Google-Smtp-Source: ABdhPJzppWxHIBVJaanDobiCC9e7KeGh1fFoGqmC/BBQLtsZZGj/Ju1cF37fKxrDIa5Z9TkrhDrm X-Received: by 2002:a17:903:248:: with SMTP id j8mr794645plh.123.1644390293910; Tue, 08 Feb 2022 23:04:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644390293; cv=none; d=google.com; s=arc-20160816; b=MYsJ98wb3j/yEQsJ//6A+c1Xh2CSf2oVz9ithSpmoRmz7Pnsdr77uwPITL6SGUqBkU 3c1aPudH0wGCzrVyASMwxbZuGbWPnRkds1mpglJ+ejL7J3vnENcWGsXgfZaF9SYBI3yE cXn1LFEVYGcLVQUySUTHInJIxvYxhDmaXlv2okacCrOZX5U7Ak5Ezypr4SgdGI9LlusJ fftjf8NaMGUKFUwfqu2FwUtfqdtpOjKPyCJM5kKTihJr8GDlfVFMC5XSE20jnNrDliAG /MrqH56caPqQwIUnC42oS9XTznjkEEifUfpOi9P8hnMQAUutDUNaeEW8MLMw6qDdzQUu 2QfQ== 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 :dkim-signature; bh=JUdGqqOL/AiENbReMRD7Dx9TxjZn7NTW8OeBOFQBruY=; b=S/vm/cVvGnH5TLm9v1FVEajKnFKYRP4+bz4Lb6dngz7ReP2w6Esiy22pYqrl9ocsA4 BZuSuI+0jHskanqWQR7Ubp81LLAa+IaFahsCevpFRPAuLkgM0BnHXJPXMvH9cNl6a1La woSoCFfPCzEqwhmWMWEVSAKgMISj6V3uBorF6aAJvD4oAIpZS6Ltst9feYOnKmtyahH4 btTscR0lvAuzWRzokeOYgRyflaVLF5GqBgGtO3Ei2FJm5Lb9vMJ0uflvD2SoqbZ3uh+3 l3RxNL+ZN9kHppbDiFUBJg3x0KdZtdlUdbJEpwNU1+F4j8Q55i+uyl6/QxwBvnu451n8 kYQg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=syKK+oRx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=suse.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id z13si13535575ple.190.2022.02.08.23.04.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Feb 2022 23:04:53 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=syKK+oRx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=suse.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id B42DFE01926A; Tue, 8 Feb 2022 22:18:30 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1385323AbiBGNK1 (ORCPT + 99 others); Mon, 7 Feb 2022 08:10:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47488 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1445600AbiBGMmS (ORCPT ); Mon, 7 Feb 2022 07:42:18 -0500 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8C6D2E033DAF; Mon, 7 Feb 2022 04:33:57 -0800 (PST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 060CC1F38D; Mon, 7 Feb 2022 12:18:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1644236293; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=JUdGqqOL/AiENbReMRD7Dx9TxjZn7NTW8OeBOFQBruY=; b=syKK+oRx7HRZghKuXKJxOaqgXkuQ234dxQMVDFvHqsaX93Pknk+cCPMfxkHYeEw0jk+uzw 1SPGHJ5iqzTU0Vy8kr4s/+owO2lP/pLWg/MmnyUj8X9wb+MQygfHMldN0Ffcm+JVXTPR/x cN1mEwthFVDCQsFbjhA26vHWnSsuR2I= Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id D976113BBC; Mon, 7 Feb 2022 12:18:12 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id MNyWNAQOAWLMegAAMHmgww (envelope-from ); Mon, 07 Feb 2022 12:18:12 +0000 From: =?UTF-8?q?Michal=20Koutn=C3=BD?= To: Eric Biederman , Alexey Gladkov Cc: Kees Cook , Shuah Khan , Christian Brauner , Solar Designer , Ran Xiaokai , linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, Linux Containers Subject: [RFC PATCH 4/6] ucounts: Allow root to override RLIMIT_NPROC Date: Mon, 7 Feb 2022 13:17:58 +0100 Message-Id: <20220207121800.5079-5-mkoutny@suse.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220207121800.5079-1-mkoutny@suse.com> References: <20220207121800.5079-1-mkoutny@suse.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 Call sites of ucounts_limit_cmp() would allow the global root or capable user to bypass RLIMIT_NPROC on the bottom level of user_ns tree by not looking at ucounts at all. As the traversal up the user_ns tree continues, the ucounts to which the task is charged may switch the owning user (to the creator of user_ns). If the new chargee is root, we don't really care about RLIMIT_NPROC observation, so lift the limit to the max. The result is that an unprivileged user U can globally run more that RLIMIT_NPROC (of user_ns) tasks but within each user_ns it is still limited to RLIMINT_NPROC (as passed into task->signal->rlim) iff the user_nss are created by the privileged user. Signed-off-by: Michal Koutný --- kernel/ucount.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/kernel/ucount.c b/kernel/ucount.c index 53ccd96387dd..f52b7273a572 100644 --- a/kernel/ucount.c +++ b/kernel/ucount.c @@ -356,6 +356,9 @@ long ucounts_limit_cmp(struct ucounts *ucounts, enum ucount_type type, unsigned if (excess > 0) return excess; max = READ_ONCE(iter->ns->ucount_max[type]); + /* Next ucounts owned by root? RLIMIT_NPROC is moot */ + if (type == UCOUNT_RLIMIT_NPROC && uid_eq(iter->ns->owner, GLOBAL_ROOT_UID)) + max = LONG_MAX; } return excess; } -- 2.34.1