[PATCH v2 3/8] scsi: target: reject a short SET TARGET PORT GROUPS list
From: Jia Jia
Date: Tue Nov 17 2026 - 23:14:27 EST
SET TARGET PORT GROUPS has a four-byte header followed by four-byte
descriptors. target_emulate_set_target_port_groups() accepts any list
at least four bytes long, then walks a descriptor whenever bytes remain.
A five-byte list can therefore make get_unaligned_be16() read past the
parameter data.
Reject lists whose lengths are not multiples of four before walking
them or changing port group state.
KASAN reports:
BUG: KASAN: use-after-free in target_emulate_set_target_port_groups+0x1dc/0x540 [target_core_mod]
Read of size 2
target_emulate_set_target_port_groups
__target_execute_cmd
target_execute_cmd
vhost_scsi_write_pending
transport_generic_new_cmd
Fixes: c66ac9db8d4a ("[SCSI] target: Add LIO target core v4.0.0-rc6")
Signed-off-by: Jia Jia <physicalmtea@xxxxxxxxx>
---
drivers/target/target_core_alua.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/target/target_core_alua.c b/drivers/target/target_core_alua.c
index c110914b7b78b..22b4c39748704 100644
--- a/drivers/target/target_core_alua.c
+++ b/drivers/target/target_core_alua.c
@@ -298,9 +298,9 @@ target_emulate_set_target_port_groups(struct se_cmd *cmd)
int alua_access_state, primary = 0, valid_states;
u16 tg_pt_id, rtpi;
- if (cmd->data_length < 4) {
- pr_warn("SET TARGET PORT GROUPS parameter list length %u too"
- " small\n", cmd->data_length);
+ if (cmd->data_length < 4 || (cmd->data_length & 3)) {
+ pr_warn("SET TARGET PORT GROUPS invalid list length %u\n",
+ cmd->data_length);
return TCM_INVALID_PARAMETER_LIST;
}