linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Shunsuke Mie <mie@igel.co.jp>
To: Kishon Vijay Abraham I <kishon@ti.com>
Cc: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>,
	Bjorn Helgaas <bhelgaas@google.com>,
	linux-pci@vger.kernel.org,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	stable@vger.kernel.org
Subject: Re: [PATCH] PCI: endpoint: Fix use after free in pci_epf_remove_cfs()
Date: Fri, 10 Dec 2021 20:09:30 +0900	[thread overview]
Message-ID: <CANXvt5q_fpLheaFtbXGETODPRbdO5M1Nxrd1R66uEr7DaSSZVw@mail.gmail.com> (raw)
In-Reply-To: <CANXvt5r-1+W91DXNcVuRxTE0_T0TSGuduMhOfmYgY=N87uzqCg@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 2361 bytes --]

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

[-- Attachment #2: dmesg_crash.log --]
[-- Type: application/octet-stream, Size: 35947 bytes --]

  reply	other threads:[~2021-12-10 11:09 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-21  7:00 [PATCH] PCI: endpoint: Fix use after free in pci_epf_remove_cfs() Shunsuke Mie
2021-06-21  8:39 ` Greg KH
2021-12-06 11:45 ` Lorenzo Pieralisi
2021-12-07  7:26 ` Kishon Vijay Abraham I
2021-12-07  7:44   ` Shunsuke Mie
2021-12-10 11:09     ` Shunsuke Mie [this message]
  -- strict thread matches above, loose matches on Subject: below --
2021-06-11  3:50 Shunsuke Mie

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CANXvt5q_fpLheaFtbXGETODPRbdO5M1Nxrd1R66uEr7DaSSZVw@mail.gmail.com \
    --to=mie@igel.co.jp \
    --cc=bhelgaas@google.com \
    --cc=kishon@ti.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=lorenzo.pieralisi@arm.com \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).