Skip to contentSkip to conversation

RDMA/addr: potential uninitialized variable in ib_nl_process_good_ip_rsep()

PATCH In review Dan Carpenter 3 participants 6 messages Apr 2, 2021 – Apr 5, 2021

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

PATCH 1/1 RDMA/addr: potential uninitialized variable in ib_nl_process_good_ip_rsep()

The nla_len() is less than or equal to 16. If it's less than 16 then end of the "gid" buffer is uninitialized.

Fixes ae43f8286730 ("IB/core: Add IP to GID netlink offload")

---
I just spotted this in review. I think it's a bug but I'm not 100%.

 drivers/infiniband/core/addr.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/infiniband/core/addr.c +1 -1
index 0abce004a959..a037ba4424bf 100644
@@ -98,7 +98,7 @@ static inline bool ib_nl_is_good_ip_resp(const struct nlmsghdr *nlh)
 static void ib_nl_process_good_ip_rsep(const struct nlmsghdr *nlh)
 {
 	const struct nlattr *head, *curr;
-	union ib_gid gid;
+	union ib_gid gid = {};
 	struct addr_req *req;
 	int len, rem;
 	int found = 0;
Signature · 1 line
2.30.2
#1 lore raw
Quoted 7 lines · Dan Carpenter

The nla_len() is less than or equal to 16. If it's less than 16 then end of the "gid" buffer is uninitialized.

Fixes ae43f8286730 ("IB/core: Add IP to GID netlink offload")

---
I just spotted this in review. I think it's a bug but I'm not 100%.

I tend to agree with you, that it is a bug.

LS_NLA_TYPE_DGID is declared as NLA_BINARY which doesn't complain if data is less than declared ".len". However, the fix needs to be in ib_nl_is_good_ip_resp(), it shouldn't return "true" if length not equal to 16.

Thanks

#2 lore raw
Quoted 9 lines · Leon Romanovsky
Quoted 7 lines · Dan Carpenter

The nla_len() is less than or equal to 16. If it's less than 16 then end of the "gid" buffer is uninitialized.

Fixes ae43f8286730 ("IB/core: Add IP to GID netlink offload")

---
I just spotted this in review. I think it's a bug but I'm not 100%.

Quoted 6 lines

I tend to agree with you, that it is a bug.

LS_NLA_TYPE_DGID is declared as NLA_BINARY which doesn't complain if data is less than declared ".len". However, the fix needs to be in ib_nl_is_good_ip_resp(), it shouldn't return "true" if length not equal to 16.

What about just updating the policy? The bellow diff should work I believe.

drivers/infiniband/core/addr.c +3 -1
index 0abce004a959..65e3e7df8a4b 100644
@@ -76,7 +76,9 @@ static struct workqueue_struct *addr_wq;
 
 static const struct nla_policy ib_nl_addr_policy[LS_NLA_TYPE_MAX] = {
        [LS_NLA_TYPE_DGID] = {.type = NLA_BINARY,
-               .len = sizeof(struct rdma_nla_ls_gid)},
+               .len = sizeof(struct rdma_nla_ls_gid),
+               .validation_type = NLA_VALIDATE_MIN,
+               .min = sizeof(struct rdma_nla_ls_gid)},
 };
 
 static inline bool ib_nl_is_good_ip_resp(const struct nlmsghdr *nlh)
Quoted 3 lines

Thanks

Mark

#3 lore raw
Quoted 10 lines · Mark Bloch
Quoted 9 lines · Leon Romanovsky
Quoted 7 lines · Dan Carpenter

The nla_len() is less than or equal to 16. If it's less than 16 then end of the "gid" buffer is uninitialized.

Fixes ae43f8286730 ("IB/core: Add IP to GID netlink offload")

---
I just spotted this in review. I think it's a bug but I'm not 100%.

Quoted 8 lines
Quoted 6 lines

I tend to agree with you, that it is a bug.

LS_NLA_TYPE_DGID is declared as NLA_BINARY which doesn't complain if data is less than declared ".len". However, the fix needs to be in ib_nl_is_good_ip_resp(), it shouldn't return "true" if length not equal to 16.

What about just updating the policy? The bellow diff should work I believe.

I didn't know about ".validation_type", but yes this change will be enough.

Quoted 22 lines
drivers/infiniband/core/addr.c +3 -1
index 0abce004a959..65e3e7df8a4b 100644
@@ -76,7 +76,9 @@ static struct workqueue_struct *addr_wq;
 
 static const struct nla_policy ib_nl_addr_policy[LS_NLA_TYPE_MAX] = {
        [LS_NLA_TYPE_DGID] = {.type = NLA_BINARY,
-               .len = sizeof(struct rdma_nla_ls_gid)},
+               .len = sizeof(struct rdma_nla_ls_gid),
+               .validation_type = NLA_VALIDATE_MIN,
+               .min = sizeof(struct rdma_nla_ls_gid)},
 };
 
 static inline bool ib_nl_is_good_ip_resp(const struct nlmsghdr *nlh)
Quoted 4 lines

Thanks

Mark

#5 lore raw
Quoted 2 lines · Dan Carpenter

Could you send that and give me a reported-by? I'm going AFK for a week.

Sure, we will handle it.

Thanks for the report.

Quoted 4 lines

regards,
dan carpenter