All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] video: fbdev: kyrofb: fix a DoS bug by restricting user input
@ 2021-07-13 12:51 ` Zheyu Ma
  0 siblings, 0 replies; 3+ messages in thread
From: Zheyu Ma @ 2021-07-13 12:51 UTC (permalink / raw)
  To: dri-devel; +Cc: linux-fbdev, linux-kernel, security, 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.

Fix this by checking if the divisor is 0

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>
---
 drivers/video/fbdev/kyro/STG4000OverlayDevice.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/video/fbdev/kyro/STG4000OverlayDevice.c b/drivers/video/fbdev/kyro/STG4000OverlayDevice.c
index 9fde0e3b69ec..29d692fe5e75 100644
--- a/drivers/video/fbdev/kyro/STG4000OverlayDevice.c
+++ b/drivers/video/fbdev/kyro/STG4000OverlayDevice.c
@@ -407,6 +407,9 @@ int SetOverlayViewPort(volatile STG4000REG __iomem *pSTGReg,
 		ulVertDecFactor = 1;
 	}
 
+	if ((ulDest + 1) == 0)
+		return -EINVAL;
+
 	ulDacYScale = ((ulSrc - 1) * 2048) / (ulDest + 1);
 
 	tmp = STG_READ_REG(DACOverlayVtDec);	/* Decimation */
@@ -471,6 +474,9 @@ int SetOverlayViewPort(volatile STG4000REG __iomem *pSTGReg,
 		 */
 		ulScaleLeft = ulSrcLeft;
 
+		if ((ulRight - ulLeft + 2) == 0)
+			return -EINVAL;
+
 		/* shift fxscale until it is in the range of the scaler */
 		ulhDecim = 0;
 		ulScale = (((ulSrcRight - ulSrcLeft) - 1) << (11 - ulhDecim)) / (ulRight - ulLeft + 2);
-- 
2.17.6


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

* [PATCH] video: fbdev: kyrofb: fix a DoS bug by restricting user input
@ 2021-07-13 12:51 ` Zheyu Ma
  0 siblings, 0 replies; 3+ messages in thread
From: Zheyu Ma @ 2021-07-13 12:51 UTC (permalink / raw)
  To: dri-devel; +Cc: security, linux-fbdev, Zheyu Ma, 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.

Fix this by checking if the divisor is 0

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>
---
 drivers/video/fbdev/kyro/STG4000OverlayDevice.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/video/fbdev/kyro/STG4000OverlayDevice.c b/drivers/video/fbdev/kyro/STG4000OverlayDevice.c
index 9fde0e3b69ec..29d692fe5e75 100644
--- a/drivers/video/fbdev/kyro/STG4000OverlayDevice.c
+++ b/drivers/video/fbdev/kyro/STG4000OverlayDevice.c
@@ -407,6 +407,9 @@ int SetOverlayViewPort(volatile STG4000REG __iomem *pSTGReg,
 		ulVertDecFactor = 1;
 	}
 
+	if ((ulDest + 1) == 0)
+		return -EINVAL;
+
 	ulDacYScale = ((ulSrc - 1) * 2048) / (ulDest + 1);
 
 	tmp = STG_READ_REG(DACOverlayVtDec);	/* Decimation */
@@ -471,6 +474,9 @@ int SetOverlayViewPort(volatile STG4000REG __iomem *pSTGReg,
 		 */
 		ulScaleLeft = ulSrcLeft;
 
+		if ((ulRight - ulLeft + 2) == 0)
+			return -EINVAL;
+
 		/* shift fxscale until it is in the range of the scaler */
 		ulhDecim = 0;
 		ulScale = (((ulSrcRight - ulSrcLeft) - 1) << (11 - ulhDecim)) / (ulRight - ulLeft + 2);
-- 
2.17.6


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

* Re: [PATCH] video: fbdev: kyrofb: fix a DoS bug by restricting user input
  2021-07-13 12:51 ` Zheyu Ma
  (?)
@ 2021-07-13 19:46 ` Sam Ravnborg
  -1 siblings, 0 replies; 3+ messages in thread
From: Sam Ravnborg @ 2021-07-13 19:46 UTC (permalink / raw)
  To: Zheyu Ma; +Cc: security, linux-fbdev, dri-devel, linux-kernel

Hi 
On Tue, Jul 13, 2021 at 12:51:14PM +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.
> 
> Fix this by checking if the divisor is 0

This fix is trying to avoid the situation on a too low layer.
Could you please try to look at validating the inputs on a much higher
level, in kyro_dev_overlay_viewport_set().
Then the checks are much more obvious and you are more likely to catch a
number of similar bugs that the test just fails to trigger for now.

	Sam

> 
> 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>
> ---
>  drivers/video/fbdev/kyro/STG4000OverlayDevice.c | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/drivers/video/fbdev/kyro/STG4000OverlayDevice.c b/drivers/video/fbdev/kyro/STG4000OverlayDevice.c
> index 9fde0e3b69ec..29d692fe5e75 100644
> --- a/drivers/video/fbdev/kyro/STG4000OverlayDevice.c
> +++ b/drivers/video/fbdev/kyro/STG4000OverlayDevice.c
> @@ -407,6 +407,9 @@ int SetOverlayViewPort(volatile STG4000REG __iomem *pSTGReg,
>  		ulVertDecFactor = 1;
>  	}
>  
> +	if ((ulDest + 1) == 0)
> +		return -EINVAL;
> +
>  	ulDacYScale = ((ulSrc - 1) * 2048) / (ulDest + 1);
>  
>  	tmp = STG_READ_REG(DACOverlayVtDec);	/* Decimation */
> @@ -471,6 +474,9 @@ int SetOverlayViewPort(volatile STG4000REG __iomem *pSTGReg,
>  		 */
>  		ulScaleLeft = ulSrcLeft;
>  
> +		if ((ulRight - ulLeft + 2) == 0)
> +			return -EINVAL;
> +
>  		/* shift fxscale until it is in the range of the scaler */
>  		ulhDecim = 0;
>  		ulScale = (((ulSrcRight - ulSrcLeft) - 1) << (11 - ulhDecim)) / (ulRight - ulLeft + 2);
> -- 
> 2.17.6

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

end of thread, other threads:[~2021-07-13 19:46 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-13 12:51 [PATCH] video: fbdev: kyrofb: fix a DoS bug by restricting user input Zheyu Ma
2021-07-13 12:51 ` Zheyu Ma
2021-07-13 19:46 ` Sam Ravnborg

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.