Skip to content

Commit 072f19b

Browse files
sashalevinJames Bottomley
authored and
James Bottomley
committed
[SCSI] prevent stack buffer overflow in host_reset
store_host_reset() has tried to re-invent the wheel to compare sysfs strings. Unfortunately it did so poorly and never bothered to check the input from userspace before overwriting stack with it, so something simple as: echo "WoopsieWoopsie" > /sys/devices/pseudo_0/adapter0/host0/scsi_host/host0/host_reset would result in: [ 316.310101] Kernel panic - not syncing: stack-protector: Kernel stack is corrupted in: ffffffff81f5bac7 [ 316.310101] [ 316.320051] Pid: 6655, comm: sh Tainted: G W 3.7.0-rc5-next-20121114-sasha-00016-g5c9d68d-dirty raspberrypi#129 [ 316.320051] Call Trace: [ 316.340058] pps pps0: PPS event at 1352918752.620355751 [ 316.340062] pps pps0: capture assert seq raspberrypi#303 [ 316.320051] [<ffffffff83b3856b>] panic+0xcd/0x1f4 [ 316.320051] [<ffffffff81f5bac7>] ? store_host_reset+0xd7/0x100 [ 316.320051] [<ffffffff8110b996>] __stack_chk_fail+0x16/0x20 [ 316.320051] [<ffffffff81f5bac7>] store_host_reset+0xd7/0x100 [ 316.320051] [<ffffffff81e55bb3>] dev_attr_store+0x13/0x30 [ 316.320051] [<ffffffff812f7db1>] sysfs_write_file+0x101/0x170 [ 316.320051] [<ffffffff8127acc8>] vfs_write+0xb8/0x180 [ 316.320051] [<ffffffff8127ae80>] sys_write+0x50/0xa0 [ 316.320051] [<ffffffff83c03418>] tracesys+0xe1/0xe6 Fix this by uninventing whatever was going on there and just use sysfs_streq. Bug introduced by 2944369 ("[SCSI] scsi: Added support for adapter and firmware reset"). [jejb: added necessary const to prevent compile warnings] Signed-off-by: Sasha Levin <[email protected]> Cc: <[email protected]> #3.2+ Signed-off-by: James Bottomley <[email protected]>
1 parent a3667aa commit 072f19b

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

drivers/scsi/scsi_sysfs.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -247,11 +247,11 @@ show_shost_active_mode(struct device *dev,
247247

248248
static DEVICE_ATTR(active_mode, S_IRUGO | S_IWUSR, show_shost_active_mode, NULL);
249249

250-
static int check_reset_type(char *str)
250+
static int check_reset_type(const char *str)
251251
{
252-
if (strncmp(str, "adapter", 10) == 0)
252+
if (sysfs_streq(str, "adapter"))
253253
return SCSI_ADAPTER_RESET;
254-
else if (strncmp(str, "firmware", 10) == 0)
254+
else if (sysfs_streq(str, "firmware"))
255255
return SCSI_FIRMWARE_RESET;
256256
else
257257
return 0;
@@ -264,12 +264,9 @@ store_host_reset(struct device *dev, struct device_attribute *attr,
264264
struct Scsi_Host *shost = class_to_shost(dev);
265265
struct scsi_host_template *sht = shost->hostt;
266266
int ret = -EINVAL;
267-
char str[10];
268267
int type;
269268

270-
sscanf(buf, "%s", str);
271-
type = check_reset_type(str);
272-
269+
type = check_reset_type(buf);
273270
if (!type)
274271
goto exit_store_host_reset;
275272

0 commit comments

Comments
 (0)