All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] iommufd/selftest: Catch overflow of uptr and length
@ 2023-03-06 17:27 Jason Gunthorpe
  2023-03-07  2:32 ` Tian, Kevin
  2023-03-10 19:46 ` Jason Gunthorpe
  0 siblings, 2 replies; 6+ messages in thread
From: Jason Gunthorpe @ 2023-03-06 17:27 UTC (permalink / raw)
  To: iommu, Kevin Tian; +Cc: Pengfei Xu

syzkaller hits a WARN_ON when trying to have a uptr close to UINTPTR_MAX:

  WARNING: CPU: 1 PID: 393 at drivers/iommu/iommufd/selftest.c:403 iommufd_test+0xb19/0x16f0
  Modules linked in:
  CPU: 1 PID: 393 Comm: repro Not tainted 6.2.0-c9c3395d5e3d #1
  Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.16.0-0-gd239552ce722-prebuilt.qemu.org 04/01/2014
  RIP: 0010:iommufd_test+0xb19/0x16f0
  Code: 94 c4 31 ff 44 89 e6 e8 a5 54 17 ff 45 84 e4 0f 85 bb 0b 00 00 41 be fb ff ff ff e8 31 53 17 ff e9 a0 f7 ff ff e8 27 53 17 ff <0f> 0b 41 be 8
  RSP: 0018:ffffc90000eabdc0 EFLAGS: 00010246
  RAX: 0000000000000000 RBX: 0000000000000000 RCX: ffffffff8214c487
  RDX: 0000000000000000 RSI: ffff88800f5c8000 RDI: 0000000000000002
  RBP: ffffc90000eabe48 R08: 0000000000000000 R09: 0000000000000001
  R10: 0000000000000001 R11: 0000000000000000 R12: 00000000cd2b0000
  R13: 00000000cd2af000 R14: 0000000000000000 R15: ffffc90000eabe68
  FS:  00007f94d76d5740(0000) GS:ffff88807dd00000(0000) knlGS:0000000000000000
  CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
  CR2: 0000000020000043 CR3: 0000000006880006 CR4: 0000000000770ee0
  PKRU: 55555554
  Call Trace:
   <TASK>
   ? write_comp_data+0x2f/0x90
   iommufd_fops_ioctl+0x1ef/0x310
   __x64_sys_ioctl+0x10e/0x160
   ? __pfx_iommufd_fops_ioctl+0x10/0x10
   do_syscall_64+0x3b/0x90
   entry_SYSCALL_64_after_hwframe+0x72/0xdc

Check that the user memory range doesn't overflow.

Fixes: f4b20bb34c83 ("iommufd: Add kernel support for testing iommufd")
Link: https://lore.kernel.org/r/Y/hOiilV1wJvu/Hv@xpf.sh.intel.com
Reported-by: Pengfei Xu <pengfei.xu@intel.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
---
 drivers/iommu/iommufd/selftest.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/drivers/iommu/iommufd/selftest.c b/drivers/iommu/iommufd/selftest.c
