From nobody Mon Jun 15 15:10:46 2026 Received: from mail-pj1-f44.google.com (mail-pj1-f44.google.com [209.85.216.44]) (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 C17303BBA07 for ; Mon, 13 Apr 2026 13:39:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776087541; cv=none; b=E+MNm0/5D0W7Utpyju1H7vCzYVxBg9/w+gEd1EVKbpTisqUny+aVRP4ZGSN88MODhxzgeKzwMdF9E+u2iJEgxX22B8HH30K5BzGeUy+2S8XC0vGJ2RaAPu+U46aA34v4/aMdbzoXgUgr25xeqF+MLwS4GR8daQ6xMcd0lN5lLHc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776087541; c=relaxed/simple; bh=WtPMwZ26K63g/t20378ABYaP1ODXlf8DcUy79QB6GO8=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=cUAKfasrX9rtSJrreS1/gXBRk9KUDvNU1u4myX1dXN5DPq+Jjpv1zbJlCjA8U7qovT+iI6qm1StmqXEBerYDRm7ugMP+JJbt3u8XfXwcP+P9u7Kc9MTPP6TFL2kIdrreVIEkjseJ8aUbHM30o3olMjL4VEBxlSjT9oiZkbOoRmg= 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=NyH9Fbul; arc=none smtp.client-ip=209.85.216.44 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="NyH9Fbul" Received: by mail-pj1-f44.google.com with SMTP id 98e67ed59e1d1-35691a231a7so2880460a91.3 for ; Mon, 13 Apr 2026 06:39:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1776087540; x=1776692340; 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=UggCRQ3k+2UlRxrfgaRoIdFJUAAFZneZshl+NRND13M=; b=NyH9Fbul19gKRmqItER9DuzcXrvmNiGqvnMNN/59QkE0wfBzTGPBC4BYFYF/namXQO yx924DNIKpFWgfRH0WQlBCRXzTC0GouRzfo1p+fly8SjTtTzLi5lhVdAiXGpv6R9Qza7 lMHQ2uDRo+wQvQZKh6Ib+s7CC0BCN2BqVlY4K2hsStL6FKkE113kJF+UhIpqpZo29YVr Q5pqWb1fEh5wKvKG+hmY3l4T1IGlFTchxgNYjIDQYT7ga2o9cC9ZnZ6jM6PAf5DgKaCl FptrnoUssWgVvlRuDFtV7abLVarQXtTod/8okBMyn8EPVR5pdOAElEjFyFVsNt3Q7a6e h1XA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776087540; x=1776692340; 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=UggCRQ3k+2UlRxrfgaRoIdFJUAAFZneZshl+NRND13M=; b=Dqj9H6/+3n1AsMJtZ+YKFg4awRtrScsO2Nb62Dblzp/FUV9RpS9nzJ1Bx4pjhyxuyF J9XZv5bZ24xInpKFHACIuogixS2ICTSmYalaxPVwHjEl5JKB4J+lrqUlch6Fo5q6QbcT hYqo80BGegVhnUrWl6Eoua6K5bDcQN00y8oyfG0CXpVR4yWbyJ7YZWUuHOVyNA+5D3Qb FVlUMVNhNgZPtRNPOANwNwK23/ahQr6YlUaRkLCl7d9vMatiZbhxEvbEnYUgpHpem/7O zuLGxXcBU9+IlJ3VlLUWqiHnpnsPeeU3N1hT27ug0sxKVIA3RzgYPiifLrtWPmg2BHvJ +BSA== X-Forwarded-Encrypted: i=1; AFNElJ8wrCN+CqFznkQ9ql+azxGUdSlOKo8vZWiA+R8n9B/hTxeBxUpv7IBw/MBS9ukGFg9KysJICPp7Af7A5xs=@vger.kernel.org X-Gm-Message-State: AOJu0YweRrLsNt3Ag7yxiTFPAVxVWBViFPpiLYX9MHuwxodIrYhWUdAx QVdwk/yzyxTA61VGfUc6o5yl5ln8NQ+Rn3Tte68Fkri+EUfWX1Xs5WXEwNjIN5/LTuA= X-Gm-Gg: AeBDieuB+bGKJAIQDDzcvcFkGdimuo2vz4OiaF3vQTcj31pPmCFvoid0X4xF52kOSot MQs9g+67kW3mozXVNc1fKupH6fdtHKYEAIwlCdrDMsUs469LCBWurrww6t5ruEigGgTTsn6HQbZ xiGnWfJL/sVnz6iQpd2wzE9bxEu2zEXI2ydWKwDWyOHSX9VidSX6TX3ZflUN2DoVZut960cNuVb cyW6cU2KwfB6FrAkLHjqvAF4X4fCgwX30z+0B1OANO7ULLPc5PsIN5h/aNKx8d3ZqPI51wlj6TA 2jSNW2KYHzWV1cCP5UK6dCxc72AKrXEXzZTpJUtGAU2V/3pylqJhWTQREb+BA6bz7aBG9+L9jqE IXVkq9RtfFQUgDX1v536YvqJmbIvBiMKHoCSsvJ2kaBoUe2ybSU7MmBihnXkouWL56juQdMPQxp WEpYbEdU9tsPWBOw1eIZPwe5MGbfvcemY= X-Received: by 2002:a17:90b:3fc5:b0:356:22ef:57ba with SMTP id 98e67ed59e1d1-35e42759e2amr12027568a91.7.1776087539999; Mon, 13 Apr 2026 06:38:59 -0700 (PDT) Received: from lgs.. ([2409:893d:1188:142d:6c67:74e8:5200:1f39]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-35e41bc6541sm4419830a91.0.2026.04.13.06.38.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Apr 2026 06:38:59 -0700 (PDT) From: Guangshuo Li To: Arnd Bergmann , Greg Kroah-Hartman , Tony Jones , Kay Sievers , linux-kernel@vger.kernel.org Cc: Guangshuo Li , stable@vger.kernel.org Subject: [PATCH v2] enclosure: Fix refcount leak in enclosure_register() error path Date: Mon, 13 Apr 2026 21:38:50 +0800 Message-ID: <20260413133850.2841274-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 device_register(), the lifetime of the embedded struct device is expected to be managed through the device core reference counting. In enclosure_register(), if device_register() fails, the error path drops the parent device reference and frees edev directly instead of releasing the device reference with put_device(&edev->edev). This bypasses the normal device lifetime rules and may leave the reference count of the embedded struct device unbalanced, resulting in a refcount leak and potentially leading to a use-after-free. The issue was identified by a static analysis tool I developed and confirmed by manual review. Fix this by using put_device(&edev->edev) in the failure path and let enclosure_release() handle the final cleanup. Fixes: ee959b00c335 ("SCSI: convert struct class_device to struct device") Cc: stable@vger.kernel.org Signed-off-by: Guangshuo Li --- v2: - note that the issue was identified by my static analysis tool - and confirmed by manual review drivers/misc/enclosure.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/misc/enclosure.c b/drivers/misc/enclosure.c index ca4c420e4a2f..9532ad8f8b4e 100644 --- a/drivers/misc/enclosure.c +++ b/drivers/misc/enclosure.c @@ -148,8 +148,7 @@ enclosure_register(struct device *dev, const char *name= , int components, return edev; =20 err: - put_device(edev->edev.parent); - kfree(edev); + put_device(&edev->edev); return ERR_PTR(err); } EXPORT_SYMBOL_GPL(enclosure_register); --=20 2.43.0