lkml.org 
[lkml]   [2021]   [Dec]   [10]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
Date
SubjectRe: [PATCH] PCI: endpoint: Fix use after free in pci_epf_remove_cfs()
Hi Kishon,

This is the crash log. I think you can reproduce this problem by loading and
unloading the pci-epf-test modules some times, but I don't think you'll see
similar logs in your environment.

The pci_ep_cfs_remove_epf_group function calls kfree for the `group`, however
a member of group, `group_entry``, is accessed by a list_del() after the loop.
The patch changes to remove list entries to prevent the accessing after freed
object.

Thanks,
Shunsuke

2021年12月7日(火) 16:44 Shunsuke Mie <mie@igel.co.jp>:
>
> Hi Kishon,
>
> 2021年12月7日(火) 16:26 Kishon Vijay Abraham I <kishon@ti.com>:
> >
> > Hi Shunsuke,
> >
> > On 21/06/21 12:30 pm, Shunsuke Mie wrote:
> > > All of entries are freed in a loop, however, the freed entry is accessed
> > > by list_del() after the loop.
> > >
> > > When epf driver that includes pci-epf-test unload, the pci_epf_remove_cfs()
> > > is called, and occurred the use after free. Therefore, kernel panics
> > > randomly after or while the module unloading.
> > >
> > > I tested this patch with r8a77951-Salvator-xs boards.
> >
> > Can you provide the crash dump?
> Ok. However, that is use-after-free bug. so, the crash log is changed randomly.
> I'll send some crash dumps.
> > >
> > > Fixes: ef1433f ("PCI: endpoint: Create configfs entry for each pci_epf_device_id table entry")
> > > Signed-off-by: Shunsuke Mie <mie@igel.co.jp>
> > > ---
> > > drivers/pci/endpoint/pci-epf-core.c | 4 +++-
> > > 1 file changed, 3 insertions(+), 1 deletion(-)
> > >
> > > diff --git a/drivers/pci/endpoint/pci-epf-core.c b/drivers/pci/endpoint/pci-epf-core.c
> > > index e9289d10f822..538e902b0ba6 100644
> > > --- a/drivers/pci/endpoint/pci-epf-core.c
> > > +++ b/drivers/pci/endpoint/pci-epf-core.c
> > > @@ -202,8 +202,10 @@ static void pci_epf_remove_cfs(struct pci_epf_driver *driver)
> > > return;
> > >
> > > mutex_lock(&pci_epf_mutex);
> > > - list_for_each_entry_safe(group, tmp, &driver->epf_group, group_entry)
> > > + list_for_each_entry_safe(group, tmp, &driver->epf_group, group_entry) {
> > > + list_del(&group->group_entry);
> >
> > Need full crash dump to see if this is really required or not. Ideally this
> > should be handled by configfs (or a configfs API could be used).
> >
> > Thanks,
> > Kishon
[unhandled content-type:application/octet-stream]
\
 
 \ /
  Last update: 2021-12-10 12:09    [W:0.313 / U:0.080 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site