Skip to contentSkip to conversation

RDMA/srp: Avoid reading uninitialized has_port on srp_parse_in() failure

PATCH Applied Serhat Kumral 4 participants 4 messages Oct 16 – Oct 18

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 RDMA/srp: Avoid reading uninitialized has_port on srp_parse_in() failure

srp_parse_in() returns -ENOMEM without initializing *has_port if kstrdup() fails. Only check has_port when srp_parse_in() succeeds.

Fixes bcef5b721568 ("RDMA/srp: Accept again source addresses that do not have a port number")

---
found by smatch:
- drivers/infiniband/ulp/srp/ib_srp.c:3502 srp_parse_options() error: uninitialized symbol 'has_port'.

 drivers/infiniband/ulp/srp/ib_srp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/infiniband/ulp/srp/ib_srp.c +1 -1
index 955f36efeebd..5811f02df980 100644
@@ -3499,7 +3499,7 @@ static int srp_parse_options(struct net *net, const char *buf,
 			}
 			ret = srp_parse_in(net, &target->rdma_cm.dst.ss, p,
 					   &has_port);
-			if (!has_port)
+			if (ret == 0 && !has_port)
 				ret = -EINVAL;
 			if (ret < 0) {
 				pr_warn("bad dest parameter '%s'\n", p);
Signature · 1 line
2.53.0
#1 lore raw
Sashiko has reviewed this patch and found no issues.
Quoted 5 lines

srp_parse_in() returns -ENOMEM without initializing *has_port if kstrdup() fails. Only check has_port when srp_parse_in() succeeds.

Fixes bcef5b721568 ("RDMA/srp: Accept again source addresses that do not have a port number")

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
maintainer Reviewed-by on v1 1/1
#2 lore raw
In reply to Serhat Kumral
Quoted 17 lines · Serhat Kumral

srp_parse_in() returns -ENOMEM without initializing *has_port if kstrdup() fails. Only check has_port when srp_parse_in() succeeds.

Fixes bcef5b721568 ("RDMA/srp: Accept again source addresses that do not have a port number")

---
found by smatch:
- drivers/infiniband/ulp/srp/ib_srp.c:3502 srp_parse_options() error: uninitialized symbol 'has_port'.

  drivers/infiniband/ulp/srp/ib_srp.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/infiniband/ulp/srp/ib_srp.c +0 -0
index 955f36efeebd..5811f02df980 100644

drivers/infiniband/ulp/srp/ib_srp.c static int srp_parse_options(struct net *net, const char *buf, · line 3505

Quoted 8 lines
drivers/infiniband/ulp/srp/ib_srp.c +1 -1
@@ -3499,7 +3499,7 @@ static int srp_parse_options(struct net *net, const char *buf,
  			}
  			ret = srp_parse_in(net, &target->rdma_cm.dst.ss, p,
  					   &has_port);
-			if (!has_port)
+			if (ret == 0 && !has_port)
  				ret = -EINVAL;
  			if (ret < 0) {
  				pr_warn("bad dest parameter '%s'\n", p);