All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] video: fbdev: kyro: fix a DoS bug by restricting user input
@ 2021-07-14  4:09 ` Zheyu Ma
  0 siblings, 0 replies; 5+ messages in thread
From: Zheyu Ma @ 2021-07-14  4:09 UTC (permalink / raw)
  To: dri-devel; +Cc: linux-fbdev, linux-kernel, sam, Zheyu Ma

The user can pass in any value to the driver through the 'ioctl'
interface. The driver dost not check, which may cause DoS bugs.

The following log reveals it:

divide error: 0000 [#1] PREEMPT SMP KASAN PTI
RIP: 0010:SetOverlayViewPort+0x133/0x5f0 drivers/video/fbdev/kyro/STG4000OverlayDevice.c:476
Call Trace:
 kyro_dev_overlay_viewport_set drivers/video/fbdev/kyro/fbdev.c:378 [inline]
 kyrofb_ioctl+0x2eb/0x330 drivers/video/fbdev/kyro/fbdev.c:603
 do_fb_ioctl+0x1f3/0x700 drivers/video/fbdev/core/fbmem.c:1171
 fb_ioctl+0xeb/0x130 drivers/video/fbdev/core/fbmem.c:1185
 vfs_ioctl fs/ioctl.c:48 [inline]
 __do_sys_ioctl fs/ioctl.c:753 [inline]
 __se_sys_ioctl fs/ioctl.c:739 [inline]
 __x64_sys_ioctl+0x19b/0x220 fs/ioctl.c:739
 do_syscall_64+0x32/0x80 arch/x86/entry/common.c:46
 entry_SYSCALL_64_after_hwframe+0x44/0xae

Signed-off-by: Zheyu Ma <zheyuma97@gmail.com>
---
Changes in v2:
    - Validate the inputs on a higher level
---
 drivers/video/fbdev/kyro/fbdev.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/video/fbdev/kyro/fbdev.c b/drivers/video/fbdev/kyro/fbdev.c
index 8fbde92ae8b9..eb0cbd1d12d5 100644
--- a/drivers/video/fbdev/kyro/fbdev.c
+++ b/drivers/video/fbdev/kyro/fbdev.c
@@ -372,6 +372,11 @@ static int kyro_dev_overlay_viewport_set(u32 x, u32 y, u32 ulWidth, u32 ulHeight
 		/* probably haven't called CreateOverlay yet */
 		return -EINVAL;
 
+	if (ulWidth == 0 || ulWidth == 0xffffffff ||
+		ulHeight == 0 || ulHeight == 0xffffffff ||
+		(x < 2 && ulWidth + 2 == 0))
+		return -EINVAL;
+
 	/* Stop Ramdac Output */
 	DisableRamdacOutput(deviceInfo.pSTGReg);
 
-- 
2.17.6


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

* [PATCH v2] video: fbdev: kyro: fix a DoS bug by restricting user input
@ 2021-07-14  4:09 ` Zheyu Ma
  0 siblings, 0 replies; 5+ messages in thread
From: Zheyu Ma @ 2021-07-14  4:09 UTC (permalink / raw)
  To: dri-devel; +Cc: linux-fbdev, Zheyu Ma, sam, linux-kernel

The user can pass in any value to the driver through the 'ioctl'
interface. The driver dost not check, which may cause DoS bugs.

The following log reveals it:

