From nobody Thu Jun 11 03:22:54 2026 Received: from mail-pj1-f43.google.com (mail-pj1-f43.google.com [209.85.216.43]) (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 004FD480DD5 for ; Tue, 5 May 2026 15:05:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777993532; cv=none; b=lpqZnQCEUIWcXjVSL/hwYlsPRopv5ChlQtMzy0w1JYef3z0OZ4VogbbxRME1ub+7MRmkDhgD/KKbrKM0gkw+l1FCWhCDC5rKSo8rftS0UCSDbE902IHdNu80fT2lZpuSs81oWAecB6Rn01rSgRdvxtwVtqaO9m3a+y7CaSv4UA4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777993532; c=relaxed/simple; bh=nel41D7/iSYikgPOWSHl22uvoq9mZoR7XVauvIj0kKA=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=ugD+C6WfH54znmczTCfmhyaY6k0fI9peOo6oHhVxqzJw2VTrjqJJxQwPU3TPFd4QqHo5EzYpFt3FL38025gOqgVZGPRrb1dvduRlDXP5MOBTjqMaz68CwIgFRcSJ9g1GwyxNsHTKt56C8cMPL8kSXWYvTha+fWrekq3HjjdAsok= 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=XWmSfV2B; arc=none smtp.client-ip=209.85.216.43 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="XWmSfV2B" Received: by mail-pj1-f43.google.com with SMTP id 98e67ed59e1d1-356337f058aso3525128a91.2 for ; Tue, 05 May 2026 08:05:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1777993530; x=1778598330; 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=nsydoNz+n1aoj4WKwfkkcVBLiH1l+lQ2IFQLRuoD3ew=; b=XWmSfV2BGq0NXdjANpOiqtlneTcjf8fefEDTupVfghGAuW6qMquwkInC57YoiSp4mJ PcbzlPLC9/vNo9TwkaCDNUNX36v6L4YU5Se1bPyFWZsfoxlQuVt+amnvBuycUXBSjfXr XjOCt64p8AbMprjhlYJIlx8TUf2vpXj3QbdNqz4/nnm2Sg9s9ZGZ6cjk2OUUDvhs6tsr V+Hvyx7xDaPgWqlj7guNFRNpZ2yUUoLglLzneK1sd+eF4jp8PZP6vYAT14jBG2PhT0P3 afN/3s2RdCJKYC13ht2GnPLrmx+5OescbxqV6FYPSjvA5WoLECdMWFXBxTbxG9/ZQOh3 LLYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777993530; x=1778598330; 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=nsydoNz+n1aoj4WKwfkkcVBLiH1l+lQ2IFQLRuoD3ew=; b=JcoOp9DuO5SFfF+saEvIOVEB4kugEVW9hBL8dlDaDB/9wddwU3Bt9T+w4BmmdA/vEj 3Z1m/1a9zOOpA7fCoSLQCVVxFMfTXeGthsLwUrpdn8keyesQtw6MiRisLvxFfHadeGT5 HjXXHx7bPmW5clZ63FitW3G0mSqUXKDnDW3BA9U1Lhpnmh8MSuImRAk8XA7SF0loZhm3 X2ORjXhjxcw6k9BkY2yzvsEXBYcso2szEAkzM0HI2/qnwp2AqYe1lTq0tWQckqhZPMzG PjWeRBYoCpxt/RU1ZTXH9MM6lbr79jBK5nB8/F/F2xEcSW5/uCQvemhGPi4ybCuEzEgH XLGw== X-Forwarded-Encrypted: i=1; AFNElJ8l2YXomsu1JR/97tn7mi1b3WJ+iOGn4kCkLZbEm0H+bAFQ5AqEKs6LBgc4xqwIcEgZDO9DEBk7zSdwrO8=@vger.kernel.org X-Gm-Message-State: AOJu0YwQSnIGoaEioxJW6GUOtnQlEKu2ZyFuvdf5x1dvb2MOytbqOnBv LqKJBguIohKnU/aK0Df8eBS3KJqtwhXpB1g+HsZ3W4fbWHYDZMgK3Iey X-Gm-Gg: AeBDiestM3Zae7fSz2wNH4DxdyzhgHKDK334i39FuWHqyGwk/a9rqJs0gRV+zfMVPtK q4in9yUjLLL5AQ7qVx4SthXvcLA8AOOCWA0P1NRZWMYq34Qxn7DemD+u3P/m33PHPYx/waLY4H7 1yjEAFsCbb94wSWLGYFbojriEJ0rp9r+D1Xd+/0YNBBQwb/01xs+v/zZEIwvNNch/wR1DGjvfrJ h4d+JmUchCPke9M3a/485YnEeUL/yzK3rYEy2qxf5b5pjs131gLDKn1ezsalwWYUMd90x81skfz zLQxncut3MBwmurm0SCTPKnX0Emnir/QhNGGcCkoaH/pVSpM0zU2Hu7ehog16AGeKgphaIJdtr8 h+79N3sJxec0FJMOXVPvv0RJKJnDuxelvIpumIkPah5O4Ce6F3HP2pzUUnhr8AJAaBgJAhZpN9r sS57OfDa2ov/Sr9l5o X-Received: by 2002:a17:90b:5543:b0:35d:a6eb:197f with SMTP id 98e67ed59e1d1-3650cb89b02mr13768708a91.0.1777993530069; Tue, 05 May 2026 08:05:30 -0700 (PDT) Received: from lgs.. ([2001:250:5800:1000::f280]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-36575df7ab8sm2136973a91.1.2026.05.05.08.05.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 May 2026 08:05:29 -0700 (PDT) From: Guangshuo Li To: Greg Kroah-Hartman , Yaxing Guo , linux-kernel@vger.kernel.org Cc: Guangshuo Li , stable@vger.kernel.org Subject: [PATCH v5] uio: uio_pci_generic_sva: fix double free of devm_kzalloc() memory Date: Tue, 5 May 2026 23:02:56 +0800 Message-ID: <20260505150256.614071-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" uio_pci_sva allocates struct uio_pci_sva_dev with devm_kzalloc() in probe(), but then calls kfree(udev) both on the probe() error path (label out_free) and again in remove(). Because devm_kzalloc() allocations are devres-managed and are freed automatically when the device is detached (including after a failing probe() and during driver unbind), the explicit kfree() can lead to a double free. If probe() fails after devm_kzalloc(), the error path frees udev and devres cleanup will free it again when the core unwinds the partially bound device. On normal driver removal, remove() frees udev and devres will free it again when the device is detached. This issue was identified by a static analysis tool I developed and confirmed by manual review. Fix by removing the manual kfree() calls and dropping the now-unused label. Fixes: 3397c3cd859a2 ("uio: Add SVA support for PCI devices via uio_pci_gen= eric_sva.c") Cc: stable@vger.kernel.org Signed-off-by: Guangshuo Li --- v5: - Remove the now-unused udev variable from remove(). v4: - Add description of how the issue was found and tested. v3: - Add changelog below the --- line describing changes since v2. v2: - Reflow commit message to keep lines within 75 characters. drivers/uio/uio_pci_generic_sva.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/drivers/uio/uio_pci_generic_sva.c b/drivers/uio/uio_pci_generi= c_sva.c index 4a46acd994a8..d05ef77f7e32 100644 --- a/drivers/uio/uio_pci_generic_sva.c +++ b/drivers/uio/uio_pci_generic_sva.c @@ -129,15 +129,13 @@ static int probe(struct pci_dev *pdev, const struct p= ci_device_id *id) ret =3D devm_uio_register_device(&pdev->dev, &udev->info); if (ret) { dev_err(&pdev->dev, "Failed to register uio device\n"); - goto out_free; + goto out_disable; } =20 pci_set_drvdata(pdev, udev); =20 return 0; =20 -out_free: - kfree(udev); out_disable: pci_disable_device(pdev); =20 @@ -146,11 +144,8 @@ static int probe(struct pci_dev *pdev, const struct pc= i_device_id *id) =20 static void remove(struct pci_dev *pdev) { - struct uio_pci_sva_dev *udev =3D pci_get_drvdata(pdev); - pci_release_regions(pdev); pci_disable_device(pdev); - kfree(udev); } =20 static ssize_t pasid_show(struct device *dev, --=20 2.43.0