* [PATCH] RDMA/cxgb4: Fix potential null-ptr-deref in pass_establish()
@ 2023-02-02 14:52 Nikita Zhandarovich
2023-02-02 15:58 ` Jason Gunthorpe
0 siblings, 1 reply; 5+ messages in thread
From: Nikita Zhandarovich @ 2023-02-02 14:52 UTC (permalink / raw)
To: Potnuri Bharat Teja
Cc: Nikita Zhandarovich, Jason Gunthorpe, Leon Romanovsky,
linux-rdma, linux-kernel, lvc-project
If get_ep_from_tid() fails to lookup non-NULL value for ep, ep is
dereferenced later regardless of whether it is empty.
This patch adds a simple sanity check to fix the issue.
Found by Linux Verification Center (linuxtesting.org) with SVACE.
Fixes: 944661dd97f4 ("RDMA/iw_cxgb4: atomically lookup ep and get a reference")
Signed-off-by: Nikita Zhandarovich <n.zhandarovich@fintech.ru>
---
drivers/infiniband/hw/cxgb4/cm.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/drivers/infiniband/hw/cxgb4/cm.c b/drivers/infiniband/hw/cxgb4/cm.c
index c16017f6e8db..f4a02c2ec02f 100644
--- a/drivers/infiniband/hw/cxgb4/cm.c
+++ b/drivers/infiniband/hw/cxgb4/cm.c
@@ -2683,6 +2683,10 @@ static int pass_establish(struct c4iw_dev *dev, struct sk_buff *skb)
u16 tcp_opt = ntohs(req->tcp_opt);
ep = get_ep_from_tid(dev, tid);
+ if (!ep) {
+ pr_warn("%s tid %d lookup failure!\n", __func__, tid);
+ return 0;
+ }
pr_debug("ep %p tid %u\n", ep, ep->hwtid);
ep->snd_seq = be32_to_cpu(req->snd_isn);
ep->rcv_seq = be32_to_cpu(req->rcv_isn);
--
2.25.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] RDMA/cxgb4: Fix potential null-ptr-deref in pass_establish()
2023-02-02 14:52 [PATCH] RDMA/cxgb4: Fix potential null-ptr-deref in pass_establish() Nikita Zhandarovich
@ 2023-02-02 15:58 ` Jason Gunthorpe
2023-02-02 18:48 ` [PATCH v2] " Nikita Zhandarovich
0 siblings, 1 reply; 5+ messages in thread
From: Jason Gunthorpe @ 2023-02-02 15:58 UTC (permalink / raw)
To: Nikita Zhandarovich
Cc: Potnuri Bharat Teja, Leon Romanovsky, linux-rdma, linux-kernel,
lvc-project
On Thu, Feb 02, 2023 at 06:52:22AM -0800, Nikita Zhandarovich wrote:
> If get_ep_from_tid() fails to lookup non-NULL value for ep, ep is
> dereferenced later regardless of whether it is empty.
> This patch adds a simple sanity check to fix the issue.
>
> Found by Linux Verification Center (linuxtesting.org) with SVACE.
>
> Fixes: 944661dd97f4 ("RDMA/iw_cxgb4: atomically lookup ep and get a reference")
> Signed-off-by: Nikita Zhandarovich <n.zhandarovich@fintech.ru>
> ---
> drivers/infiniband/hw/cxgb4/cm.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/drivers/infiniband/hw/cxgb4/cm.c b/drivers/infiniband/hw/cxgb4/cm.c
> index c16017f6e8db..f4a02c2ec02f 100644
> --- a/drivers/infiniband/hw/cxgb4/cm.c
> +++ b/drivers/infiniband/hw/cxgb4/cm.c
> @@ -2683,6 +2683,10 @@ static int pass_establish(struct c4iw_dev *dev, struct sk_buff *skb)
> u16 tcp_opt = ntohs(req->tcp_opt);
>
> ep = get_ep_from_tid(dev, tid);
> + if (!ep) {
> + pr_warn("%s tid %d lookup failure!\n", __func__, tid);
> + return 0;
> + }
don't print please
Jason
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v2] RDMA/cxgb4: Fix potential null-ptr-deref in pass_establish()
2023-02-02 15:58 ` Jason Gunthorpe
@ 2023-02-02 18:48 ` Nikita Zhandarovich
2023-02-06 13:55 ` Leon Romanovsky
2023-02-06 13:58 ` Leon Romanovsky
0 siblings, 2 replies; 5+ messages in thread
From: Nikita Zhandarovich @ 2023-02-02 18:48 UTC (permalink / raw)
To: Potnuri Bharat Teja
Cc: Nikita Zhandarovich, Jason Gunthorpe, Leon Romanovsky,
linux-rdma, linux-kernel, lvc-project
If get_ep_from_tid() fails to lookup non-NULL value for ep, ep is
dereferenced later regardless of whether it is empty.
This patch adds a simple sanity check to fix the issue.
Found by Linux Verification Center (linuxtesting.org) with SVACE.
Fixes: 944661dd97f4 ("RDMA/iw_cxgb4: atomically lookup ep and get a reference")
Signed-off-by: Nikita Zhandarovich <n.zhandarovich@fintech.ru>
---
v2: do not use pr_warn() when get_ep_from_tid() returns NULL as
Jason Gunthorpe <jgg@ziepe.ca> suggested.
drivers/infiniband/hw/cxgb4/cm.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/infiniband/hw/cxgb4/cm.c b/drivers/infiniband/hw/cxgb4/cm.c
index 499a425a3379..f5f4579f037c 100644
--- a/drivers/infiniband/hw/cxgb4/cm.c
+++ b/drivers/infiniband/hw/cxgb4/cm.c
@@ -2676,6 +2676,8 @@ static int pass_establish(struct c4iw_dev *dev, struct sk_buff *skb)
u16 tcp_opt = ntohs(req->tcp_opt);
ep = get_ep_from_tid(dev, tid);
+ if (!ep)
+ return 0;
pr_debug("ep %p tid %u\n", ep, ep->hwtid);
ep->snd_seq = be32_to_cpu(req->snd_isn);
ep->rcv_seq = be32_to_cpu(req->rcv_isn);
--
2.25.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v2] RDMA/cxgb4: Fix potential null-ptr-deref in pass_establish()
2023-02-02 18:48 ` [PATCH v2] " Nikita Zhandarovich
@ 2023-02-06 13:55 ` Leon Romanovsky
2023-02-06 13:58 ` Leon Romanovsky
1 sibling, 0 replies; 5+ messages in thread
From: Leon Romanovsky @ 2023-02-06 13:55 UTC (permalink / raw)
To: Nikita Zhandarovich
Cc: Potnuri Bharat Teja, Jason Gunthorpe, linux-rdma, linux-kernel,
lvc-project
On Thu, Feb 02, 2023 at 10:48:50AM -0800, Nikita Zhandarovich wrote:
> If get_ep_from_tid() fails to lookup non-NULL value for ep, ep is
> dereferenced later regardless of whether it is empty.
> This patch adds a simple sanity check to fix the issue.
>
> Found by Linux Verification Center (linuxtesting.org) with SVACE.
>
> Fixes: 944661dd97f4 ("RDMA/iw_cxgb4: atomically lookup ep and get a reference")
> Signed-off-by: Nikita Zhandarovich <n.zhandarovich@fintech.ru>
> ---
> v2: do not use pr_warn() when get_ep_from_tid() returns NULL as
> Jason Gunthorpe <jgg@ziepe.ca> suggested.
>
> drivers/infiniband/hw/cxgb4/cm.c | 2 ++
> 1 file changed, 2 insertions(+)
I applied, but please next time.
1. Don't send patches as reply-to. It messes whole patch flow.
2. Use target in subject line, e.g. [PATCH rdma-next] or [PATCH rdma-rc]
Thanks
>
> diff --git a/drivers/infiniband/hw/cxgb4/cm.c b/drivers/infiniband/hw/cxgb4/cm.c
> index 499a425a3379..f5f4579f037c 100644
> --- a/drivers/infiniband/hw/cxgb4/cm.c
> +++ b/drivers/infiniband/hw/cxgb4/cm.c
> @@ -2676,6 +2676,8 @@ static int pass_establish(struct c4iw_dev *dev, struct sk_buff *skb)
> u16 tcp_opt = ntohs(req->tcp_opt);
>
> ep = get_ep_from_tid(dev, tid);
> + if (!ep)
> + return 0;
> pr_debug("ep %p tid %u\n", ep, ep->hwtid);
> ep->snd_seq = be32_to_cpu(req->snd_isn);
> ep->rcv_seq = be32_to_cpu(req->rcv_isn);
> --
> 2.25.1
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2] RDMA/cxgb4: Fix potential null-ptr-deref in pass_establish()
2023-02-02 18:48 ` [PATCH v2] " Nikita Zhandarovich
2023-02-06 13:55 ` Leon Romanovsky
@ 2023-02-06 13:58 ` Leon Romanovsky
1 sibling, 0 replies; 5+ messages in thread
From: Leon Romanovsky @ 2023-02-06 13:58 UTC (permalink / raw)
To: Potnuri Bharat Teja, Nikita Zhandarovich
Cc: Jason Gunthorpe, linux-rdma, linux-kernel, lvc-project
On Thu, 02 Feb 2023 10:48:50 -0800, Nikita Zhandarovich wrote:
> If get_ep_from_tid() fails to lookup non-NULL value for ep, ep is
> dereferenced later regardless of whether it is empty.
> This patch adds a simple sanity check to fix the issue.
>
> Found by Linux Verification Center (linuxtesting.org) with SVACE.
>
>
> [...]
Applied, thanks!
[1/1] RDMA/cxgb4: Fix potential null-ptr-deref in pass_establish()
https://git.kernel.org/rdma/rdma/c/283861a4c52c1e
Best regards,
--
Leon Romanovsky <leon@kernel.org>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2023-02-06 14:00 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-02 14:52 [PATCH] RDMA/cxgb4: Fix potential null-ptr-deref in pass_establish() Nikita Zhandarovich
2023-02-02 15:58 ` Jason Gunthorpe
2023-02-02 18:48 ` [PATCH v2] " Nikita Zhandarovich
2023-02-06 13:55 ` Leon Romanovsky
2023-02-06 13:58 ` Leon Romanovsky
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).