Skip to contentSkip to conversation

scsi: target: iblock: Fix wrong PR ops NULL check for PREEMPT/RELEASE

PATCH Applied [email protected] 4 participants 4 messages Jul 24 – Jul 29

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 scsi: target: iblock: Fix wrong PR ops NULL check for PREEMPT/RELEASE

From: TanZheng <[email protected]>

In the iblock_execute_pr_out function, PRO_PREEMPT, PRO_PREEMPT_AND_ABORT and PRO_RELEASE all perform callback capability checks through ops->pr_clear. The error check allows unimplemented hooks to pass through the gate, resulting dereferencing a NULL function pointer.

Check whether the hooks that need to be called are supported.

Fixes 394f81184882 ("scsi: target: Add block PR support to iblock")
---
 drivers/target/target_core_iblock.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/target/target_core_iblock.c +3 -3
index 1087d1d17c36..ea65d39fef88 100644
@@ -906,7 +906,7 @@ static sense_reason_t iblock_execute_pr_out(struct se_cmd *cmd, u8 sa, u64 key,
 		break;
 	case PRO_PREEMPT:
 	case PRO_PREEMPT_AND_ABORT:
-		if (!ops->pr_clear) {
+		if (!ops->pr_preempt) {
 			pr_err("block_device does not support pr_preempt.\n");
 			return TCM_UNSUPPORTED_SCSI_OPCODE;
 		}
@@ -916,8 +916,8 @@ static sense_reason_t iblock_execute_pr_out(struct se_cmd *cmd, u8 sa, u64 key,
 				      sa == PRO_PREEMPT_AND_ABORT);
 		break;
 	case PRO_RELEASE:
-		if (!ops->pr_clear) {
-			pr_err("block_device does not support pr_pclear.\n");
+		if (!ops->pr_release) {
+			pr_err("block_device does not support pr_release.\n");
 			return TCM_UNSUPPORTED_SCSI_OPCODE;
 		}
 
Signature · 1 line
2.25.1
#1 lore raw
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] Un-ratelimited error logging can be abused by an initiator to flood the kernel log. --

--- Patch [1]: [PATCH] scsi: target: iblock: Fix wrong PR ops NULL check for PREEMPT/RELEASE --- commit 562d965ef4dd6b2eb1b1b38dac4b060b92e2df13
Author: TanZheng <[email protected]>

scsi: target: iblock: Fix wrong PR ops NULL check for PREEMPT/RELEASE

This commit corrects a bug in the iblock_execute_pr_out function where the pr_clear callback was being checked instead of the corresponding pr_preempt and pr_release callbacks. This fixes a potential NULL pointer dereference if those specific PR ops are unimplemented.

drivers/target/target_core_iblock.c static sense_reason_t iblock_execute_pr_out(struct se_cmd *cmd, u8 sa, u64 key, · line 910

Quoted 9 lines
drivers/target/target_core_iblock.c +1 -1
@@ -906,7 +906,7 @@ static sense_reason_t iblock_execute_pr_out(struct se_cmd *cmd, u8 sa, u64 key,
 		break;
 	case PRO_PREEMPT:
 	case PRO_PREEMPT_AND_ABORT:
-		if (!ops->pr_clear) {
+		if (!ops->pr_preempt) {
 			pr_err("block_device does not support pr_preempt.\n");

[Severity: High]
This is a pre-existing issue, but could this un-ratelimited error logging be abused by a remote initiator to flood the kernel log?

If a malicious or misbehaving SCSI initiator repeatedly sends PR OUT commands with unsupported operations, it will hit this pr_err() at a high frequency. This could flood the dmesg buffer, hide other critical messages, and potentially cause resource exhaustion.

This same pattern exists throughout iblock_execute_pr_out, including the default switch case for unknown Service Actions:

    default:
        pr_err("Unknown PERSISTENT_RESERVE_OUT SA: 0x%02x\n", sa);
        return TCM_UNSUPPORTED_SCSI_OPCODE;

Would it be safer to use pr_err_ratelimited() for these initiator-triggerable errors?

Quoted 2 lines
drivers/target/target_core_iblock.c +0 -0
 			return TCM_UNSUPPORTED_SCSI_OPCODE;
 		}
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Reviewed-by on v1 1/1
#2 lore raw
In reply to [email protected]
Quoted 11 lines · On 7/24/26 2:58 AM, [email protected] wrote:

From: TanZheng <[email protected]>

In the iblock_execute_pr_out function, PRO_PREEMPT, PRO_PREEMPT_AND_ABORT and PRO_RELEASE all perform callback capability checks through ops->pr_clear. The error check allows unimplemented hooks to pass through the gate, resulting dereferencing a NULL function pointer.

Check whether the hooks that need to be called are supported.

Fixes 394f81184882 ("scsi: target: Add block PR support to iblock")
#3 lore raw
In reply to [email protected]
Quoted 8 lines · On Fri, 24 Jul 2026 15:58:50 +0800, [email protected] wrote:

In the iblock_execute_pr_out function, PRO_PREEMPT, PRO_PREEMPT_AND_ABORT and PRO_RELEASE all perform callback capability checks through ops->pr_clear. The error check allows unimplemented hooks to pass through the gate, resulting dereferencing a NULL function pointer.

Check whether the hooks that need to be called are supported.

[...]

Applied to 7.2/scsi-fixes, thanks!

[1/1] scsi: target: iblock: Fix wrong PR ops NULL check for PREEMPT/RELEASE

      https://git.kernel.org/mkp/scsi/c/9c33222bd387
Signature · 1 line
Martin K. Petersen