* [PATCH] RDMA/addr: potential uninitialized variable in ib_nl_process_good_ip_rsep()
@ 2021-04-02 11:47 Dan Carpenter
2021-04-04 10:33 ` Leon Romanovsky
0 siblings, 1 reply; 6+ messages in thread
From: Dan Carpenter @ 2021-04-02 11:47 UTC (permalink / raw)
To: Doug Ledford
Cc: Jason Gunthorpe, Leon Romanovsky, Mark Bloch, linux-rdma,
linux-kernel, kernel-janitors
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")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
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(-)
diff --git a/drivers/infiniband/core/addr.c b/drivers/infiniband/core/addr.c
index 0abce004a959..a037ba4424bf 100644
--- a/drivers/infiniband/core/addr.c
+++ b/drivers/infiniband/core/addr.c
@@ -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;
--
2.30.2
^ permalink raw reply related [flat|nested] 6+ messages in thread* Re: [PATCH] RDMA/addr: potential uninitialized variable in ib_nl_process_good_ip_rsep() 2021-04-02 11:47 [PATCH] RDMA/addr: potential uninitialized variable in ib_nl_process_good_ip_rsep() Dan Carpenter @ 2021-04-04 10:33 ` Leon Romanovsky 2021-04-04 13:13 ` Mark Bloch 0 siblings, 1 reply; 6+ messages in thread From: Leon Romanovsky @ 2021-04-04 10:33 UTC (permalink / raw) To: Dan Carpenter Cc: Doug Ledford, Jason Gunthorpe, Mark Bloch, linux-rdma, linux-kernel, kernel-janitors On Fri, Apr 02, 2021 at 02:47:23PM +0300, Dan Carpenter wrote: > 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") > Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com> > --- > 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 ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] RDMA/addr: potential uninitialized variable in ib_nl_process_good_ip_rsep() 2021-04-04 10:33 ` Leon Romanovsky @ 2021-04-04 13:13 ` Mark Bloch 2021-04-04 13:15 ` Leon Romanovsky 2021-04-05 5:41 ` Dan Carpenter 0 siblings, 2 replies; 6+ messages in thread From: Mark Bloch @ 2021-04-04 13:13 UTC (permalink / raw) To: Leon Romanovsky, Dan Carpenter Cc: Doug Ledford, Jason Gunthorpe, Mark Bloch, linux-rdma, linux-kernel, kernel-janitors On 4/4/21 1:33 PM, Leon Romanovsky wrote: > On Fri, Apr 02, 2021 at 02:47:23PM +0300, Dan Carpenter wrote: >> 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") >> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com> >> --- >> 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. What about just updating the policy? The bellow diff should work I believe. diff --git a/drivers/infiniband/core/addr.c b/drivers/infiniband/core/addr.c index 0abce004a959..65e3e7df8a4b 100644 --- a/drivers/infiniband/core/addr.c +++ b/drivers/infiniband/core/addr.c @@ -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) > > Thanks > Mark ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] RDMA/addr: potential uninitialized variable in ib_nl_process_good_ip_rsep() 2021-04-04 13:13 ` Mark Bloch @ 2021-04-04 13:15 ` Leon Romanovsky 2021-04-05 5:41 ` Dan Carpenter 1 sibling, 0 replies; 6+ messages in thread From: Leon Romanovsky @ 2021-04-04 13:15 UTC (permalink / raw) To: Mark Bloch Cc: Dan Carpenter, Doug Ledford, Jason Gunthorpe, Mark Bloch, linux-rdma, linux-kernel, kernel-janitors On Sun, Apr 04, 2021 at 04:13:17PM +0300, Mark Bloch wrote: > On 4/4/21 1:33 PM, Leon Romanovsky wrote: > > On Fri, Apr 02, 2021 at 02:47:23PM +0300, Dan Carpenter wrote: > >> 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") > >> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com> > >> --- > >> 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. > > 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. > > diff --git a/drivers/infiniband/core/addr.c b/drivers/infiniband/core/addr.c > index 0abce004a959..65e3e7df8a4b 100644 > --- a/drivers/infiniband/core/addr.c > +++ b/drivers/infiniband/core/addr.c > @@ -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) > > > > > Thanks > > > > Mark ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] RDMA/addr: potential uninitialized variable in ib_nl_process_good_ip_rsep() 2021-04-04 13:13 ` Mark Bloch 2021-04-04 13:15 ` Leon Romanovsky @ 2021-04-05 5:41 ` Dan Carpenter 2021-04-05 5:52 ` Leon Romanovsky 1 sibling, 1 reply; 6+ messages in thread From: Dan Carpenter @ 2021-04-05 5:41 UTC (permalink / raw) To: Mark Bloch Cc: Leon Romanovsky, Doug Ledford, Jason Gunthorpe, Mark Bloch, linux-rdma, linux-kernel, kernel-janitors Could you send that and give me a reported-by? I'm going AFK for a week. regards, dan carpenter ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] RDMA/addr: potential uninitialized variable in ib_nl_process_good_ip_rsep() 2021-04-05 5:41 ` Dan Carpenter @ 2021-04-05 5:52 ` Leon Romanovsky 0 siblings, 0 replies; 6+ messages in thread From: Leon Romanovsky @ 2021-04-05 5:52 UTC (permalink / raw) To: Dan Carpenter Cc: Mark Bloch, Doug Ledford, Jason Gunthorpe, Mark Bloch, linux-rdma, linux-kernel, kernel-janitors On Mon, Apr 05, 2021 at 08:41:41AM +0300, Dan Carpenter wrote: > 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. > > regards, > dan carpenter > ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2021-04-05 5:52 UTC | newest] Thread overview: 6+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2021-04-02 11:47 [PATCH] RDMA/addr: potential uninitialized variable in ib_nl_process_good_ip_rsep() Dan Carpenter 2021-04-04 10:33 ` Leon Romanovsky 2021-04-04 13:13 ` Mark Bloch 2021-04-04 13:15 ` Leon Romanovsky 2021-04-05 5:41 ` Dan Carpenter 2021-04-05 5:52 ` Leon Romanovsky
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox