Commit 9ba2a5cb authored by Sagi Grimberg's avatar Sagi Grimberg Committed by Jens Axboe

nvmet: filter newlines from user input

We should avoid consuming the newlines in traddr, trsvcid and
device_path. Add minimal processing to make sure they are gone.
Reviewed-by: default avatarJohannes Thumshirn <jthumshirn@suse.de>
Signed-off-by: default avatarSagi Grimberg <sagi@grimberg.me>
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent d4c68c7a
...@@ -137,8 +137,10 @@ static ssize_t nvmet_addr_traddr_store(struct config_item *item, ...@@ -137,8 +137,10 @@ static ssize_t nvmet_addr_traddr_store(struct config_item *item,
pr_err("Disable the address before modifying\n"); pr_err("Disable the address before modifying\n");
return -EACCES; return -EACCES;
} }
return snprintf(port->disc_addr.traddr,
sizeof(port->disc_addr.traddr), "%s", page); if (sscanf(page, "%s\n", port->disc_addr.traddr) != 1)
return -EINVAL;
return count;
} }
CONFIGFS_ATTR(nvmet_, addr_traddr); CONFIGFS_ATTR(nvmet_, addr_traddr);
...@@ -208,8 +210,10 @@ static ssize_t nvmet_addr_trsvcid_store(struct config_item *item, ...@@ -208,8 +210,10 @@ static ssize_t nvmet_addr_trsvcid_store(struct config_item *item,
pr_err("Disable the address before modifying\n"); pr_err("Disable the address before modifying\n");
return -EACCES; return -EACCES;
} }
return snprintf(port->disc_addr.trsvcid,
sizeof(port->disc_addr.trsvcid), "%s", page); if (sscanf(page, "%s\n", port->disc_addr.trsvcid) != 1)
return -EINVAL;
return count;
} }
CONFIGFS_ATTR(nvmet_, addr_trsvcid); CONFIGFS_ATTR(nvmet_, addr_trsvcid);
...@@ -288,7 +292,7 @@ static ssize_t nvmet_ns_device_path_store(struct config_item *item, ...@@ -288,7 +292,7 @@ static ssize_t nvmet_ns_device_path_store(struct config_item *item,
kfree(ns->device_path); kfree(ns->device_path);
ret = -ENOMEM; ret = -ENOMEM;
ns->device_path = kstrdup(page, GFP_KERNEL); ns->device_path = kstrndup(page, strcspn(page, "\n"), GFP_KERNEL);
if (!ns->device_path) if (!ns->device_path)
goto out_unlock; goto out_unlock;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment