Received: by 2002:a05:6a10:7420:0:0:0:0 with SMTP id hk32csp4208565pxb; Mon, 21 Feb 2022 14:52:27 -0800 (PST) X-Google-Smtp-Source: ABdhPJxFd0Ob4pBysR7T3x6CEsRq0xMY0/+1qSavIl9qYgjbGms+88he9NWh1FPU1FDxY2LqA/e0 X-Received: by 2002:a17:902:e84a:b0:14e:d70b:92d5 with SMTP id t10-20020a170902e84a00b0014ed70b92d5mr20412353plg.94.1645483947098; Mon, 21 Feb 2022 14:52:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645483947; cv=none; d=google.com; s=arc-20160816; b=tJUiecTdm7+Pob04BhsEssLiCmwJ0lNTdXoyvZqkgoTzvM/tv8oP/lyMetvK86PU8S ZIPJZSaWurc1jeE6b9VUmu+IJG8/rqdBlIhNx+oVXRQtFL0NgZCOrBYEt95eyFoY81fE Kx6cBgdTLlE80gvLrbASsCMqSPFZZIOMPWI1/AsmGF7j2bgr173yOYMxj9xIjTjBQXUo UzBh1uOet0m83RvxXPgZgHfdV2xP0h/udipQW+XdGVx58e8rzJq90N1ELvGnqVIrnc7e C/eQt4E06fD0cIodXyTB9Ows5mToy/SIE+Z16Z5ypAsozy70hWWoDup19Mbre+vAG9FD yJvQ== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=opW1RyzoNmRbirX/ybiKc9kBT+bFiVZ2SujPoFnucOU=; b=pPmq+tIdyOR3VMzKNvAd1+petQ7c5cNjI2rJTR7GjG9h27mI6SuG3xEYL63xPxb5C+ My0CmFYICvttTslZV7a5beF5vN1e4vVpavaZXMJXk8i+4NhHOIVLz4o3gTDfPCrfgrvB 0RFVxKaFOcsKEk1V1gxdzQOe1Sg08QiLodlY7owzyGvgHL3aRQAIT+zeGRE0Mb8IuZXK RMvSBCzjNXAKV8+Yfb8iQEjg6/YKGluss6qzSgqt7+dg20bmTKxniYk+1QDN4mY5l3SH Xy8wjJXbj/jfDuFeKVBrjto4PDKdY+5LCLzlnCzowVOmZDhcQvoE1LfWMGyhwxusY4o+ DHWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=QlHNGIZz; 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=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b6si11426306pgc.288.2022.02.21.14.52.12; Mon, 21 Feb 2022 14:52:27 -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; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=QlHNGIZz; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1354292AbiBUKD0 (ORCPT + 99 others); Mon, 21 Feb 2022 05:03:26 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:55764 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352466AbiBUJzp (ORCPT ); Mon, 21 Feb 2022 04:55:45 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C7BE2443D9; Mon, 21 Feb 2022 01:24:32 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 618D860F6E; Mon, 21 Feb 2022 09:24:32 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3CE95C340E9; Mon, 21 Feb 2022 09:24:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1645435471; bh=zPYmlyTMwlVMzmNoiNA+hp2syFFidFgu756N2cZjayc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QlHNGIZzwnKLZXADKCHEi1i6QK7tFdA3I9/Aw1mCOyLTpU+YE5+nwM3JGzY1IW/T5 CFuKn6gCf5XXIJrvcA53KzTYrJmIdc2Ic3CFJW4rBGTXLdDindrOadPgwux7iQ+0Av OlDC7L4QC296IsMjRwIzIOzUN6JTe/KducNsnoHk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Shuah Khan , "Eric W. Biederman" Subject: [PATCH 5.16 174/227] ucounts: Handle wrapping in is_ucounts_overlimit Date: Mon, 21 Feb 2022 09:49:53 +0100 Message-Id: <20220221084940.593128934@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220221084934.836145070@linuxfoundation.org> References: <20220221084934.836145070@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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 From: Eric W. Biederman commit 0cbae9e24fa7d6c6e9f828562f084da82217a0c5 upstream. While examining is_ucounts_overlimit and reading the various messages I realized that is_ucounts_overlimit fails to deal with counts that may have wrapped. Being wrapped should be a transitory state for counts and they should never be wrapped for long, but it can happen so handle it. Cc: stable@vger.kernel.org Fixes: 21d1c5e386bc ("Reimplement RLIMIT_NPROC on top of ucounts") Link: https://lkml.kernel.org/r/20220216155832.680775-5-ebiederm@xmission.com Reviewed-by: Shuah Khan Signed-off-by: "Eric W. Biederman" Signed-off-by: Greg Kroah-Hartman --- kernel/ucount.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) --- a/kernel/ucount.c +++ b/kernel/ucount.c @@ -350,7 +350,8 @@ bool is_ucounts_overlimit(struct ucounts if (rlimit > LONG_MAX) max = LONG_MAX; for (iter = ucounts; iter; iter = iter->ns->ucounts) { - if (get_ucounts_value(iter, type) > max) + long val = get_ucounts_value(iter, type); + if (val < 0 || val > max) return true; max = READ_ONCE(iter->ns->ucount_max[type]); }