From patchwork Tue Dec 17 10:58:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guixin Liu X-Patchwork-Id: 852305 Received: from out30-101.freemail.mail.aliyun.com (out30-101.freemail.mail.aliyun.com [115.124.30.101]) (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 C30A81EB9E8 for ; Tue, 17 Dec 2024 10:58:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.101 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734433138; cv=none; b=u0xeTzaLF0rdVrxOZTnYDKI/c5GNutKy8PR8QWdvVwyMNrJcDCmODkXTpVCLKgQ4k5mBJvqGij/AzEx6Xvx96xerTJ7nMzmBlUPUcvZO2+4v/3f6BCaAdBlrIdBRamnFHHxR+UyA79DiLY5JDeWScanGAp/atPsEaGEvMF+TuX8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734433138; c=relaxed/simple; bh=gWrQlSTzr4nVUZNOUodnVFD6bjhpA4RtMJdrGKTKEu0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QgeTNSp8SAliqA3Pn29IxxTd17+WBKTw3z18NFjo8hzXa8sn4JsG6r7lgLY9AxwLbf37fEr3MxHAY0YBQldoWKnIcXHGNbcBl3uH+kjp77KzhsVI9TbdL7rwxuOG6o/wPJeQ/Awg6E1poTN9czMukC4PlyyvBwIrqp2qBNzk28w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=reCbolTk; arc=none smtp.client-ip=115.124.30.101 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="reCbolTk" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1734433131; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=QW/xovfrvnu4XdsN/L25eDlZf5saxk45kn8XkVhNOLI=; b=reCbolTkELhEK0xxFRn861uNk25LHwi8M94v3uhHPcXnESLaLZXggpM++pJ3ouNZiKCrFv+Rw9oEE2HjKnQCvG77jyMkghgCIsHhH8FjoKxchuDeQstFDa6br1+g1SkMK5xr7WIqMpuk3DgP7BT0x6Cs8GT+T3pxZvGwAYCpc7o= Received: from localhost(mailfrom:kanie@linux.alibaba.com fp:SMTPD_---0WLiZ2-y_1734433126 cluster:ay36) by smtp.aliyun-inc.com; Tue, 17 Dec 2024 18:58:50 +0800 From: Guixin Liu To: Alim Akhtar , Avri Altman , Bart Van Assche , "James E . J . Bottomley" , "Martin K . Petersen" Cc: linux-scsi@vger.kernel.org Subject: [PATCH 1/2] scsi: ufs: delete bsg_dev when setup bsg fail Date: Tue, 17 Dec 2024 18:58:39 +0800 Message-ID: <20241217105840.120081-2-kanie@linux.alibaba.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241217105840.120081-1-kanie@linux.alibaba.com> References: <20241217105840.120081-1-kanie@linux.alibaba.com> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 We should remove the bsg device when bsg_setup_queue() return fail to release the resources. Signed-off-by: Guixin Liu --- drivers/ufs/core/ufs_bsg.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/ufs/core/ufs_bsg.c b/drivers/ufs/core/ufs_bsg.c index 6c09d97ae006..58023f735c19 100644 --- a/drivers/ufs/core/ufs_bsg.c +++ b/drivers/ufs/core/ufs_bsg.c @@ -257,6 +257,7 @@ int ufs_bsg_probe(struct ufs_hba *hba) NULL, 0); if (IS_ERR(q)) { ret = PTR_ERR(q); + device_del(bsg_dev); goto out; } From patchwork Tue Dec 17 10:58:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guixin Liu X-Patchwork-Id: 851631 Received: from out30-113.freemail.mail.aliyun.com (out30-113.freemail.mail.aliyun.com [115.124.30.113]) (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 33AAE1E8823 for ; Tue, 17 Dec 2024 10:59:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.113 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734433146; cv=none; b=qorPWh97MpfxO5L5KMR+/Celf/xXqJvp7FYnoauDP9kCXmVPpbQUjlMPYoLzpgusgV6M2hs/j6FdZsf3NQyatS+lRb8RD7lUHI5EdCBatff3Z6RfROz04UhOMRfLree9fqJa3mu9AKHMcEM5AviPV2EfIQ0ARhwG65HDKWU9IHw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734433146; c=relaxed/simple; bh=0q/vRBue26MgCPntAdFd60YFDQHhIcfoeTMFI7wi08w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XTc63qaRZCetSyWhIgdCur7IK6F3jwjxdXU388W6J8O7caZ8lf0zMnCO21MVoI3tN3Z0bo8QH+/cMh6Rr/kFP9pJRJ9xyiJl1s+2VU3dOUeUSXMBueM9yNXZW2h8KQ3Wh2L6Dn1pPzaZl92cbXphYS04WzyaLZ2I1G8TCdpbco0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=FS16hFz8; arc=none smtp.client-ip=115.124.30.113 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="FS16hFz8" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1734433136; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=s/7w0ibCS2KTb5dCH6Je4t8+tD3bgIfnHg/yaZWWvaw=; b=FS16hFz86P/OHDv3g5ixa7OQQre171uywfPdmas7SE8dgYuBOuXFirZ8SHbxSq7z4zPu1VJC/pHYodWvLZlAMI8dFF7blwUpQZGOMz/uzI70Z199flazAufVgezVbKd6X/UIhFwByVnrS0a6QMBDV3S+UpNDT+eSyBy71WqUXlI= Received: from localhost(mailfrom:kanie@linux.alibaba.com fp:SMTPD_---0WLiZ20N_1734433131 cluster:ay36) by smtp.aliyun-inc.com; Tue, 17 Dec 2024 18:58:56 +0800 From: Guixin Liu To: Alim Akhtar , Avri Altman , Bart Van Assche , "James E . J . Bottomley" , "Martin K . Petersen" Cc: linux-scsi@vger.kernel.org Subject: [PATCH 2/2] scsi: ufs: set bsg_queue to NULL after remove Date: Tue, 17 Dec 2024 18:58:40 +0800 Message-ID: <20241217105840.120081-3-kanie@linux.alibaba.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241217105840.120081-1-kanie@linux.alibaba.com> References: <20241217105840.120081-1-kanie@linux.alibaba.com> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Currently, this does not cause any issues, but I believe it is necessary to set bsg_queue to NULL after removing it to prevent potential use-after-free (UAF) access. Signed-off-by: Guixin Liu --- drivers/ufs/core/ufs_bsg.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/ufs/core/ufs_bsg.c b/drivers/ufs/core/ufs_bsg.c index 58023f735c19..8d4ad0a3f2cf 100644 --- a/drivers/ufs/core/ufs_bsg.c +++ b/drivers/ufs/core/ufs_bsg.c @@ -216,6 +216,7 @@ void ufs_bsg_remove(struct ufs_hba *hba) return; bsg_remove_queue(hba->bsg_queue); + hba->bsg_queue = NULL; device_del(bsg_dev); put_device(bsg_dev);