From nobody Mon Dec 2 13:57:49 2024 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 308A712C552 for ; Thu, 31 Oct 2024 04:56:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730350579; cv=none; b=XWV+8eymn3lPcnYx4zYUO7eJLmltYxnVofHien7jy4gw/tJMaqh69B+zHo1MdJ3wwC72t6UM7SBjFtzYQHiWXyWtOCkmyU8hDcn/cr3K+b84aek+0uwkR9xt0p03JTx1jDbogqTzYC7M/uA4j3gHP/aG3okjkCsOldOcYSuHOUA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730350579; c=relaxed/simple; bh=90DyzMh+3InP5LjjTqhduziKAJPe9dWWJgXzrPyn2vo=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=jcqf+XN7iwR+2f4vzbSyrYplT/BzC75CODsLZWdXQnc8r5DB4gkv3ksFK3CryDjzcWU749ziEXU+xQBOGZ9saFPg9qK/OfCq0cmct4PQ+RoRGUb/7LLaTTcVeWfFsJ/rbLND+o+OKfL9gBMScfZqzTPfJX77UkGoPv8s9NIZdmc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--avagin.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=YLRYp3mC; arc=none smtp.client-ip=209.85.128.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--avagin.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="YLRYp3mC" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6e3231725c9so9969207b3.1 for ; Wed, 30 Oct 2024 21:56:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1730350576; x=1730955376; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=I97b63gkdmSBdnuB9dOGrYfy4ImSP9vTzH5ACLew3Zw=; b=YLRYp3mC134cb6P7R/kcTiCDYR74LxToAxYKl45wNbdHPw58cVs/zHrrhF4pFC3+U4 f2fD30I2v7iboH/FcUVduNsxXPm+v7ppGXrWNaYPqKB6CNwGJ694Vg5+rbpkY5xQYQoo Nr3d+VLcZ3x2dIDNLcClVysa8y2RW04NacOWqHUXrliFRXZPMizhi8NfMMNpj0hBr644 EWUth+za/EtXo5GDGYOxLjQUe8VNqAVS6jt09devo03DxIoV65Vf4BD2NgzxK2s8QpUT uirA24R/Nxndz0tV0cVSlGvbJ/446WfEFPPxCAnFu1xt2KhmbTmM85jrNH6S+ljCF8PH 7Dcw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730350576; x=1730955376; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=I97b63gkdmSBdnuB9dOGrYfy4ImSP9vTzH5ACLew3Zw=; b=t7W3QceNgdu09tS3V9Fq80BFdMXpX07775E4M+2i2huI1vyFFdTGeSwUMOzZVZY1AH DMHOOUCaGu0XKp9c/loZNa7lEciY8U1RpS+S48Rx1h33nca1XHIBgLO9qNwSNi1xdORx ThU8BzUHysrwSjPMANeuEOiLu42Xq1fyTlH05+VTNuJpB637CJ/xkA8KHpZSDNTg6YJ0 Gt+ipQuVEWLx2wGHP1EgPJmGHG1D0Wpla0BaWc/6c2li+aFMtvXKbtEbDNX69YkcSngJ WNh94Q6iFyxOQ4Byvl9itLqJfmQ+ZmErKMI9F6oVBw+R7mSf1SaRUCPtkUiIpcIB2Tgm pWDA== X-Forwarded-Encrypted: i=1; AJvYcCX3ZKDd67PHtQwfPayZSQyLvnGmdGZZTH8Pjv2kx/0ZrjC7vJTOau8+x7LjfHhsM6fzrd/ZT98pUiHucTA=@vger.kernel.org X-Gm-Message-State: AOJu0Yz4LQj+CmuBz3erTdz5OBPShcBgKC7eozHpIteU/2ZxD6JrG+Ci nbHcDiUbPmeWj2v/+Zj8p2Jlv9zHsAffU0L1O0awH2w2n5yWJinnUx9uGxNLIUmeOyL8QG2Fv8P ZbQ== X-Google-Smtp-Source: AGHT+IFDKij6GqUhNl2/DRmDfo7qXWmYSb2Sa5UFVNMcbiS21Jx6n2f7TRhyYY1CL5jEng9qhM8rjfAven0= X-Received: from avagin.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:b84]) (user=avagin job=sendgmr) by 2002:a25:d8c9:0:b0:e30:c868:1eba with SMTP id 3f1490d57ef6-e30c868200cmr12089276.2.1730350576189; Wed, 30 Oct 2024 21:56:16 -0700 (PDT) Date: Thu, 31 Oct 2024 04:56:01 +0000 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Mailer: git-send-email 2.47.0.163.g1226f6d8fa-goog Message-ID: <20241031045602.309600-1-avagin@google.com> Subject: [PATCH] ucounts: fix counter leak in inc_rlimit_get_ucounts() From: Andrei Vagin To: "Eric W. Biederman" , Kees Cook Cc: Roman Gushchin , linux-kernel@vger.kernel.org, Andrei Vagin , Alexey Gladkov , stable@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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. Fixes: 15bc01effefe ("ucounts: Fix signal ucount refcounting") Tested-by: Roman Gushchin Co-debugged-by: Roman Gushchin Cc: Kees Cook Cc: Andrei Vagin Cc: "Eric W. Biederman" Cc: Alexey Gladkov Cc: Signed-off-by: Andrei Vagin Acked-by: Alexey Gladkov Acked-by: Roman Gushchin --- kernel/ucount.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/kernel/ucount.c b/kernel/ucount.c index 8c07714ff27d..16c0ea1cb432 100644 --- a/kernel/ucount.c +++ b/kernel/ucount.c @@ -328,13 +328,12 @@ long inc_rlimit_get_ucounts(struct ucounts *ucounts, = enum rlimit_type type) if (new !=3D 1) continue; if (!get_ucounts(iter)) - goto dec_unwind; + goto unwind; } return ret; -dec_unwind: +unwind: dec =3D atomic_long_sub_return(1, &iter->rlimit[type]); WARN_ON_ONCE(dec < 0); -unwind: do_dec_rlimit_put_ucounts(ucounts, iter, type); return 0; } --=20 2.47.0.163.g1226f6d8fa-goog