divide error: 0000 [#1] PREEMPT SMP KASAN PTI
RIP: 0010:SetOverlayViewPort+0x133/0x5f0 drivers/video/fbdev/kyro/STG4000OverlayDevice.c:476
Call Trace:
 kyro_dev_overlay_viewport_set drivers/video/fbdev/kyro/fbdev.c:378 [inline]
 kyrofb_ioctl+0x2eb/0x330 drivers/video/fbdev/kyro/fbdev.c:603
 do_fb_ioctl+0x1f3/0x700 drivers/video/fbdev/core/fbmem.c:1171
 fb_ioctl+0xeb/0x130 drivers/video/fbdev/core/fbmem.c:1185
 vfs_ioctl fs/ioctl.c:48 [inline]
 __do_sys_ioctl fs/ioctl.c:753 [inline]
 __se_sys_ioctl fs/ioctl.c:739 [inline]
 __x64_sys_ioctl+0x19b/0x220 fs/ioctl.c:739
 do_syscall_64+0x32/0x80 arch/x86/entry/common.c:46
 entry_SYSCALL_64_after_hwframe+0x44/0xae

Signed-off-by: Zheyu Ma <zheyuma97@gmail.com>
---
Changes in v2:
    - Validate the inputs on a higher level
---
 drivers/video/fbdev/kyro/fbdev.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/video/fbdev/kyro/fbdev.c b/drivers/video/fbdev/kyro/fbdev.c
index 8fbde92ae8b9..eb0cbd1d12d5 100644
--- a/drivers/video/fbdev/kyro/fbdev.c
+++ b/drivers/video/fbdev/kyro/fbdev.c
@@ -372,6 +372,11 @@ static int kyro_dev_overlay_viewport_set(u32 x, u32 y, u32 ulWidth, u32 ulHeight
 		/* probably haven't called CreateOverlay yet */
 		return -EINVAL;
 
+	if (ulWidth == 0 || ulWidth == 0xffffffff ||
+		ulHeight == 0 || ulHeight == 0xffffffff ||
+		(x < 2 && ulWidth + 2 == 0))
+		return -EINVAL;
+
 	/* Stop Ramdac Output */
 	DisableRamdacOutput(deviceInfo.pSTGReg);
 
-- 
2.17.6


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

* Re: [PATCH v2] video: fbdev: kyro: fix a DoS bug by restricting user input
  2021-07-14  4:09 ` Zheyu Ma
  (?)
@ 2021-07-19 18:50 ` Sam Ravnborg
  2021-07-20  6:45     ` Zheyu Ma
  -1 siblings, 1 reply; 5+ messages in thread
From: Sam Ravnborg @ 2021-07-19 18:50 UTC (permalink / raw)
  To: Zheyu Ma; +Cc: linux-fbdev, linux-kernel, dri-devel

Hi Zheyu,
On Wed, Jul 14, 2021 at 04:09:22AM +0000, Zheyu Ma wrote:
> The user can pass in any value to the driver through the 'ioctl'
> interface. The driver dost not check, which may cause DoS bugs.
> 
> The following log reveals it:
> 
> divide error: 0000 [#1] PREEMPT SMP KASAN PTI
> RIP: 0010:SetOverlayViewPort+0x133/0x5f0 drivers/video/fbdev/kyro/STG4000OverlayDevice.c:476
> Call Trace:
>  kyro_dev_overlay_viewport_set drivers/video/fbdev/kyro/fbdev.c:378 [inline]
>  kyrofb_ioctl+0x2eb/0x330 drivers/video/fbdev/kyro/fbdev.c:603
>  do_fb_ioctl+0x1f3/0x700 drivers/video/fbdev/core/fbmem.c:1171
>  fb_ioctl+0xeb/0x130 drivers/video/fbdev/core/fbmem.c:1185
>  vfs_ioctl fs/ioctl.c:48 [inline]
>  __do_sys_ioctl fs/ioctl.c:753 [inline]
>  __se_sys_ioctl fs/ioctl.c:739 [inline]
>  __x64_sys_ioctl+0x19b/0x220 fs/ioctl.c:739
>  do_syscall_64+0x32/0x80 arch/x86/entry/common.c:46
>  entry_SYSCALL_64_after_hwframe+0x44/0xae
> 
> Signed-off-by: Zheyu Ma <zheyuma97@gmail.com>
> ---
> Changes in v2:
>     - Validate the inputs on a higher level

Much better, thanks.
When a line is continued like here the statement shall aling with the
opening brace. I fixed it up when applying the patch to drm-misc-next so
no need to do anything this time.

	Sam

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

* Re: [PATCH v2] video: fbdev: kyro: fix a DoS bug by restricting user input
  2021-07-19 18:50 ` Sam Ravnborg
@ 2021-07-20  6:45     ` Zheyu Ma
  0 siblings, 0 replies; 5+ messages in thread
From: Zheyu Ma @ 2021-07-20  6:45 UTC (permalink / raw)
  To: Sam Ravnborg; +Cc: dri-devel, linux-fbdev, Linux Kernel Mailing List

On Tue, Jul 20, 2021 at 2:50 AM Sam Ravnborg <sam@ravnborg.org> wrote:
>
> Hi Zheyu,
> On Wed, Jul 14, 2021 at 04:09:22AM +0000, Zheyu Ma wrote:
> > The user can pass in any value to the driver through the 'ioctl'
> > interface. The driver dost not check, which may cause DoS bugs.
> >
> > The following log reveals it:
> >
> > divide error: 0000 [#1] PREEMPT SMP KASAN PTI
> > RIP: 0010:SetOverlayViewPort+0x133/0x5f0 drivers/video/fbdev/kyro/STG4000OverlayDevice.c:476
> > Call Trace:
> >  kyro_dev_overlay_viewport_set drivers/video/fbdev/kyro/fbdev.c:378 [inline]
> >  kyrofb_ioctl+0x2eb/0x330 drivers/video/fbdev/kyro/fbdev.c:603
> >  do_fb_ioctl+0x1f3/0x700 drivers/video/fbdev/core/fbmem.c:1171
> >  fb_ioctl+0xeb/0x130 drivers/video/fbdev/core/fbmem.c:1185
> >  vfs_ioctl fs/ioctl.c:48 [inline]
> >  __do_sys_ioctl fs/ioctl.c:753 [inline]
> >  __se_sys_ioctl fs/ioctl.c:739 [inline]
> >  __x64_sys_ioctl+0x19b/0x220 fs/ioctl.c:739
> >  do_syscall_64+0x32/0x80 arch/x86/entry/common.c:46
> >  entry_SYSCALL_64_after_hwframe+0x44/0xae
> >
> > Signed-off-by: Zheyu Ma <zheyuma97@gmail.com>
> > ---
> > Changes in v2:
> >     - Validate the inputs on a higher level
>
> Much better, thanks.
> When a line is continued like here the statement shall aling with the
> opening brace. I fixed it up when applying the patch to drm-misc-next so
> no need to do anything this time.

Thanks for your kind reminder, I will pay attention next time.

Regards,
Zheyu Ma

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

* Re: [PATCH v2] video: fbdev: kyro: fix a DoS bug by restricting user input
@ 2021-07-20  6:45     ` Zheyu Ma
  0 siblings, 0 replies; 5+ messages in thread
From: Zheyu Ma @ 2021-07-20  6:45 UTC (permalink / raw)
  To: Sam Ravnborg; +Cc: linux-fbdev, Linux Kernel Mailing List, dri-devel

On Tue, Jul 20, 2021 at 2:50 AM Sam Ravnborg <sam@ravnborg.org> wrote:
>
> Hi Zheyu,
> On Wed, Jul 14, 2021 at 04:09:22AM +0000, Zheyu Ma wrote:
> > The user can pass in any value to the driver through the 'ioctl'
> > interface. The driver dost not check, which may cause DoS bugs.
> >
> > The following log reveals it:
> >
> > divide error: 0000 [#1] PREEMPT SMP KASAN PTI
> > RIP: 0010:SetOverlayViewPort+0x133/0x5f0 drivers/video/fbdev/kyro/STG4000OverlayDevice.c:476
> > Call Trace:
> >  kyro_dev_overlay_viewport_set drivers/video/fbdev/kyro/fbdev.c:378 [inline]
> >  kyrofb_ioctl+0x2eb/0x330 drivers/video/fbdev/kyro/fbdev.c:603
> >  do_fb_ioctl+0x1f3/0x700 drivers/video/fbdev/core/fbmem.c:1171
> >  fb_ioctl+0xeb/0x130 drivers/video/fbdev/core/fbmem.c:1185
> >  vfs_ioctl fs/ioctl.c:48 [inline]
> >  __do_sys_ioctl fs/ioctl.c:753 [inline]
> >  __se_sys_ioctl fs/ioctl.c:739 [inline]
> >  __x64_sys_ioctl+0x19b/0x220 fs/ioctl.c:739
> >  do_syscall_64+0x32/0x80 arch/x86/entry/common.c:46
> >  entry_SYSCALL_64_after_hwframe+0x44/0xae
> >
> > Signed-off-by: Zheyu Ma <zheyuma97@gmail.com>
> > ---
> > Changes in v2:
> >     - Validate the inputs on a higher level
>
> Much better, thanks.
> When a line is continued like here the statement shall aling with the
> opening brace. I fixed it up when applying the patch to drm-misc-next so
> no need to do anything this time.

Thanks for your kind reminder, I will pay attention next time.

Regards,
Zheyu Ma

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

end of thread, other threads:[~2021-07-20  7:23 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-14  4:09 [PATCH v2] video: fbdev: kyro: fix a DoS bug by restricting user input Zheyu Ma
2021-07-14  4:09 ` Zheyu Ma
2021-07-19 18:50 ` Sam Ravnborg
2021-07-20  6:45   ` Zheyu Ma
2021-07-20  6:45     ` Zheyu Ma

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.