linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] vdpa/vp_vdpa: fix kfree a wrong pointer in vp_vdpa_remove
@ 2022-12-07 12:08 Nanyong Sun
  2022-12-08  2:05 ` Cindy Lu
  0 siblings, 1 reply; 3+ messages in thread
From: Nanyong Sun @ 2022-12-07 12:08 UTC (permalink / raw)
  To: mst, jasowang, gautam.dawar, elic, sgarzare
  Cc: wangrong68, lulu, virtualization, linux-kernel, sunnanyong,
	liushixin2, wangkefeng.wang

From: Rong Wang <wangrong68@huawei.com>

In vp_vdpa_remove(), the code kfree(&vp_vdpa_mgtdev->mgtdev.id_table) uses
a reference of pointer as the argument of kfree, which is the wrong pointer
and then may hit crash like this:

Unable to handle kernel paging request at virtual address 00ffff003363e30c
Internal error: Oops: 96000004 [#1] SMP
Call trace:
 rb_next+0x20/0x5c
 ext4_readdir+0x494/0x5c4 [ext4]
 iterate_dir+0x168/0x1b4
 __se_sys_getdents64+0x68/0x170
 __arm64_sys_getdents64+0x24/0x30
 el0_svc_common.constprop.0+0x7c/0x1bc
 do_el0_svc+0x2c/0x94
 el0_svc+0x20/0x30
 el0_sync_handler+0xb0/0xb4
 el0_sync+0x160/0x180
Code: 54000220 f9400441 b4000161 aa0103e0 (f9400821)
SMP: stopping secondary CPUs
Starting crashdump kernel...

Fixes: ffbda8e9df10 ("vdpa/vp_vdpa : add vdpa tool support in vp_vdpa")
Signed-off-by: Rong Wang <wangrong68@huawei.com>
Signed-off-by: Nanyong Sun <sunnanyong@huawei.com>
---
 drivers/vdpa/virtio_pci/vp_vdpa.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/vdpa/virtio_pci/vp_vdpa.c b/drivers/vdpa/virtio_pci/vp_vdpa.c
index d448db0c4de3..8fe267ca3e76 100644
--- a/drivers/vdpa/virtio_pci/vp_vdpa.c
+++ b/drivers/vdpa/virtio_pci/vp_vdpa.c
@@ -647,7 +647,7 @@ static void vp_vdpa_remove(struct pci_dev *pdev)
 	mdev = vp_vdpa_mgtdev->mdev;
 	vp_modern_remove(mdev);
 	vdpa_mgmtdev_unregister(&vp_vdpa_mgtdev->mgtdev);
-	kfree(&vp_vdpa_mgtdev->mgtdev.id_table);
+	kfree(vp_vdpa_mgtdev->mgtdev.id_table);
 	kfree(mdev);
 	kfree(vp_vdpa_mgtdev);
 }
-- 
2.25.1


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

* Re: [PATCH] vdpa/vp_vdpa: fix kfree a wrong pointer in vp_vdpa_remove
  2022-12-07 12:08 [PATCH] vdpa/vp_vdpa: fix kfree a wrong pointer in vp_vdpa_remove Nanyong Sun
@ 2022-12-08  2:05 ` Cindy Lu
  2022-12-08  7:33   ` Jason Wang
  0 siblings, 1 reply; 3+ messages in thread
From: Cindy Lu @ 2022-12-08  2:05 UTC (permalink / raw)
  To: Nanyong Sun
  Cc: mst, jasowang, gautam.dawar, elic, sgarzare, wangrong68,
	virtualization, linux-kernel, liushixin2, wangkefeng.wang

On Wed, 7 Dec 2022 at 19:23, Nanyong Sun <sunnanyong@huawei.com> wrote:
>
> From: Rong Wang <wangrong68@huawei.com>
>
> In vp_vdpa_remove(), the code kfree(&vp_vdpa_mgtdev->mgtdev.id_table) uses
> a reference of pointer as the argument of kfree, which is the wrong pointer
> and then may hit crash like this:
>
> Unable to handle kernel paging request at virtual address 00ffff003363e30c
> Internal error: Oops: 96000004 [#1] SMP
> Call trace:
>  rb_next+0x20/0x5c
>  ext4_readdir+0x494/0x5c4 [ext4]
>  iterate_dir+0x168/0x1b4
>  __se_sys_getdents64+0x68/0x170
>  __arm64_sys_getdents64+0x24/0x30
>  el0_svc_common.constprop.0+0x7c/0x1bc
>  do_el0_svc+0x2c/0x94
>  el0_svc+0x20/0x30
>  el0_sync_handler+0xb0/0xb4
>  el0_sync+0x160/0x180
> Code: 54000220 f9400441 b4000161 aa0103e0 (f9400821)
> SMP: stopping secondary CPUs
> Starting crashdump kernel...
>
> Fixes: ffbda8e9df10 ("vdpa/vp_vdpa : add vdpa tool support in vp_vdpa")
> Signed-off-by: Rong Wang <wangrong68@huawei.com>
> Signed-off-by: Nanyong Sun <sunnanyong@huawei.com>
> ---
>  drivers/vdpa/virtio_pci/vp_vdpa.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/vdpa/virtio_pci/vp_vdpa.c b/drivers/vdpa/virtio_pci/vp_vdpa.c
> index d448db0c4de3..8fe267ca3e76 100644
> --- a/drivers/vdpa/virtio_pci/vp_vdpa.c
> +++ b/drivers/vdpa/virtio_pci/vp_vdpa.c
> @@ -647,7 +647,7 @@ static void vp_vdpa_remove(struct pci_dev *pdev)
>         mdev = vp_vdpa_mgtdev->mdev;
>         vp_modern_remove(mdev);
>         vdpa_mgmtdev_unregister(&vp_vdpa_mgtdev->mgtdev);
> -       kfree(&vp_vdpa_mgtdev->mgtdev.id_table);
> +       kfree(vp_vdpa_mgtdev->mgtdev.id_table);
>         kfree(mdev);
>         kfree(vp_vdpa_mgtdev);
>  }
> --
> 2.25.1
>
Reviewed-by: Cindy Lu <lulu@redhat.com>


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

* Re: [PATCH] vdpa/vp_vdpa: fix kfree a wrong pointer in vp_vdpa_remove
  2022-12-08  2:05 ` Cindy Lu
