Skip to contentSkip to conversation

RDMA/core: Fix storing node description

PATCH Superseded Kamal Heib 2 participants 3 messages Jan 13, 2020 – Jan 14, 2020 InfiniBand

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Kamal Heib

author
#0 lore raw

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.

Fixes c5bcbbb9fe00 ("IB: Allow userspace to set node description")
---
 drivers/infiniband/core/sysfs.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/infiniband/core/sysfs.c +4 -1
index 087682e6969e..55f4d7c1fcc9 100644
@@ -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
#1 lore raw
Quoted 13 lines · Kamal Heib

Make sure to return -EINVAL when the supplied string is bigger then IB_DEVICE_NODE_DESC_MAX.

Fixes c5bcbbb9fe00 ("IB: Allow userspace to set node description")
 drivers/infiniband/core/sysfs.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/infiniband/core/sysfs.c +1 -0
index 087682e6969e..55f4d7c1fcc9 100644
+++ 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 -1
 	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);

I think this should just be written as

if (strscpy(desc.node_desc, buf, sizeof(desc.node_desc)) == -E2BIG)

    return -EINVAL;

Jason

author
#2 lore raw
Quoted 22 lines · Jason Gunthorpe
Quoted 21 lines · Kamal Heib

Make sure to return -EINVAL when the supplied string is bigger then IB_DEVICE_NODE_DESC_MAX.

Fixes c5bcbbb9fe00 ("IB: Allow userspace to set node description")
 drivers/infiniband/core/sysfs.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/infiniband/core/sysfs.c +4 -0
index 087682e6969e..55f4d7c1fcc9 100644
+++ 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