* [PATCH] RDMA/uverbs: check for allocation failure in uapi_add_elm()
@ 2019-05-30 8:20 Dan Carpenter
2019-05-30 18:47 ` Jason Gunthorpe
0 siblings, 1 reply; 2+ messages in thread
From: Dan Carpenter @ 2019-05-30 8:20 UTC (permalink / raw)
To: kernel-janitors
If the kzalloc() fails then we should return ERR_PTR(-ENOMEM). In the
current code it's possible that the kzalloc() fails and the
radix_tree_insert() inserts the NULL pointer successfully and we return
the NULL "elm" pointer to the caller. That results in a NULL pointer
dereference.
Fixes: 9ed3e5f44772 ("IB/uverbs: Build the specs into a radix tree at runtime")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
drivers/infiniband/core/uverbs_uapi.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/infiniband/core/uverbs_uapi.c b/drivers/infiniband/core/uverbs_uapi.c
index 7a987acf0c0b..ccc4be0a6566 100644
--- a/drivers/infiniband/core/uverbs_uapi.c
+++ b/drivers/infiniband/core/uverbs_uapi.c
@@ -22,6 +22,8 @@ static void *uapi_add_elm(struct uverbs_api *uapi, u32 key, size_t alloc_size)
return ERR_PTR(-EOVERFLOW);
elm = kzalloc(alloc_size, GFP_KERNEL);
+ if (!elm)
+ return ERR_PTR(-ENOMEM);
rc = radix_tree_insert(&uapi->radix, key, elm);
if (rc) {
kfree(elm);
--
2.20.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] RDMA/uverbs: check for allocation failure in uapi_add_elm()
2019-05-30 8:20 [PATCH] RDMA/uverbs: check for allocation failure in uapi_add_elm() Dan Carpenter
@ 2019-05-30 18:47 ` Jason Gunthorpe
0 siblings, 0 replies; 2+ messages in thread
From: Jason Gunthorpe @ 2019-05-30 18:47 UTC (permalink / raw)
To: kernel-janitors
On Thu, May 30, 2019 at 11:20:24AM +0300, Dan Carpenter wrote:
> If the kzalloc() fails then we should return ERR_PTR(-ENOMEM). In the
> current code it's possible that the kzalloc() fails and the
> radix_tree_insert() inserts the NULL pointer successfully and we return
> the NULL "elm" pointer to the caller. That results in a NULL pointer
> dereference.
>
> Fixes: 9ed3e5f44772 ("IB/uverbs: Build the specs into a radix tree at runtime")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> ---
> drivers/infiniband/core/uverbs_uapi.c | 2 ++
> 1 file changed, 2 insertions(+)
Applied to for-next, thanks
Jason
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2019-05-30 18:47 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-05-30 8:20 [PATCH] RDMA/uverbs: check for allocation failure in uapi_add_elm() Dan Carpenter
2019-05-30 18:47 ` Jason Gunthorpe
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).