Skip to contentSkip to conversation

Fix segfault if device_type set to pt but bstype not sg or bsg

PATCH Applied Andy Grover 2 participants 2 messages Mar 18, 2014 – Mar 22, 2014 Kbuild

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fix segfault if device_type set to pt but bstype not sg or bsg

If bstype not set to sg or bsg, it will default to rdwr, and we will call target_cmd_perform instead of target_cmd_perform_passthrough when accessing the device, which crashes tgtd. There's an existing check for setting bstype without setting dev_type, but also add a check the other way, setting dev_type without setting bstype to a valid value for pt.

Add an error message to the existing check, as well.

---
 usr/target.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
usr/target.c +10 -0
index 0f3066b..6dce46b 100644
@@ -547,6 +547,16 @@ tgtadm_err tgt_device_create(int tid, int dev_type, uint64_t lun, char *params,
 	if ((!strncmp(bst->bs_name, "bsg", 3) ||
 	     !strncmp(bst->bs_name, "sg", 2)) &&
 	    dev_type != TYPE_PT) {
+		eprintf("Must set device type to pt for bsg/sg bstype\n");
+		adm_err = TGTADM_INVALID_REQUEST;
+		goto out;
+	}
+
+	if (!(!strncmp(bst->bs_name, "bsg", 3) ||
+	     !strncmp(bst->bs_name, "sg", 2)) &&
+	    dev_type == TYPE_PT) {
+		eprintf("Must set bstype to bsg or sg for devicetype pt, not %s\n",
+			bst->bs_name);
 		adm_err = TGTADM_INVALID_REQUEST;
 		goto out;
 	}
Signature · 1 line
1.8.5.3
#1 lore raw
Quoted 6 lines · On Tue, 18 Mar 2014 11:02:02 -0700 Andy Grover <[email protected]> wrote:

If bstype not set to sg or bsg, it will default to rdwr, and we will call target_cmd_perform instead of target_cmd_perform_passthrough when accessing the device, which crashes tgtd. There's an existing check for setting bstype without setting dev_type, but also add a check the other way, setting dev_type without setting bstype to a valid value for pt.

Quoted 6 lines

Add an error message to the existing check, as well.

---
 usr/target.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

Applied, thanks a lot!