Linux SCSI subsystem development
 help / color / mirror / Atom feed
* [PATCH] scsi: ufs: rpmb: Return -EIO instead of SCSI result on failure
@ 2026-11-24  4:52 Nayeon Kim via B4 Relay
  2026-11-24  4:56 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Nayeon Kim via B4 Relay @ 2026-11-24  4:52 UTC (permalink / raw)
  To: linux-scsi, Martin K. Petersen
  Cc: Alim Akhtar, Jorge Ramirez-Ortiz, James E.J. Bottomley, Bean Huo,
	Bart Van Assche, linux-kernel, Stanley Jhu

From: Nayeon Kim <nayeoni.kim@samsung.com>

rpmb_route_frames() is documented to return a negative errno on
failure, but ufs_sec_submit() returns the value of scsi_execute_cmd()
as is. When a SECURITY PROTOCOL IN/OUT command fails, that value is a
positive SCSI result such as SAM_STAT_CHECK_CONDITION or
DID_ERROR << 16. ufs_rpmb_route_frames() passes it up and logs it as
"ret=%d". Since scsi_execute_cmd() sets RQF_QUIET, the sense data is
not logged anywhere.

handle_rpc_func_rpmb_frames(), the only caller of rpmb_route_frames(),
checks for a non-zero return, so OP-TEE still sees the failure.

Log the SCSI result and sense data in ufs_sec_submit() and convert
positive results to -EIO, as ufshcd_set_dev_pwr_mode() does.

Signed-off-by: Nayeon Kim <nayeoni.kim@samsung.com>
---
Based on 7.4/scsi-fixes because it depends on commit 7bc9b854cd68
("scsi: ufs: rpmb: Decouple device lifecycle from devres to avoid UAF").
Not urgent; fine for 7.5. Compile-tested (W=1) only.
---
 drivers/ufs/core/ufs-rpmb.c | 20 +++++++++++++++++---
 1 file changed, 17 insertions(+), 3 deletions(-)

diff --git a/drivers/ufs/core/ufs-rpmb.c b/drivers/ufs/core/ufs-rpmb.c
index 6803f3e62d78..d94633700cdf 100644
--- a/drivers/ufs/core/ufs-rpmb.c
+++ b/drivers/ufs/core/ufs-rpmb.c
@@ -19,6 +19,7 @@
 #include <linux/rpmb.h>
 #include <linux/string.h>
 #include <linux/list.h>
+#include <scsi/scsi_dbg.h>
 #include <ufs/ufshcd.h>
 #include <linux/unaligned.h>
 #include "ufshcd-priv.h"
@@ -55,10 +56,13 @@ static int ufs_sec_submit(struct ufs_rpmb_dev *ufs_rpmb, u16 spsp,
 	struct scsi_failures failures = {
 		.failure_definitions = failure_defs,
 	};
+	struct scsi_sense_hdr sshdr;
 	const struct scsi_exec_args exec_args = {
+		.sshdr = &sshdr,
 		.failures = &failures,
 	};
 	u8 cdb[12] = { };
+	int ret;
 
 	if (!sdev || !scsi_device_online(sdev))
 		return -ENODEV;
@@ -68,9 +72,19 @@ static int ufs_sec_submit(struct ufs_rpmb_dev *ufs_rpmb, u16 spsp,
 	put_unaligned_be16(spsp, &cdb[2]);
 	put_unaligned_be32(len, &cdb[6]);
 
-	return scsi_execute_cmd(sdev, cdb, send ? REQ_OP_DRV_OUT : REQ_OP_DRV_IN,
-				buffer, len, /*timeout=*/30 * HZ, /*retries=*/0,
-				&exec_args);
+	ret = scsi_execute_cmd(sdev, cdb, send ? REQ_OP_DRV_OUT : REQ_OP_DRV_IN,
+			       buffer, len, /*timeout=*/30 * HZ, /*retries=*/0,
+			       &exec_args);
+	if (ret > 0) {
+		dev_err(&ufs_rpmb->dev,
+			"SECURITY PROTOCOL %s failed: result %#x\n",
+			send ? "OUT" : "IN", ret);
+		if (scsi_sense_valid(&sshdr))
+			scsi_print_sense_hdr(sdev, NULL, &sshdr);
+		ret = -EIO;
+	}
+
+	return ret;
 }
 
 /* UFS RPMB route frames implementation */

---
base-commit: efd68f17acca65f581b9f2fa9ba50c8643ab544d
change-id: 20261124-b4-ufs-3-rpmb-errno-94dfb88ef817



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] scsi: ufs: rpmb: Return -EIO instead of SCSI result on failure
  2026-11-24  4:52 [PATCH] scsi: ufs: rpmb: Return -EIO instead of SCSI result on failure Nayeon Kim via B4 Relay
@ 2026-11-24  4:56 ` sashiko-bot
  0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-11-24  4:56 UTC (permalink / raw)
  To: Nayeon Kim, linux-scsi

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] scsi: ufs: rpmb: missing Fixes trailer for return value fix in
  ufs_sec_submit()
--

commit 04d79d2b7f15b664ba1b55919c7db6dc6388376b
Author: Nayeon Kim <nayeoni.kim@samsung.com>

> scsi: ufs: rpmb: Return -EIO instead of SCSI result on failure
>
> rpmb_route_frames() is documented to return a negative errno on
> failure, but ufs_sec_submit() returns the value of scsi_execute_cmd()
> as is. When a SECURITY PROTOCOL IN/OUT command fails, that value is a
> positive SCSI result such as SAM_STAT_CHECK_CONDITION or
> DID_ERROR << 16. ufs_rpmb_route_frames() passes it up and logs it as
> "ret=%d". Since scsi_execute_cmd() sets RQF_QUIET, the sense data is
> not logged anywhere.
>
> handle_rpc_func_rpmb_frames(), the only caller of rpmb_route_frames(),
> checks for a non-zero return, so OP-TEE still sees the failure.
>
> Log the SCSI result and sense data in ufs_sec_submit() and convert
> positive results to -EIO, as ufshcd_set_dev_pwr_mode() does.
>
> Signed-off-by: Nayeon Kim <nayeoni.kim@samsung.com>

[Severity: Low]
This fixes the return value contract of ufs_sec_submit().  Should it
include a Fixes tag:

  Fixes: b06b8c421485 ("scsi: ufs: core: Add OP-TEE based RPMB driver for UFS devices")

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261124-b4-ufs-3-rpmb-errno-v1-1-65b54643ca21@samsung.com?part=1

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-24  4:56 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-24  4:52 [PATCH] scsi: ufs: rpmb: Return -EIO instead of SCSI result on failure Nayeon Kim via B4 Relay
2026-11-24  4:56 ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox