From nobody Mon Jun 15 15:08:19 2026 Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) (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 630D43624C4 for ; Sun, 12 Apr 2026 17:54:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776016485; cv=none; b=LBL3U66m/CqbaQsII0Zm403eZJcfHSIuD7RfyIYyo8BEZvGQnN06LVg0RYY/hisgbAwOutd37trsY/9GEqLW7aDW+/Mjx0/Cqzvf04fWH1lIxWMRQcQhleDKdkCArOMso8N75/SMiR46cL28itsb7c0vgru3w6E02pSLwC9mhrs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776016485; c=relaxed/simple; bh=eWr2u+WsL7203seYPlzK90nPqYFM0pnWF51zgRqHmO4=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=RMLT2ZynrtQQ1zaolJ9xDsZgLHspZenV60KWvK8ykFxj2qs1VSdkbl1v/mrb8FjD4gyF23mb9bIowULcQPymxoOETDpACH6W+trmhi0UKThsLSLnRrdJXn8pGmY6E45QZz/MoXEb4ke9zZGwfU7ZQTd7ow4iH4lHJy/YHuzoCrw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Rbiioped; arc=none smtp.client-ip=209.85.214.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Rbiioped" Received: by mail-pl1-f169.google.com with SMTP id d9443c01a7336-2b4583f0a1aso2813875ad.3 for ; Sun, 12 Apr 2026 10:54:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1776016483; x=1776621283; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=YDfdf5SNMNx3/WAzaXsxgQ2xJAL/YKTWXjEjNPHPnao=; b=RbiiopedT4gGaRXLBcAzMvNSvVOywXDFCwOEJZy21acz3aqvf5LQgeX2xJK8ELnhdn xyefg2oAkkpiNYir8KKTKNCVPvqxYn96Qs7Wq2iBZrWJwi5NGHlgQY8yeUD0qOrE4Mg2 QeTJsFLMefCBWU8H9a8F2OTCZd9I8Wl5OXKrLlQePE3Znfk5+VsqeET36HOjygfyzvLx Jo5MG3wEsnWb8FSawN33u8XX7u3m3PS9bZJgeGWukh9Pt0Xo/uC7DpNFlOc2OprD2FGA 0btHEOYu5SnXJtcomSCKe+gxJuX8xy3ZQn9+jUKJe8QyFemVrh6gn8sj0XQwtXoYS7a7 kimg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776016483; x=1776621283; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=YDfdf5SNMNx3/WAzaXsxgQ2xJAL/YKTWXjEjNPHPnao=; b=HZ4x2cDdbxQRTGeGluqF8FU1wgwGEEYWDdt2zefV7rFKfV74KHPQFZmOtGGCrVHDTq XgxAyLZz+bw3I3Zgespal0zTljoUxD+t19R8H7W7QfqE9wF/BIf2FCUZV5SMFyrq6akL gTWnWIc56yEoeIC7aVMhBHe4BvAw5kQ0sK3tj3sviSORyy1wfzKIJU+FummylrDuHe61 7on/JVjxzzO7HK4iqXsQs/LYGqE1fGVw4v00rskdNi5nLmwPpp5XinW3dmxqLekPyzLl vG3nNTUNOqhdt8rMYXRsd0Pb+G0kUkCM/ZzktUrEC23+nDKXJaMY5h/HVAiZeHugsaMV ImCg== X-Forwarded-Encrypted: i=1; AFNElJ+mZPDXkKnllsogo+eO0yUvpU9kfXxd9zH4NsbYgzcs7prZubg95FHsuLZqDjtuRXP+6Xt2SeUO2MJ7ixw=@vger.kernel.org X-Gm-Message-State: AOJu0YxTXM0Iqy3WkoLttEcthLiJzOs16zGStjXuBZVffV6BQnurb0VQ 3V2/hrjoo1ylN9p7TANIWNeqO3mvCtBhwPd3qhBJsxPa3SLZB4Umek0B X-Gm-Gg: AeBDies7MGIzjfHusBRZ6QjsdLHk5iBGszPl3N6oRTuSJNJuJr/uUw3mrWGqiL/CQ4n etZma+WKx0TGIk+hx53ST2wTy3puca9+pqrLC6hKQVa5SyuSorCoGSCJxAsRnU6iIXBYvzyGegl Y45iXEQghnBgs4Ve893uAB1HoPX5kjdDmMeLyTiLwm106K/oN1UqiCD/tlY0tHmKO/ieVyn5izO madGaEshTZMRc/RuVPwVNLfCN20Wcg2gv8VFzA0GPsQi1+q+ydkoPKt39MEMr9n3TixcK6MY4ay 07meOQ+vti1wE2hShE6QzYy0QSZ4V1IgWsWs/3DbeR2qAY2d3SNBPdfPu3tMD5S6gx8ePbb0m+S BH/8PNnODL22gu1IIzbn0or0d+fGZUf9Qd2J97jV295kzUDpsDsGHuNA+Ou2Ps0prWetQlf1R0A eHhIb480iQ4BijMzuhXsh5rzB+ X-Received: by 2002:a17:902:f642:b0:2b4:5986:cd80 with SMTP id d9443c01a7336-2b45986d953mr20083035ad.26.1776016483595; Sun, 12 Apr 2026 10:54:43 -0700 (PDT) Received: from lgs.. ([2409:893d:1188:142d:6dbb:2e05:75d3:967e]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2b2d4f25d83sm92119835ad.58.2026.04.12.10.54.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 Apr 2026 10:54:42 -0700 (PDT) From: Guangshuo Li To: Andrew Morton , David Hildenbrand , Lorenzo Stoakes , Zi Yan , Baolin Wang , "Liam R. Howlett" , Nico Pache , Ryan Roberts , Dev Jain , Barry Song , Lance Yang , linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Guangshuo Li , stable@vger.kernel.org Subject: [PATCH v2] mm: thp: Fix refcount leak in thpsize_create() error path Date: Mon, 13 Apr 2026 01:54:28 +0800 Message-ID: <20260412175428.2613383-1-lgs201920130244@gmail.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" After kobject_init_and_add(), the lifetime of the embedded struct kobject is expected to be managed through the kobject core reference counting. In thpsize_create(), if kobject_init_and_add() fails, thpsize is freed directly with kfree() rather than releasing the kobject reference with kobject_put(). This may leave the reference count of the embedded struct kobject unbalanced, resulting in a refcount leak. Fix this by using kobject_put(&thpsize->kobj) in the failure path and letting thpsize_release() handle the final cleanup. Fixes: 3485b88390b0 ("mm: thp: introduce multi-size THP sysfs interface") Cc: stable@vger.kernel.org Signed-off-by: Guangshuo Li --- v2: - Drop the incorrect UAF mention from the commit message - Clarify that the bug is an unbalanced kobject reference in the - kobject_init_and_add() failure path mm/huge_memory.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 40cf59301c21..c8ffa188a198 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -726,10 +726,8 @@ static struct thpsize *thpsize_create(int order, struc= t kobject *parent) =20 ret =3D kobject_init_and_add(&thpsize->kobj, &thpsize_ktype, parent, "hugepages-%lukB", size); - if (ret) { - kfree(thpsize); + if (ret) goto err; - } =20 =20 ret =3D sysfs_add_group(&thpsize->kobj, &any_ctrl_attr_grp); --=20 2.43.0