From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7ED0B1DF24B; Wed, 6 Nov 2024 12:25:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730895924; cv=none; b=JDTmSdGJoZuqIeS0yhs3z88dLNjOMCc5LVZa78+vsGAsENBG7mY12CdHiq2aphBndex+25fZRGU046H9MGpI9FZgKGXbtJf1Z+nee6Ij4iVvnbnDtJi0iOuCfGNvpwlv0vpSgkvBG0SOLoPbj3ZcSU1nA2sM1Ny4a1tItsEwX4I= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730895924; c=relaxed/simple; bh=JdaL0tCPLl0iYP3TKNTf692K2xzyIIo2fV0W1+YQa78=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=QcjQ6KsWP8wOry7KTb3OybgHqtwsuWncNkBXCBULINM90HpWtNHYpnDnOjWCDt0QYYJ8eCnjlvWBMB+CLQX4+y1bOFM+r1FZuYWgPUAD1lfXSA/BEOQp6G2SOE7eoxnnuHoVpg78EW60m7XFo/w9L1kOpotIdt9U7cD3szjqNK0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=n67Y5QkE; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="n67Y5QkE" Received: by smtp.kernel.org (Postfix) with ESMTPSA id F2126C4CECD; Wed, 6 Nov 2024 12:25:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1730895924; bh=JdaL0tCPLl0iYP3TKNTf692K2xzyIIo2fV0W1+YQa78=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=n67Y5QkEDxSWecbssDPATIZXY8Q9sJ66uFz+7xWwm5hzG45iXQiWE3U0oe7KH/IXK gMqCkeFBUus5rn8IluiHH1SvtOA6fClLBRxFmNujF40Z++icZDh1m/NG1CDn/mTLlU WpgY7jytrNfKaVRJ0AXKvFAcBR3xapu5cvQkaUes= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Xiu Jianfeng , =?UTF-8?q?Michal=20Koutn=C3=BD?= , Tejun Heo , Sasha Levin Subject: [PATCH 6.11 003/245] cgroup: Fix potential overflow issue when checking max_depth Date: Wed, 6 Nov 2024 13:00:56 +0100 Message-ID: <20241106120319.326880101@linuxfoundation.org> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241106120319.234238499@linuxfoundation.org> References: <20241106120319.234238499@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 6.11-stable review patch. If anyone has any objections, please let me know. ------------------ From: Xiu Jianfeng [ Upstream commit 3cc4e13bb1617f6a13e5e6882465984148743cf4 ] cgroup.max.depth is the maximum allowed descent depth below the current cgroup. If the actual descent depth is equal or larger, an attempt to create a new child cgroup will fail. However due to the cgroup->max_depth is of int type and having the default value INT_MAX, the condition 'level > cgroup->max_depth' will never be satisfied, and it will cause an overflow of the level after it reaches to INT_MAX. Fix it by starting the level from 0 and using '>=' instead. It's worth mentioning that this issue is unlikely to occur in reality, as it's impossible to have a depth of INT_MAX hierarchy, but should be be avoided logically. Fixes: 1a926e0bbab8 ("cgroup: implement hierarchy limits") Signed-off-by: Xiu Jianfeng Reviewed-by: Michal Koutný Signed-off-by: Tejun Heo Signed-off-by: Sasha Levin --- kernel/cgroup/cgroup.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c index c8e4b62b436a4..6ba7dd2ab771d 100644 --- a/kernel/cgroup/cgroup.c +++ b/kernel/cgroup/cgroup.c @@ -5722,7 +5722,7 @@ static bool cgroup_check_hierarchy_limits(struct cgroup *parent) { struct cgroup *cgroup; int ret = false; - int level = 1; + int level = 0; lockdep_assert_held(&cgroup_mutex); @@ -5730,7 +5730,7 @@ static bool cgroup_check_hierarchy_limits(struct cgroup *parent) if (cgroup->nr_descendants >= cgroup->max_descendants) goto fail; - if (level > cgroup->max_depth) + if (level >= cgroup->max_depth) goto fail; level++; -- 2.43.0