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 87E7D2144C0; Tue, 12 Nov 2024 10:31:35 +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=1731407495; cv=none; b=nYfGdDz6bvKqt7xdL45zJjrHAMVX/hfz0ld+Lswh/nmwQhUdTO+ebL7gmZ7eemDLbLSeBNvh1ZdIBczMAaZ1sA/ndzf21zlMxqVA3vR7lsZJScYNqXwZs1b3dWG/xBNPUfPpmNsvVgbZWH29knQpjcVPty9TlMVG4JC8/GWB+Is= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731407495; c=relaxed/simple; bh=BweZHoy9Rgl/marJLTfldn4mm9oZW4kQMADyqT9djUU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=u3WoD4ZCJtDV+j50mre2URWQHzre5nSdm5ipx0a/bwPpo38Iy2Sc8zKXskhkS/MitIyKB0kOYlWt3rR6K766eQAcGB5r8cDyCZDVivgTyB/IccWQjSFRUm6RUvlsaqE2Kwc4jmqJlh0uPJNE61JIYFdKeJuXufDem9B3K8nNnIs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=lI+B7gId; 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="lI+B7gId" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0A635C4CED6; Tue, 12 Nov 2024 10:31:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1731407495; bh=BweZHoy9Rgl/marJLTfldn4mm9oZW4kQMADyqT9djUU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lI+B7gIdfZawEWc5JLO0xmW7QYaK7xmq1dlgNvIAf7iabRxsRXUirsjwqbjKJa3Fx 0YEisaK8h77l3qo11MTU8vPObTH3srt4+N54zhzUD+QHjIktOulpZXHoN5FTCjGx1s sS4nBoC3VmRrt97ILet12xKvyMpvkMTNW4WBqhfE= 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.1 93/98] ucounts: fix counter leak in inc_rlimit_get_ucounts() Date: Tue, 12 Nov 2024 11:21:48 +0100 Message-ID: <20241112101847.787688183@linuxfoundation.org> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241112101844.263449965@linuxfoundation.org> References: <20241112101844.263449965@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-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 @@ -318,7 +318,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) @@ -336,7 +336,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; }