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 CF8BB1FFC52; Tue, 12 Nov 2024 10:38:15 +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=1731407895; cv=none; b=dRAeP5rwpLZpXlHCn+a123i8TWtnmbCBeJS18cUg0QLohWe23VhmvwFD3T2JPLjwUzdMG2aXruRAJOL50H2GbPnfCuxbPKbASJqKgRY/9Dn6T+ezubdR84IllxrIOIJYLSBaxhSdBHoYAzr5tb9xYiUTLbLNHuYS6VRNnRQBBis= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731407895; c=relaxed/simple; bh=lhxL405+BOf8GaQ65S0M82xCobfPR2s+mT/xcvWR78o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Qc+Oy6kCKjuvqD8+SMQigu/NmGTGj/epKjWkDzEcULcO4YhmZG7JJ21mTT8oD88fI1wTZp3wNBHeLe/qGk0KY+4fBE4Lz7WRBzXo7QtWxiFvJ4cxhKqNySL2yn6j0sMQnylDI+KZ2QycXNxxxUXQXIBW+eXwiA0fMu0VgDLa/ZM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=CD74oqDB; 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="CD74oqDB" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0B6E1C4CECD; Tue, 12 Nov 2024 10:38:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1731407895; bh=lhxL405+BOf8GaQ65S0M82xCobfPR2s+mT/xcvWR78o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CD74oqDBhsvFe+kub58eqDBfp5EgRHMM4Py4wLmKJLNs57ZT6Tymb2ORYyPSgua3v GtT2SCXEh6KlWYqY8SfT4/H0CptPHttCugeljvf+NuKVef9Vl6H8VmFrV0b3InSWkJ hWjJBMeqKuryr+CV49KiMPnNoCUxM2IGqbErSjYs= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Andrei Vagin , Roman Gushchin , Alexey Gladkov , Kees Cook , "Eric W. Biederman" , Oleg Nesterov , Andrew Morton Subject: [PATCH 6.6 116/119] ucounts: fix counter leak in inc_rlimit_get_ucounts() Date: Tue, 12 Nov 2024 11:22:04 +0100 Message-ID: <20241112101853.149164576@linuxfoundation.org> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241112101848.708153352@linuxfoundation.org> References: <20241112101848.708153352@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-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Andrei Vagin commit 432dc0654c612457285a5dcf9bb13968ac6f0804 upstream. The inc_rlimit_get_ucounts() increments the specified rlimit counter and then checks its limit. If the value exceeds the limit, the function returns an error without decrementing the counter. Link: https://lkml.kernel.org/r/20241101191940.3211128-1-roman.gushchin@linux.dev Fixes: 15bc01effefe ("ucounts: Fix signal ucount refcounting") Signed-off-by: Andrei Vagin Co-developed-by: Roman Gushchin Signed-off-by: Roman Gushchin Tested-by: Roman Gushchin Acked-by: Alexey Gladkov Cc: Kees Cook Cc: Andrei Vagin Cc: "Eric W. Biederman" Cc: Alexey Gladkov Cc: Oleg Nesterov Cc: Signed-off-by: Andrew Morton Signed-off-by: Greg Kroah-Hartman --- kernel/ucount.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) --- a/kernel/ucount.c +++ b/kernel/ucount.c @@ -319,7 +319,7 @@ long inc_rlimit_get_ucounts(struct ucoun for (iter = ucounts; iter; iter = iter->ns->ucounts) { long new = atomic_long_add_return(1, &iter->rlimit[type]); if (new < 0 || new > max) - goto unwind; + goto dec_unwind; if (iter == ucounts) ret = new; if (!override_rlimit) @@ -337,7 +337,6 @@ long inc_rlimit_get_ucounts(struct ucoun dec_unwind: dec = atomic_long_sub_return(1, &iter->rlimit[type]); WARN_ON_ONCE(dec < 0); -unwind: do_dec_rlimit_put_ucounts(ucounts, iter, type); return 0; }