diff mbox series

RDMA/nldev: Fix NULL pointer dereferences issue in rdma_nl_notify_event

Message ID 20240926143402.70354-1-qianqiang.liu@163.com (mailing list archive)
State Superseded
Headers show
Series RDMA/nldev: Fix NULL pointer dereferences issue in rdma_nl_notify_event | expand

Commit Message

Qianqiang Liu Sept. 26, 2024, 2:34 p.m. UTC
nlmsg_put() may return a NULL pointer assigned to nlh, which will later
be dereferenced in nlmsg_end().

Signed-off-by: Qianqiang Liu <qianqiang.liu@163.com>
---
 drivers/infiniband/core/nldev.c | 2 ++
 1 file changed, 2 insertions(+)

Comments

Dan Carpenter Oct. 9, 2024, 2:30 p.m. UTC | #1
On Thu, Sep 26, 2024 at 10:34:03PM +0800, Qianqiang Liu wrote:
> nlmsg_put() may return a NULL pointer assigned to nlh, which will later
> be dereferenced in nlmsg_end().
> 
> Signed-off-by: Qianqiang Liu <qianqiang.liu@163.com>
> ---
>  drivers/infiniband/core/nldev.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/infiniband/core/nldev.c b/drivers/infiniband/core/nldev.c
> index 39f89a4b8649..7dc8e2ec62cc 100644
> --- a/drivers/infiniband/core/nldev.c
> +++ b/drivers/infiniband/core/nldev.c
> @@ -2816,6 +2816,8 @@ int rdma_nl_notify_event(struct ib_device *device, u32 port_num,
>  	nlh = nlmsg_put(skb, 0, 0,
>  			RDMA_NL_GET_TYPE(RDMA_NL_NLDEV, RDMA_NLDEV_CMD_MONITOR),
>  			0, 0);
> +	if (!nlh)
> +		goto err_free;

Need to set the error code before the goto.  "ret = -EMSGSIZE;"

regards,
dan carpenter
diff mbox series

Patch

diff --git a/drivers/infiniband/core/nldev.c b/drivers/infiniband/core/nldev.c
index 39f89a4b8649..7dc8e2ec62cc 100644
--- a/drivers/infiniband/core/nldev.c
+++ b/drivers/infiniband/core/nldev.c
@@ -2816,6 +2816,8 @@  int rdma_nl_notify_event(struct ib_device *device, u32 port_num,
 	nlh = nlmsg_put(skb, 0, 0,
 			RDMA_NL_GET_TYPE(RDMA_NL_NLDEV, RDMA_NLDEV_CMD_MONITOR),
 			0, 0);
+	if (!nlh)
+		goto err_free;
 
 	switch (type) {
 	case RDMA_REGISTER_EVENT: