linux-rdma.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] RDMA/uverbs: Check for null return of kmalloc_array
@ 2021-12-31  9:33 Jiasheng Jiang
  2022-01-03 11:56 ` Leon Romanovsky
  2022-01-05 18:24 ` Jason Gunthorpe
  0 siblings, 2 replies; 3+ messages in thread
From: Jiasheng Jiang @ 2021-12-31  9:33 UTC (permalink / raw)
  To: dledford, jgg; +Cc: linux-rdma, linux-kernel, Jiasheng Jiang

Because of the possible failure of the allocation, data might be NULL
pointer and will cause the dereference of the NULL pointer later.
Therefore, it might be better to check it and return -ENOMEM.

Fixes: 6884c6c4bd09 ("RDMA/verbs: Store the write/write_ex uapi entry points in the uverbs_api")
Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn>
---
 drivers/infiniband/core/uverbs_uapi.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/infiniband/core/uverbs_uapi.c b/drivers/infiniband/core/uverbs_uapi.c
index 62f5bcb712cf..1e71925613cc 100644
--- a/drivers/infiniband/core/uverbs_uapi.c
+++ b/drivers/infiniband/core/uverbs_uapi.c
@@ -447,6 +447,9 @@ static int uapi_finalize(struct uverbs_api *uapi)
 	uapi->num_write_ex = max_write_ex + 1;
 	data = kmalloc_array(uapi->num_write + uapi->num_write_ex,
 			     sizeof(*uapi->write_methods), GFP_KERNEL);
+	if (!data)
+		return -ENOMEM;
+
 	for (i = 0; i != uapi->num_write + uapi->num_write_ex; i++)
 		data[i] = &uapi->notsupp_method;
 	uapi->write_methods = data;
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] RDMA/uverbs: Check for null return of kmalloc_array
  2021-12-31  9:33 [PATCH] RDMA/uverbs: Check for null return of kmalloc_array Jiasheng Jiang
@ 2022-01-03 11:56 ` Leon Romanovsky
  2022-01-05 18:24 ` Jason Gunthorpe
  1 sibling, 0 replies; 3+ messages in thread
From: Leon Romanovsky @ 2022-01-03 11:56 UTC (permalink / raw)
  To: Jiasheng Jiang; +Cc: dledford, jgg, linux-rdma, linux-kernel

On Fri, Dec 31, 2021 at 05:33:15PM +0800, Jiasheng Jiang wrote:
> Because of the possible failure of the allocation, data might be NULL
> pointer and will cause the dereference of the NULL pointer later.
> Therefore, it might be better to check it and return -ENOMEM.
> 
> Fixes: 6884c6c4bd09 ("RDMA/verbs: Store the write/write_ex uapi entry points in the uverbs_api")
> Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn>
> ---
>  drivers/infiniband/core/uverbs_uapi.c | 3 +++
>  1 file changed, 3 insertions(+)
> 

Thanks,
Reviewed-by: Leon Romanovsky <leonro@nvidia.com>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] RDMA/uverbs: Check for null return of kmalloc_array
  2021-12-31  9:33 [PATCH] RDMA/uverbs: Check for null return of kmalloc_array Jiasheng Jiang
  2022-01-03 11:56 ` Leon Romanovsky
@ 2022-01-05 18:24 ` Jason Gunthorpe
  1 sibling, 0 replies; 3+ messages in thread
From: Jason Gunthorpe @ 2022-01-05 18:24 UTC (permalink / raw)
  To: Jiasheng Jiang; +Cc: dledford, linux-rdma, linux-kernel

On Fri, Dec 31, 2021 at 05:33:15PM +0800, Jiasheng Jiang wrote:
> Because of the possible failure of the allocation, data might be NULL
> pointer and will cause the dereference of the NULL pointer later.
> Therefore, it might be better to check it and return -ENOMEM.
> 
> Fixes: 6884c6c4bd09 ("RDMA/verbs: Store the write/write_ex uapi entry points in the uverbs_api")
> Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn>
> Reviewed-by: Leon Romanovsky <leonro@nvidia.com>
> ---
>  drivers/infiniband/core/uverbs_uapi.c | 3 +++
>  1 file changed, 3 insertions(+)

Applied to for-rc, thanks

Jason

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-01-05 18:24 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-31  9:33 [PATCH] RDMA/uverbs: Check for null return of kmalloc_array Jiasheng Jiang
2022-01-03 11:56 ` Leon Romanovsky
2022-01-05 18:24 ` 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).