* [PATCH] infiniband/i40iw: Fix a use after free in i40iw_cm_event_handler
@ 2021-03-11 3:14 Lv Yunlong
2021-03-11 18:21 ` Jason Gunthorpe
0 siblings, 1 reply; 5+ messages in thread
From: Lv Yunlong @ 2021-03-11 3:14 UTC (permalink / raw)
To: faisal.latif, shiraz.saleem, dledford, jgg
Cc: linux-rdma, linux-kernel, Lv Yunlong
In the case of I40IW_CM_EVENT_ABORTED, i40iw_event_connect_error()
could be called to free the event->cm_node. However, event->cm_node
will be used after and cause use after free. It needs to add flags
to inform that event->cm_node has been freed.
Signed-off-by: Lv Yunlong <lyl2019@mail.ustc.edu.cn>
---
drivers/infiniband/hw/i40iw/i40iw_cm.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/drivers/infiniband/hw/i40iw/i40iw_cm.c b/drivers/infiniband/hw/i40iw/i40iw_cm.c
index ac65c8237b2e..447b43c2d21f 100644
--- a/drivers/infiniband/hw/i40iw/i40iw_cm.c
+++ b/drivers/infiniband/hw/i40iw/i40iw_cm.c
@@ -4175,6 +4175,7 @@ static void i40iw_cm_event_handler(struct work_struct *work)
struct i40iw_cm_event,
event_work);
struct i40iw_cm_node *cm_node;
+ int flags = 0;
if (!event || !event->cm_node || !event->cm_node->cm_core)
return;
@@ -4211,6 +4212,7 @@ static void i40iw_cm_event_handler(struct work_struct *work)
(event->cm_node->state == I40IW_CM_STATE_OFFLOADED))
break;
i40iw_event_connect_error(event);
+ flags = 1;
break;
default:
i40iw_pr_err("event type = %d\n", event->type);
@@ -4218,7 +4220,8 @@ static void i40iw_cm_event_handler(struct work_struct *work)
}
event->cm_info.cm_id->rem_ref(event->cm_info.cm_id);
- i40iw_rem_ref_cm_node(event->cm_node);
+ if (!flags)
+ i40iw_rem_ref_cm_node(event->cm_node);
kfree(event);
}
--
2.25.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] infiniband/i40iw: Fix a use after free in i40iw_cm_event_handler
2021-03-11 3:14 [PATCH] infiniband/i40iw: Fix a use after free in i40iw_cm_event_handler Lv Yunlong
@ 2021-03-11 18:21 ` Jason Gunthorpe
2021-03-12 1:13 ` Saleem, Shiraz
0 siblings, 1 reply; 5+ messages in thread
From: Jason Gunthorpe @ 2021-03-11 18:21 UTC (permalink / raw)
To: Lv Yunlong, shiraz.saleem
Cc: faisal.latif, dledford, linux-rdma, linux-kernel
On Wed, Mar 10, 2021 at 07:14:14PM -0800, Lv Yunlong wrote:
> In the case of I40IW_CM_EVENT_ABORTED, i40iw_event_connect_error()
> could be called to free the event->cm_node. However, event->cm_node
> will be used after and cause use after free. It needs to add flags
> to inform that event->cm_node has been freed.
>
> Signed-off-by: Lv Yunlong <lyl2019@mail.ustc.edu.cn>
> ---
> drivers/infiniband/hw/i40iw/i40iw_cm.c | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
This might be OK (though I don't like the free variable), Shiraz??
Jason
^ permalink raw reply [flat|nested] 5+ messages in thread
* RE: [PATCH] infiniband/i40iw: Fix a use after free in i40iw_cm_event_handler
2021-03-11 18:21 ` Jason Gunthorpe
@ 2021-03-12 1:13 ` Saleem, Shiraz
2021-03-12 1:57 ` lyl2019
0 siblings, 1 reply; 5+ messages in thread
From: Saleem, Shiraz @ 2021-03-12 1:13 UTC (permalink / raw)
To: Jason Gunthorpe, Lv Yunlong
Cc: Latif, Faisal, dledford, linux-rdma, linux-kernel
> Subject: Re: [PATCH] infiniband/i40iw: Fix a use after free in
> i40iw_cm_event_handler
>
> On Wed, Mar 10, 2021 at 07:14:14PM -0800, Lv Yunlong wrote:
> > In the case of I40IW_CM_EVENT_ABORTED, i40iw_event_connect_error()
> > could be called to free the event->cm_node. However, event->cm_node
> > will be used after and cause use after free. It needs to add flags to
> > inform that event->cm_node has been freed.
> >
> > Signed-off-by: Lv Yunlong <lyl2019@mail.ustc.edu.cn>
> > ---
> > drivers/infiniband/hw/i40iw/i40iw_cm.c | 5 ++++-
> > 1 file changed, 4 insertions(+), 1 deletion(-)
>
> This might be OK (though I don't like the free variable), Shiraz??
>
How was this reproduced? Do you have some call trace leading up to use after free?
The cm_node refcnt is bumped at creation time and once in i40iw_receive_ilq before packet is processed.
That should protect the cm_node from disappearing in the event handler in the abort event case.
The dec at end of i40iw_receive ilq should be point where the cm_node is freed specifically in the abort case.
Shiraz
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: RE: [PATCH] infiniband/i40iw: Fix a use after free in i40iw_cm_event_handler
2021-03-12 1:13 ` Saleem, Shiraz
@ 2021-03-12 1:57 ` lyl2019
2021-03-13 1:11 ` Saleem, Shiraz
0 siblings, 1 reply; 5+ messages in thread
From: lyl2019 @ 2021-03-12 1:57 UTC (permalink / raw)
To: Saleem, Shiraz
Cc: Jason Gunthorpe, Latif, Faisal, dledford, linux-rdma, linux-kernel
> -----原始邮件-----
> 发件人: "Saleem, Shiraz" <shiraz.saleem@intel.com>
> 发送时间: 2021-03-12 09:13:39 (星期五)
> 收件人: "Jason Gunthorpe" <jgg@nvidia.com>, "Lv Yunlong" <lyl2019@mail.ustc.edu.cn>
> 抄送: "Latif, Faisal" <faisal.latif@intel.com>, "dledford@redhat.com" <dledford@redhat.com>, "linux-rdma@vger.kernel.org" <linux-rdma@vger.kernel.org>, "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
> 主题: RE: [PATCH] infiniband/i40iw: Fix a use after free in i40iw_cm_event_handler
>
> > Subject: Re: [PATCH] infiniband/i40iw: Fix a use after free in
> > i40iw_cm_event_handler
> >
> > On Wed, Mar 10, 2021 at 07:14:14PM -0800, Lv Yunlong wrote:
> > > In the case of I40IW_CM_EVENT_ABORTED, i40iw_event_connect_error()
> > > could be called to free the event->cm_node. However, event->cm_node
> > > will be used after and cause use after free. It needs to add flags to
> > > inform that event->cm_node has been freed.
> > >
> > > Signed-off-by: Lv Yunlong <lyl2019@mail.ustc.edu.cn>
> > > ---
> > > drivers/infiniband/hw/i40iw/i40iw_cm.c | 5 ++++-
> > > 1 file changed, 4 insertions(+), 1 deletion(-)
> >
> > This might be OK (though I don't like the free variable), Shiraz??
> >
>
> How was this reproduced? Do you have some call trace leading up to use after free?
>
> The cm_node refcnt is bumped at creation time and once in i40iw_receive_ilq before packet is processed.
> That should protect the cm_node from disappearing in the event handler in the abort event case.
> The dec at end of i40iw_receive ilq should be point where the cm_node is freed specifically in the abort case.
>
> Shiraz
>
This problem was reported by a path-sensitive analyzer developed by our Security Lab(Loccs).
The analyzer reported that there is a feasible path to free event->cm_node and use it after,
and that is what i described in the first commit.
Thanks.
^ permalink raw reply [flat|nested] 5+ messages in thread
* RE: RE: [PATCH] infiniband/i40iw: Fix a use after free in i40iw_cm_event_handler
2021-03-12 1:57 ` lyl2019
@ 2021-03-13 1:11 ` Saleem, Shiraz
0 siblings, 0 replies; 5+ messages in thread
From: Saleem, Shiraz @ 2021-03-13 1:11 UTC (permalink / raw)
To: lyl2019
Cc: Jason Gunthorpe, Latif, Faisal, dledford, linux-rdma, linux-kernel
> Subject: Re: RE: [PATCH] infiniband/i40iw: Fix a use after free in
> i40iw_cm_event_handler
>
>
>
>
> > -----原始邮件-----
> > 发件人: "Saleem, Shiraz" <shiraz.saleem@intel.com>
> > 发送时间: 2021-03-12 09:13:39 (星期五)
> > 收件人: "Jason Gunthorpe" <jgg@nvidia.com>, "Lv Yunlong"
> > <lyl2019@mail.ustc.edu.cn>
> > 抄送: "Latif, Faisal" <faisal.latif@intel.com>, "dledford@redhat.com"
> > <dledford@redhat.com>, "linux-rdma@vger.kernel.org"
> > <linux-rdma@vger.kernel.org>, "linux-kernel@vger.kernel.org"
> > <linux-kernel@vger.kernel.org>
> > 主题: RE: [PATCH] infiniband/i40iw: Fix a use after free in
> > i40iw_cm_event_handler
> >
> > > Subject: Re: [PATCH] infiniband/i40iw: Fix a use after free in
> > > i40iw_cm_event_handler
> > >
> > > On Wed, Mar 10, 2021 at 07:14:14PM -0800, Lv Yunlong wrote:
> > > > In the case of I40IW_CM_EVENT_ABORTED, i40iw_event_connect_error()
> > > > could be called to free the event->cm_node. However,
> > > > event->cm_node will be used after and cause use after free. It
> > > > needs to add flags to inform that event->cm_node has been freed.
> > > >
> > > > Signed-off-by: Lv Yunlong <lyl2019@mail.ustc.edu.cn>
> > > > ---
> > > > drivers/infiniband/hw/i40iw/i40iw_cm.c | 5 ++++-
> > > > 1 file changed, 4 insertions(+), 1 deletion(-)
> > >
> > > This might be OK (though I don't like the free variable), Shiraz??
> > >
> >
> > How was this reproduced? Do you have some call trace leading up to use after
> free?
> >
> > The cm_node refcnt is bumped at creation time and once in i40iw_receive_ilq
> before packet is processed.
> > That should protect the cm_node from disappearing in the event handler in the
> abort event case.
> > The dec at end of i40iw_receive ilq should be point where the cm_node is freed
> specifically in the abort case.
> >
> > Shiraz
> >
>
> This problem was reported by a path-sensitive analyzer developed by our Security
> Lab(Loccs).
> The analyzer reported that there is a feasible path to free event->cm_node and use
> it after, and that is what i described in the first commit.
>
OK. I don’t think that an extra dec refcnt in itself for the abort case is enough evidence to
say that the cm_node is freed in i40iw_event_connect_error.
Shiraz
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2021-03-13 1:13 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-11 3:14 [PATCH] infiniband/i40iw: Fix a use after free in i40iw_cm_event_handler Lv Yunlong
2021-03-11 18:21 ` Jason Gunthorpe
2021-03-12 1:13 ` Saleem, Shiraz
2021-03-12 1:57 ` lyl2019
2021-03-13 1:11 ` Saleem, Shiraz
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.