index 17cb7b95eb2757..58471f9452be55 100644
--- a/drivers/iommu/iommufd/selftest.c
+++ b/drivers/iommu/iommufd/selftest.c
@@ -480,10 +480,12 @@ static int iommufd_test_md_check_pa(struct iommufd_ucmd *ucmd,
 {
 	struct iommufd_hw_pagetable *hwpt;
 	struct mock_iommu_domain *mock;
+	uintptr_t end;
 	int rc;
 
 	if (iova % MOCK_IO_PAGE_SIZE || length % MOCK_IO_PAGE_SIZE ||
-	    (uintptr_t)uptr % MOCK_IO_PAGE_SIZE)
+	    (uintptr_t)uptr % MOCK_IO_PAGE_SIZE ||
+	    check_add_overflow((uintptr_t)uptr, (uintptr_t)length, &end))
 		return -EINVAL;
 
 	hwpt = get_md_pagetable(ucmd, mockpt_id, &mock);
@@ -531,7 +533,10 @@ static int iommufd_test_md_check_refs(struct iommufd_ucmd *ucmd,
 				      void __user *uptr, size_t length,
 				      unsigned int refs)
 {
-	if (length % PAGE_SIZE || (uintptr_t)uptr % PAGE_SIZE)
+	uintptr_t end;
+
+	if (length % PAGE_SIZE || (uintptr_t)uptr % PAGE_SIZE ||
+	    check_add_overflow((uintptr_t)uptr, (uintptr_t)length, &end))
 		return -EINVAL;
 
 	for (; length; length -= PAGE_SIZE) {

base-commit: 4ed4791afb34c61650b17407846174a72e4034f4
-- 
2.39.2


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

* RE: [PATCH] iommufd/selftest: Catch overflow of uptr and length
  2023-03-06 17:27 [PATCH] iommufd/selftest: Catch overflow of uptr and length Jason Gunthorpe
@ 2023-03-07  2:32 ` Tian, Kevin
  2023-03-10 19:46 ` Jason Gunthorpe
  1 sibling, 0 replies; 6+ messages in thread
From: Tian, Kevin @ 2023-03-07  2:32 UTC (permalink / raw)
  To: Jason Gunthorpe, iommu@lists.linux.dev; +Cc: Xu, Pengfei

> From: Jason Gunthorpe <jgg@nvidia.com>
> Sent: Tuesday, March 7, 2023 1:27 AM
> 
> syzkaller hits a WARN_ON when trying to have a uptr close to UINTPTR_MAX:
> 
>   WARNING: CPU: 1 PID: 393 at drivers/iommu/iommufd/selftest.c:403
> iommufd_test+0xb19/0x16f0
>   Modules linked in:
>   CPU: 1 PID: 393 Comm: repro Not tainted 6.2.0-c9c3395d5e3d #1
>   Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.16.0-0-
> gd239552ce722-prebuilt.qemu.org 04/01/2014
>   RIP: 0010:iommufd_test+0xb19/0x16f0
>   Code: 94 c4 31 ff 44 89 e6 e8 a5 54 17 ff 45 84 e4 0f 85 bb 0b 00 00 41 be fb
> ff ff ff e8 31 53 17 ff e9 a0 f7 ff ff e8 27 53 17 ff <0f> 0b 41 be 8
>   RSP: 0018:ffffc90000eabdc0 EFLAGS: 00010246
>   RAX: 0000000000000000 RBX: 0000000000000000 RCX: ffffffff8214c487
>   RDX: 0000000000000000 RSI: ffff88800f5c8000 RDI: 0000000000000002
>   RBP: ffffc90000eabe48 R08: 0000000000000000 R09: 0000000000000001
>   R10: 0000000000000001 R11: 0000000000000000 R12: 00000000cd2b0000
>   R13: 00000000cd2af000 R14: 0000000000000000 R15: ffffc90000eabe68
>   FS:  00007f94d76d5740(0000) GS:ffff88807dd00000(0000)
> knlGS:0000000000000000
>   CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
>   CR2: 0000000020000043 CR3: 0000000006880006 CR4: 0000000000770ee0
>   PKRU: 55555554
>   Call Trace:
>    <TASK>
>    ? write_comp_data+0x2f/0x90
>    iommufd_fops_ioctl+0x1ef/0x310
>    __x64_sys_ioctl+0x10e/0x160
>    ? __pfx_iommufd_fops_ioctl+0x10/0x10
>    do_syscall_64+0x3b/0x90
>    entry_SYSCALL_64_after_hwframe+0x72/0xdc
> 
> Check that the user memory range doesn't overflow.
> 
> Fixes: f4b20bb34c83 ("iommufd: Add kernel support for testing iommufd")
> Link: https://lore.kernel.org/r/Y/hOiilV1wJvu/Hv@xpf.sh.intel.com
> Reported-by: Pengfei Xu <pengfei.xu@intel.com>
> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>

Reviewed-by: Kevin Tian <kevin.tian@intel.com>

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

* Re: [PATCH] iommufd/selftest: Catch overflow of uptr and length
  2023-03-06 17:27 [PATCH] iommufd/selftest: Catch overflow of uptr and length Jason Gunthorpe
  2023-03-07  2:32 ` Tian, Kevin
@ 2023-03-10 19:46 ` Jason Gunthorpe
  2023-04-17  8:34   ` Pengfei Xu
  1 sibling, 1 reply; 6+ messages in thread
From: Jason Gunthorpe @ 2023-03-10 19:46 UTC (permalink / raw)
  To: iommu, Kevin Tian; +Cc: Pengfei Xu

On Mon, Mar 06, 2023 at 01:27:04PM -0400, Jason Gunthorpe wrote:
> syzkaller hits a WARN_ON when trying to have a uptr close to UINTPTR_MAX:
> 
>   WARNING: CPU: 1 PID: 393 at drivers/iommu/iommufd/selftest.c:403 iommufd_test+0xb19/0x16f0
>   Modules linked in:
>   CPU: 1 PID: 393 Comm: repro Not tainted 6.2.0-c9c3395d5e3d #1
>   Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.16.0-0-gd239552ce722-prebuilt.qemu.org 04/01/2014
>   RIP: 0010:iommufd_test+0xb19/0x16f0
>   Code: 94 c4 31 ff 44 89 e6 e8 a5 54 17 ff 45 84 e4 0f 85 bb 0b 00 00 41 be fb ff ff ff e8 31 53 17 ff e9 a0 f7 ff ff e8 27 53 17 ff <0f> 0b 41 be 8
>   RSP: 0018:ffffc90000eabdc0 EFLAGS: 00010246
>   RAX: 0000000000000000 RBX: 0000000000000000 RCX: ffffffff8214c487
>   RDX: 0000000000000000 RSI: ffff88800f5c8000 RDI: 0000000000000002
>   RBP: ffffc90000eabe48 R08: 0000000000000000 R09: 0000000000000001
>   R10: 0000000000000001 R11: 0000000000000000 R12: 00000000cd2b0000
>   R13: 00000000cd2af000 R14: 0000000000000000 R15: ffffc90000eabe68
>   FS:  00007f94d76d5740(0000) GS:ffff88807dd00000(0000) knlGS:0000000000000000
>   CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
>   CR2: 0000000020000043 CR3: 0000000006880006 CR4: 0000000000770ee0
>   PKRU: 55555554
>   Call Trace:
>    <TASK>
>    ? write_comp_data+0x2f/0x90
>    iommufd_fops_ioctl+0x1ef/0x310
>    __x64_sys_ioctl+0x10e/0x160
>    ? __pfx_iommufd_fops_ioctl+0x10/0x10
>    do_syscall_64+0x3b/0x90
>    entry_SYSCALL_64_after_hwframe+0x72/0xdc
> 
> Check that the user memory range doesn't overflow.
> 
> Fixes: f4b20bb34c83 ("iommufd: Add kernel support for testing iommufd")
> Link: https://lore.kernel.org/r/Y/hOiilV1wJvu/Hv@xpf.sh.intel.com
> Reported-by: Pengfei Xu <pengfei.xu@intel.com>
> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
> ---
>  drivers/iommu/iommufd/selftest.c | 9 +++++++--
>  1 file changed, 7 insertions(+), 2 deletions(-)

Applied

Jason

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

* Re: [PATCH] iommufd/selftest: Catch overflow of uptr and length
  2023-03-10 19:46 ` Jason Gunthorpe
@ 2023-04-17  8:34   ` Pengfei Xu
  2023-04-17 12:23     ` Jason Gunthorpe
  0 siblings, 1 reply; 6+ messages in thread
From: Pengfei Xu @ 2023-04-17  8:34 UTC (permalink / raw)
  To: Jason Gunthorpe; +Cc: iommu, Kevin Tian

Hi Jason,

It's a soft remind.
Seems like this patch was not merged into Linux kernel main line yet for some
reason?
And this issue still could be reproduced in v6.3-rc7 kernel.

Thanks!
BR.

On 2023-03-10 at 15:46:15 -0400, Jason Gunthorpe wrote:
> On Mon, Mar 06, 2023 at 01:27:04PM -0400, Jason Gunthorpe wrote:
> > syzkaller hits a WARN_ON when trying to have a uptr close to UINTPTR_MAX:
> > 
> >   WARNING: CPU: 1 PID: 393 at drivers/iommu/iommufd/selftest.c:403 iommufd_test+0xb19/0x16f0
> >   Modules linked in:
> >   CPU: 1 PID: 393 Comm: repro Not tainted 6.2.0-c9c3395d5e3d #1
> >   Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.16.0-0-gd239552ce722-prebuilt.qemu.org 04/01/2014
> >   RIP: 0010:iommufd_test+0xb19/0x16f0
> >   Code: 94 c4 31 ff 44 89 e6 e8 a5 54 17 ff 45 84 e4 0f 85 bb 0b 00 00 41 be fb ff ff ff e8 31 53 17 ff e9 a0 f7 ff ff e8 27 53 17 ff <0f> 0b 41 be 8
> >   RSP: 0018:ffffc90000eabdc0 EFLAGS: 00010246
> >   RAX: 0000000000000000 RBX: 0000000000000000 RCX: ffffffff8214c487
> >   RDX: 0000000000000000 RSI: ffff88800f5c8000 RDI: 0000000000000002
> >   RBP: ffffc90000eabe48 R08: 0000000000000000 R09: 0000000000000001
> >   R10: 0000000000000001 R11: 0000000000000000 R12: 00000000cd2b0000
> >   R13: 00000000cd2af000 R14: 0000000000000000 R15: ffffc90000eabe68
> >   FS:  00007f94d76d5740(0000) GS:ffff88807dd00000(0000) knlGS:0000000000000000
> >   CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
> >   CR2: 0000000020000043 CR3: 0000000006880006 CR4: 0000000000770ee0
> >   PKRU: 55555554
> >   Call Trace:
> >    <TASK>
> >    ? write_comp_data+0x2f/0x90
> >    iommufd_fops_ioctl+0x1ef/0x310
> >    __x64_sys_ioctl+0x10e/0x160
> >    ? __pfx_iommufd_fops_ioctl+0x10/0x10
> >    do_syscall_64+0x3b/0x90
> >    entry_SYSCALL_64_after_hwframe+0x72/0xdc
> > 
> > Check that the user memory range doesn't overflow.
> > 
> > Fixes: f4b20bb34c83 ("iommufd: Add kernel support for testing iommufd")
> > Link: https://lore.kernel.org/r/Y/hOiilV1wJvu/Hv@xpf.sh.intel.com
> > Reported-by: Pengfei Xu <pengfei.xu@intel.com>
> > Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
> > ---
> >  drivers/iommu/iommufd/selftest.c | 9 +++++++--
> >  1 file changed, 7 insertions(+), 2 deletions(-)
> 
> Applied
> 
> Jason

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

* Re: [PATCH] iommufd/selftest: Catch overflow of uptr and length
  2023-04-17  8:34   ` Pengfei Xu
@ 2023-04-17 12:23     ` Jason Gunthorpe
  2023-04-17 13:21       ` Pengfei Xu
  0 siblings, 1 reply; 6+ messages in thread
From: Jason Gunthorpe @ 2023-04-17 12:23 UTC (permalink / raw)
  To: Pengfei Xu; +Cc: iommu, Kevin Tian

On Mon, Apr 17, 2023 at 04:34:41PM +0800, Pengfei Xu wrote:
> Hi Jason,
> 
> It's a soft remind.
> Seems like this patch was not merged into Linux kernel main line yet for some
> reason?
> And this issue still could be reproduced in v6.3-rc7 kernel.

Yes, since it is a selftest only issue it will go into 6.4

Jason

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

* Re: [PATCH] iommufd/selftest: Catch overflow of uptr and length
  2023-04-17 12:23     ` Jason Gunthorpe
@ 2023-04-17 13:21       ` Pengfei Xu
  0 siblings, 0 replies; 6+ messages in thread
From: Pengfei Xu @ 2023-04-17 13:21 UTC (permalink / raw)
  To: Jason Gunthorpe; +Cc: iommu, Kevin Tian

On 2023-04-17 at 09:23:30 -0300, Jason Gunthorpe wrote:
> On Mon, Apr 17, 2023 at 04:34:41PM +0800, Pengfei Xu wrote:
> > Hi Jason,
> > 
> > It's a soft remind.
> > Seems like this patch was not merged into Linux kernel main line yet for some
> > reason?
> > And this issue still could be reproduced in v6.3-rc7 kernel.
> 
> Yes, since it is a selftest only issue it will go into 6.4
> 
  Ah, got it, thanks for the description!

  Thanks!
  BR.

> Jason

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

end of thread, other threads:[~2023-04-17 13:19 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-03-06 17:27 [PATCH] iommufd/selftest: Catch overflow of uptr and length Jason Gunthorpe
2023-03-07  2:32 ` Tian, Kevin
2023-03-10 19:46 ` Jason Gunthorpe
2023-04-17  8:34   ` Pengfei Xu
2023-04-17 12:23     ` Jason Gunthorpe
2023-04-17 13:21       ` Pengfei Xu

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.