@ 2022-12-08  7:33   ` Jason Wang
  0 siblings, 0 replies; 3+ messages in thread
From: Jason Wang @ 2022-12-08  7:33 UTC (permalink / raw)
  To: Cindy Lu
  Cc: Nanyong Sun, mst, gautam.dawar, elic, sgarzare, wangrong68,
	virtualization, linux-kernel, liushixin2, wangkefeng.wang

On Thu, Dec 8, 2022 at 10:05 AM Cindy Lu <lulu@redhat.com> wrote:
>
> On Wed, 7 Dec 2022 at 19:23, Nanyong Sun <sunnanyong@huawei.com> wrote:
> >
> > From: Rong Wang <wangrong68@huawei.com>
> >
> > In vp_vdpa_remove(), the code kfree(&vp_vdpa_mgtdev->mgtdev.id_table) uses
> > a reference of pointer as the argument of kfree, which is the wrong pointer
> > and then may hit crash like this:
> >
> > Unable to handle kernel paging request at virtual address 00ffff003363e30c
> > Internal error: Oops: 96000004 [#1] SMP
> > Call trace:
> >  rb_next+0x20/0x5c
> >  ext4_readdir+0x494/0x5c4 [ext4]
> >  iterate_dir+0x168/0x1b4
> >  __se_sys_getdents64+0x68/0x170
> >  __arm64_sys_getdents64+0x24/0x30
> >  el0_svc_common.constprop.0+0x7c/0x1bc
> >  do_el0_svc+0x2c/0x94
> >  el0_svc+0x20/0x30
> >  el0_sync_handler+0xb0/0xb4
> >  el0_sync+0x160/0x180
> > Code: 54000220 f9400441 b4000161 aa0103e0 (f9400821)
> > SMP: stopping secondary CPUs
> > Starting crashdump kernel...
> >
> > Fixes: ffbda8e9df10 ("vdpa/vp_vdpa : add vdpa tool support in vp_vdpa")
> > Signed-off-by: Rong Wang <wangrong68@huawei.com>
> > Signed-off-by: Nanyong Sun <sunnanyong@huawei.com>
> > ---
> >  drivers/vdpa/virtio_pci/vp_vdpa.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/drivers/vdpa/virtio_pci/vp_vdpa.c b/drivers/vdpa/virtio_pci/vp_vdpa.c
> > index d448db0c4de3..8fe267ca3e76 100644
> > --- a/drivers/vdpa/virtio_pci/vp_vdpa.c
> > +++ b/drivers/vdpa/virtio_pci/vp_vdpa.c
> > @@ -647,7 +647,7 @@ static void vp_vdpa_remove(struct pci_dev *pdev)
> >         mdev = vp_vdpa_mgtdev->mdev;
> >         vp_modern_remove(mdev);
> >         vdpa_mgmtdev_unregister(&vp_vdpa_mgtdev->mgtdev);
> > -       kfree(&vp_vdpa_mgtdev->mgtdev.id_table);
> > +       kfree(vp_vdpa_mgtdev->mgtdev.id_table);
> >         kfree(mdev);
> >         kfree(vp_vdpa_mgtdev);
> >  }
> > --
> > 2.25.1
> >
> Reviewed-by: Cindy Lu <lulu@redhat.com>

Acked-by: Jason Wang <jasowang@redhat.com>

Thanks

>


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

end of thread, other threads:[~2022-12-08  7:34 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-07 12:08 [PATCH] vdpa/vp_vdpa: fix kfree a wrong pointer in vp_vdpa_remove Nanyong Sun
2022-12-08  2:05 ` Cindy Lu
2022-12-08  7:33   ` Jason Wang

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).