Skip to contentSkip to conversation

RDMA/rxe: fix the parent sysfs read when the interface has 15 chars

PATCH Applied Yi Zhang 3 participants 3 messages Aug 20, 2020 – Aug 24, 2020

Subsystems (2)
lore
Share & tools
lore

Yi Zhang

author
#0 lore raw

PATCH v2 1/1 RDMA/rxe: fix the parent sysfs read when the interface has 15 chars

parent sysfs reads will yield '\0' bytes when the interface name has 15 chars, and there will no "\n" output.

reproducer:
Create one interface with 15 chars
[root@test ~]# ip a s enp0s29u1u7u3c2
2: enp0s29u1u7u3c2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UNKNOWN group default qlen 1000

    link/ether 02:21:28:57:47:17 brd ff:ff:ff:ff:ff:ff
    inet6 fe80::ac41:338f:5bcd:c222/64 scope link noprefixroute
       valid_lft forever preferred_lft forever

[root@test ~]# modprobe rdma_rxe
[root@test ~]# echo enp0s29u1u7u3c2 > /sys/module/rdma_rxe/parameters/add [root@test ~]# cat /sys/class/infiniband/rxe0/parent enp0s29u1u7u3c2[root@test ~]#
[root@test ~]# f="/sys/class/infiniband/rxe0/parent" [root@test ~]# echo "$(<"$f")"
-bash: warning: command substitution: ignored null byte in input enp0s29u1u7u3c2

---
 drivers/infiniband/sw/rxe/rxe_verbs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/infiniband/sw/rxe/rxe_verbs.c +1 -1
index bb61e534e468..756980f79951 100644
@@ -1056,7 +1056,7 @@ static ssize_t parent_show(struct device *device,
 	struct rxe_dev *rxe =
 		rdma_device_to_drv_device(device, struct rxe_dev, ib_dev);
 
-	return snprintf(buf, 16, "%s\n", rxe_parent_name(rxe, 1));
+	return scnprintf(buf, PAGE_SIZE, "%s\n", rxe_parent_name(rxe, 1));
 }
 
 static DEVICE_ATTR_RO(parent);
Signature · 1 line
2.21.0
Reviewed-by on v2 1/1
#1 lore raw
Quoted 30 lines · Yi Zhang

parent sysfs reads will yield '\0' bytes when the interface name has 15 chars, and there will no "\n" output.

reproducer:
Create one interface with 15 chars
[root@test ~]# ip a s enp0s29u1u7u3c2
2: enp0s29u1u7u3c2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UNKNOWN group default qlen 1000

     link/ether 02:21:28:57:47:17 brd ff:ff:ff:ff:ff:ff
     inet6 fe80::ac41:338f:5bcd:c222/64 scope link noprefixroute
        valid_lft forever preferred_lft forever

[root@test ~]# modprobe rdma_rxe
[root@test ~]# echo enp0s29u1u7u3c2 > /sys/module/rdma_rxe/parameters/add [root@test ~]# cat /sys/class/infiniband/rxe0/parent enp0s29u1u7u3c2[root@test ~]#
[root@test ~]# f="/sys/class/infiniband/rxe0/parent" [root@test ~]# echo "$(<"$f")"
-bash: warning: command substitution: ignored null byte in input enp0s29u1u7u3c2

---
  drivers/infiniband/sw/rxe/rxe_verbs.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/infiniband/sw/rxe/rxe_verbs.c +0 -0
index bb61e534e468..756980f79951 100644

drivers/infiniband/sw/rxe/rxe_verbs.c static ssize_t parent_show(struct device *device, · line 1062

Quoted 8 lines
drivers/infiniband/sw/rxe/rxe_verbs.c +1 -1
@@ -1056,7 +1056,7 @@ static ssize_t parent_show(struct device *device,
  	struct rxe_dev *rxe =
  		rdma_device_to_drv_device(device, struct rxe_dev, ib_dev);
 
-	return snprintf(buf, 16, "%s\n", rxe_parent_name(rxe, 1));
+	return scnprintf(buf, PAGE_SIZE, "%s\n", rxe_parent_name(rxe, 1));
  }
 
  static DEVICE_ATTR_RO(parent);

Please add 'Cc: stable' to this patch.

Anyway:

maintainer Applied
#2 lore raw
In reply to Yi Zhang
Quoted 19 lines · Yi Zhang

parent sysfs reads will yield '\0' bytes when the interface name has 15 chars, and there will no "\n" output.

reproducer:
Create one interface with 15 chars
[root@test ~]# ip a s enp0s29u1u7u3c2
2: enp0s29u1u7u3c2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UNKNOWN group default qlen 1000

    link/ether 02:21:28:57:47:17 brd ff:ff:ff:ff:ff:ff
    inet6 fe80::ac41:338f:5bcd:c222/64 scope link noprefixroute
       valid_lft forever preferred_lft forever

[root@test ~]# modprobe rdma_rxe
[root@test ~]# echo enp0s29u1u7u3c2 > /sys/module/rdma_rxe/parameters/add [root@test ~]# cat /sys/class/infiniband/rxe0/parent enp0s29u1u7u3c2[root@test ~]#
[root@test ~]# f="/sys/class/infiniband/rxe0/parent" [root@test ~]# echo "$(<"$f")"
-bash: warning: command substitution: ignored null byte in input enp0s29u1u7u3c2

Quoted 6 lines
---
 drivers/infiniband/sw/rxe/rxe_verbs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Applied to for-rc with a Fixes and cc stable line

Thanks,
Jason