linux-rdma.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] RDMA/rxe: Fix possible NULL pointer dereference
@ 2020-10-12 16:52 Alex Dewar
       [not found] ` <DM6PR12MB3516EC1E0F28EB8F9B970F24D5050@DM6PR12MB3516.namprd12.prod.outlook.com>
  2020-10-16 17:04 ` Jason Gunthorpe
  0 siblings, 2 replies; 3+ messages in thread
From: Alex Dewar @ 2020-10-12 16:52 UTC (permalink / raw)
  Cc: Alex Dewar, Zhu Yanjun, Doug Ledford, Jason Gunthorpe,
	Bob Pearson, linux-rdma, linux-kernel

skb_clone() is called without checking if the returned pointer is NULL
before it is dereferenced. Fix by adding an additional error check.

Fixes: e7ec96fc7932 ("RDMA/rxe: Fix skb lifetime in rxe_rcv_mcast_pkt()")
Addresses-Coverity-ID: 1497804: Null pointer dereferences (NULL_RETURNS)
Signed-off-by: Alex Dewar <alex.dewar90@gmail.com>
---
 drivers/infiniband/sw/rxe/rxe_recv.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/drivers/infiniband/sw/rxe/rxe_recv.c b/drivers/infiniband/sw/rxe/rxe_recv.c
index 11f3daf20768..a65936e12f89 100644
--- a/drivers/infiniband/sw/rxe/rxe_recv.c
+++ b/drivers/infiniband/sw/rxe/rxe_recv.c
@@ -266,10 +266,13 @@ static void rxe_rcv_mcast_pkt(struct rxe_dev *rxe, struct sk_buff *skb)
 		/* for all but the last qp create a new clone of the
 		 * skb and pass to the qp.
 		 */
-		if (mce->qp_list.next != &mcg->qp_list)
+		if (mce->qp_list.next != &mcg->qp_list) {
 			per_qp_skb = skb_clone(skb, GFP_ATOMIC);
-		else
+			if (!per_qp_skb)
+				goto err2;
+		} else {
 			per_qp_skb = skb;
+		}
 
 		per_qp_pkt = SKB_TO_PKT(per_qp_skb);
 		per_qp_pkt->qp = qp;
@@ -283,6 +286,10 @@ static void rxe_rcv_mcast_pkt(struct rxe_dev *rxe, struct sk_buff *skb)
 
 	return;
 
+err2:
+	spin_unlock_bh(&mcg->mcg_lock);
+	rxe_drop_ref(mcg);	/* drop ref from rxe_pool_get_key. */
+
 err1:
 	kfree_skb(skb);
 }
-- 
2.28.0


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

* Re: FW: [PATCH] RDMA/rxe: Fix possible NULL pointer dereference
       [not found] ` <DM6PR12MB3516EC1E0F28EB8F9B970F24D5050@DM6PR12MB3516.namprd12.prod.outlook.com>
@ 2020-10-14  0:37   ` Zhu Yanjun
  0 siblings, 0 replies; 3+ messages in thread
From: Zhu Yanjun @ 2020-10-14  0:37 UTC (permalink / raw)
  To: Yanjun Zhu, Alex Dewar, Doug Ledford, Jason Gunthorpe,
	Bob Pearson, linux-rdma, LKML

On Wed, Oct 14, 2020 at 8:34 AM Yanjun Zhu <yanjunz@nvidia.com> wrote:
>
>
>
> -----Original Message-----
> From: Alex Dewar <alex.dewar90@gmail.com>
> Sent: Tuesday, October 13, 2020 12:53 AM
> Cc: Alex Dewar <alex.dewar90@gmail.com>; Yanjun Zhu <yanjunz@nvidia.com>; Doug Ledford <dledford@redhat.com>; Jason Gunthorpe <jgg@ziepe.ca>; Bob Pearson <rpearsonhpe@gmail.com>; linux-rdma@vger.kernel.org; linux-kernel@vger.kernel.org
> Subject: [PATCH] RDMA/rxe: Fix possible NULL pointer dereference
>
> skb_clone() is called without checking if the returned pointer is NULL before it is dereferenced. Fix by adding an additional error check.
>
> Fixes: e7ec96fc7932 ("RDMA/rxe: Fix skb lifetime in rxe_rcv_mcast_pkt()")
> Addresses-Coverity-ID: 1497804: Null pointer dereferences (NULL_RETURNS)
> Signed-off-by: Alex Dewar <alex.dewar90@gmail.com>

