RDMA/core: Fix storing node description
PATCH 1/1 RDMA/core: Fix storing node description
Make sure to return -EINVAL when the supplied string is bigger then IB_DEVICE_NODE_DESC_MAX.
--- drivers/infiniband/core/sysfs.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/infiniband/core/sysfs.c +4 -1
@@ -1265,10 +1265,13 @@ static ssize_t node_desc_store(struct device *device,struct ib_device_modify desc = {};int ret; +if (count >IB_DEVICE_NODE_DESC_MAX ) +return -EINVAL ; +if (!dev->ops.modify_device)return -EOPNOTSUPP ; -memcpy (desc.node_desc, buf,min_t (int, count,IB_DEVICE_NODE_DESC_MAX )); +memcpy (desc.node_desc, buf, count); ret =ib_modify_device (dev,IB_DEVICE_MODIFY_NODE_DESC , &desc);if (ret)return ret;
Signature · 1 line
2.21.1
Quoted 13 lines · Kamal Heib
Make sure to return
-EINVALwhen the supplied string is bigger thenIB_DEVICE_NODE_DESC_MAX.Fixes c5bcbbb9fe00 ("IB: Allow userspace to set node description")Signed-off-by Kamal Heib <[email protected]>drivers/infiniband/core/sysfs.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)drivers/infiniband/core/sysfs.c +1
-0+++ b/drivers/infiniband/core/sysfs.c@@ -1265,10 +1265,13 @@ static ssize_t node_desc_store(struct device *device,struct ib_device_modify desc = {};
drivers/infiniband/core/sysfs.c static ssize_t node_desc_store(struct device *device, · line 1274
Quoted 10 lines
drivers/infiniband/core/sysfs.c +4
-1int ret; +if (count >IB_DEVICE_NODE_DESC_MAX ) +return -EINVAL ; +if (!dev->ops.modify_device)return -EOPNOTSUPP ; -memcpy (desc.node_desc, buf,min_t (int, count,IB_DEVICE_NODE_DESC_MAX )); +memcpy (desc.node_desc, buf, count);
I think this should just be written as
if (strscpy(desc.node_desc, buf, sizeof(desc.node_desc)) == -E2BIG)
return -EINVAL;
Jason
Quoted 22 lines · Jason Gunthorpe
Quoted 21 lines · Kamal Heib
Make sure to return
-EINVALwhen the supplied string is bigger thenIB_DEVICE_NODE_DESC_MAX.Fixes c5bcbbb9fe00 ("IB: Allow userspace to set node description")Signed-off-by Kamal Heib <[email protected]>drivers/infiniband/core/sysfs.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)drivers/infiniband/core/sysfs.c +4
-0+++ b/drivers/infiniband/core/sysfs.c@@ -1265,10 +1265,13 @@ static ssize_t node_desc_store(struct device *device,struct ib_device_modify desc = {};int ret; +if (count >IB_DEVICE_NODE_DESC_MAX ) +return -EINVAL ; +if (!dev->ops.modify_device)return -EOPNOTSUPP ;
Quoted 8 lines
drivers/infiniband/core/sysfs.c static ssize_t node_desc_store(struct device *device, · line 1274
Quoted 2 lines
drivers/infiniband/core/sysfs.c +1
-1-memcpy (desc.node_desc, buf,min_t (int, count,IB_DEVICE_NODE_DESC_MAX )); +memcpy (desc.node_desc, buf, count);I think this should just be written as
if (
strscpy(desc.node_desc, buf, sizeof(desc.node_desc))==-E2BIG)return -EINVAL;
OK, I'll send a V2 soon.
Quoted 1 line
Jason