Thanks a lot.

Zhu Yanjun
> ---
>  drivers/infiniband/sw/rxe/rxe_recv.c | 11 +++++++++--
>  1 file changed, 9 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/infiniband/sw/rxe/rxe_recv.c b/drivers/infiniband/sw/rxe/rxe_recv.c
> index 11f3daf20768..a65936e12f89 100644
> --- a/drivers/infiniband/sw/rxe/rxe_recv.c
> +++ b/drivers/infiniband/sw/rxe/rxe_recv.c
> @@ -266,10 +266,13 @@ static void rxe_rcv_mcast_pkt(struct rxe_dev *rxe, struct sk_buff *skb)
>                 /* for all but the last qp create a new clone of the
>                  * skb and pass to the qp.
>                  */
> -               if (mce->qp_list.next != &mcg->qp_list)
> +               if (mce->qp_list.next != &mcg->qp_list) {
>                         per_qp_skb = skb_clone(skb, GFP_ATOMIC);
> -               else
> +                       if (!per_qp_skb)
> +                               goto err2;
> +               } else {
>                         per_qp_skb = skb;
> +               }
>
>                 per_qp_pkt = SKB_TO_PKT(per_qp_skb);
>                 per_qp_pkt->qp = qp;
> @@ -283,6 +286,10 @@ static void rxe_rcv_mcast_pkt(struct rxe_dev *rxe, struct sk_buff *skb)
>
>         return;
>
> +err2:
> +       spin_unlock_bh(&mcg->mcg_lock);
> +       rxe_drop_ref(mcg);      /* drop ref from rxe_pool_get_key. */
> +
>  err1:
>         kfree_skb(skb);
>  }
> --
> 2.28.0
>

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

* Re: [PATCH] RDMA/rxe: Fix possible NULL pointer dereference
  2020-10-12 16:52 [PATCH] RDMA/rxe: Fix possible NULL pointer dereference Alex Dewar
       [not found] ` <DM6PR12MB3516EC1E0F28EB8F9B970F24D5050@DM6PR12MB3516.namprd12.prod.outlook.com>
@ 2020-10-16 17:04 ` Jason Gunthorpe
  1 sibling, 0 replies; 3+ messages in thread
From: Jason Gunthorpe @ 2020-10-16 17:04 UTC (permalink / raw)
  To: Alex Dewar
  Cc: Zhu Yanjun, Doug Ledford, Bob Pearson, linux-rdma, linux-kernel

On Mon, Oct 12, 2020 at 05:52:30PM +0100, Alex Dewar wrote:
> skb_clone() is called without checking if the returned pointer is NULL
> before it is dereferenced. Fix by adding an additional error check.
> 
> Fixes: e7ec96fc7932 ("RDMA/rxe: Fix skb lifetime in rxe_rcv_mcast_pkt()")
> Addresses-Coverity-ID: 1497804: Null pointer dereferences (NULL_RETURNS)
> Signed-off-by: Alex Dewar <alex.dewar90@gmail.com>
> ---
>  drivers/infiniband/sw/rxe/rxe_recv.c | 11 +++++++++--
>  1 file changed, 9 insertions(+), 2 deletions(-)

I took Bob's version of this since it is a little bit simpler

Thanks,
Jason

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

end of thread, other threads:[~2020-10-16 17:04 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-12 16:52 [PATCH] RDMA/rxe: Fix possible NULL pointer dereference Alex Dewar
     [not found] ` <DM6PR12MB3516EC1E0F28EB8F9B970F24D5050@DM6PR12MB3516.namprd12.prod.outlook.com>
2020-10-14  0:37   ` FW: " Zhu Yanjun
2020-10-16 17:04 ` 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).