public inbox for stable@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] fbmem: Reject FB_ACTIVATE_KD_TEXT from userspace
@ 2023-04-04 19:39 Daniel Vetter
  2023-04-11 13:44 ` Daniel Vetter
  2023-04-11 14:03 ` Javier Martinez Canillas
  0 siblings, 2 replies; 6+ messages in thread
From: Daniel Vetter @ 2023-04-04 19:39 UTC (permalink / raw)
  To: Intel Graphics Development
  Cc: Daniel Vetter, Daniel Vetter, Alex Deucher, shlomo,
	Michel Dänzer, Noralf Trønnes, Thomas Zimmermann,
	Maarten Lankhorst, Maxime Ripard, David Airlie, Daniel Vetter,
	dri-devel, stable, Bartlomiej Zolnierkiewicz, Geert Uytterhoeven,
	Nathan Chancellor, Qiujun Huang, Peter Rosin, linux-fbdev,
	Helge Deller, Sam Ravnborg, Geert Uytterhoeven, Samuel Thibault,
	Tetsuo Handa, Shigeru Yoshida

This is an oversight from dc5bdb68b5b3 ("drm/fb-helper: Fix vt
restore") - I failed to realize that nasty userspace could set this.

It's not pretty to mix up kernel-internal and userspace uapi flags
like this, but since the entire fb_var_screeninfo structure is uapi
we'd need to either add a new parameter to the ->fb_set_par callback
and fb_set_par() function, which has a _lot_ of users. Or some other
fairly ugly side-channel int fb_info. Neither is a pretty prospect.

Instead just correct the issue at hand by filtering out this
kernel-internal flag in the ioctl handling code.

Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
Fixes: dc5bdb68b5b3 ("drm/fb-helper: Fix vt restore")
Cc: Alex Deucher <alexander.deucher@amd.com>
Cc: shlomo@fastmail.com
Cc: Michel Dänzer <michel@daenzer.net>
Cc: Noralf Trønnes <noralf@tronnes.org>
Cc: Thomas Zimmermann <tzimmermann@suse.de>
Cc: Daniel Vetter <daniel.vetter@intel.com>
Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
Cc: Maxime Ripard <mripard@kernel.org>
Cc: David Airlie <airlied@linux.ie>
Cc: Daniel Vetter <daniel@ffwll.ch>
Cc: dri-devel@lists.freedesktop.org
Cc: <stable@vger.kernel.org> # v5.7+
Cc: Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>
Cc: Geert Uytterhoeven <geert@linux-m68k.org>
Cc: Nathan Chancellor <natechancellor@gmail.com>
Cc: Qiujun Huang <hqjagain@gmail.com>
Cc: Peter Rosin <peda@axentia.se>
Cc: linux-fbdev@vger.kernel.org
Cc: Helge Deller <deller@gmx.de>
Cc: Sam Ravnborg <sam@ravnborg.org>
Cc: Geert Uytterhoeven <geert+renesas@glider.be>
Cc: Samuel Thibault <samuel.thibault@ens-lyon.org>
Cc: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Cc: Shigeru Yoshida <syoshida@redhat.com>
---
 drivers/video/fbdev/core/fbmem.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/video/fbdev/core/fbmem.c b/drivers/video/fbdev/core/fbmem.c
index 875541ff185b..3fd95a79e4c3 100644
--- a/drivers/video/fbdev/core/fbmem.c
+++ b/drivers/video/fbdev/core/fbmem.c
@@ -1116,6 +1116,8 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
 	case FBIOPUT_VSCREENINFO:
 		if (copy_from_user(&var, argp, sizeof(var)))
 			return -EFAULT;
+		/* only for kernel-internal use */
+		var.activate &= ~FB_ACTIVATE_KD_TEXT;
 		console_lock();
 		lock_fb_info(info);
 		ret = fbcon_modechange_possible(info, &var);
-- 
2.40.0


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

* Re: [PATCH] fbmem: Reject FB_ACTIVATE_KD_TEXT from userspace
  2023-04-04 19:39 [PATCH] fbmem: Reject FB_ACTIVATE_KD_TEXT from userspace Daniel Vetter
@ 2023-04-11 13:44 ` Daniel Vetter
  2023-04-11 13:58   ` Maarten Lankhorst
  2023-04-11 15:57   ` Geert Uytterhoeven
  2023-04-11 14:03 ` Javier Martinez Canillas
  1 sibling, 2 replies; 6+ messages in thread
From: Daniel Vetter @ 2023-04-11 13:44 UTC (permalink / raw)
  To: Intel Graphics Development
  Cc: Daniel Vetter, Daniel Vetter, Alex Deucher, shlomo,
	Michel Dänzer, Noralf Trønnes, Thomas Zimmermann,
	Maarten Lankhorst, Maxime Ripard, David Airlie, Daniel Vetter,
	dri-devel, stable, Bartlomiej Zolnierkiewicz, Geert Uytterhoeven,
	Nathan Chancellor, Qiujun Huang, Peter Rosin, linux-fbdev,
	Helge Deller, Sam Ravnborg, Geert Uytterhoeven, Samuel Thibault,
	Tetsuo Handa, Shigeru Yoshida

On Tue, Apr 04, 2023 at 09:39:34PM +0200, Daniel Vetter wrote:
> This is an oversight from dc5bdb68b5b3 ("drm/fb-helper: Fix vt
> restore") - I failed to realize that nasty userspace could set this.
> 
> It's not pretty to mix up kernel-internal and userspace uapi flags
> like this, but since the entire fb_var_screeninfo structure is uapi
> we'd need to either add a new parameter to the ->fb_set_par callback
> and fb_set_par() function, which has a _lot_ of users. Or some other
> fairly ugly side-channel int fb_info. Neither is a pretty prospect.
> 
> Instead just correct the issue at hand by filtering out this
> kernel-internal flag in the ioctl handling code.
> 
> Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
> Fixes: dc5bdb68b5b3 ("drm/fb-helper: Fix vt restore")
> Cc: Alex Deucher <alexander.deucher@amd.com>
> Cc: shlomo@fastmail.com
> Cc: Michel Dänzer <michel@daenzer.net>
> Cc: Noralf Trønnes <noralf@tronnes.org>
> Cc: Thomas Zimmermann <tzimmermann@suse.de>
> Cc: Daniel Vetter <daniel.vetter@intel.com>
> Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
> Cc: Maxime Ripard <mripard@kernel.org>
> Cc: David Airlie <airlied@linux.ie>
> Cc: Daniel Vetter <daniel@ffwll.ch>
> Cc: dri-devel@lists.freedesktop.org
> Cc: <stable@vger.kernel.org> # v5.7+
> Cc: Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>
> Cc: Geert Uytterhoeven <geert@linux-m68k.org>
> Cc: Nathan Chancellor <natechancellor@gmail.com>
> Cc: Qiujun Huang <hqjagain@gmail.com>
> Cc: Peter Rosin <peda@axentia.se>
> Cc: linux-fbdev@vger.kernel.org
> Cc: Helge Deller <deller@gmx.de>
> Cc: Sam Ravnborg <sam@ravnborg.org>
> Cc: Geert Uytterhoeven <geert+renesas@glider.be>
> Cc: Samuel Thibault <samuel.thibault@ens-lyon.org>
> Cc: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
> Cc: Shigeru Yoshida <syoshida@redhat.com>

An Ack on this (or a better idea) would be great, so I can stuff it into
-fixes.

Thanks, Daniel

> ---
>  drivers/video/fbdev/core/fbmem.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/video/fbdev/core/fbmem.c b/drivers/video/fbdev/core/fbmem.c
> index 875541ff185b..3fd95a79e4c3 100644
> --- a/drivers/video/fbdev/core/fbmem.c
> +++ b/drivers/video/fbdev/core/fbmem.c
> @@ -1116,6 +1116,8 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
>  	case FBIOPUT_VSCREENINFO:
>  		if (copy_from_user(&var, argp, sizeof(var)))
>  			return -EFAULT;
> +		/* only for kernel-internal use */
> +		var.activate &= ~FB_ACTIVATE_KD_TEXT;
>  		console_lock();
>  		lock_fb_info(info);
>  		ret = fbcon_modechange_possible(info, &var);
> -- 
> 2.40.0
> 

-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch

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

* Re: [PATCH] fbmem: Reject FB_ACTIVATE_KD_TEXT from userspace
  2023-04-11 13:44 ` Daniel Vetter
@ 2023-04-11 13:58   ` Maarten Lankhorst
  2023-04-11 15:57   ` Geert Uytterhoeven
  1 sibling, 0 replies; 6+ messages in thread
From: Maarten Lankhorst @ 2023-04-11 13:58 UTC (permalink / raw)
  To: Daniel Vetter, Intel Graphics Development
  Cc: Daniel Vetter, Daniel Vetter, Alex Deucher, shlomo,
	Michel Dänzer, Noralf Trønnes, Thomas Zimmermann,
	Maxime Ripard, David Airlie, dri-devel, stable,
	Bartlomiej Zolnierkiewicz, Geert Uytterhoeven, Nathan Chancellor,
	Qiujun Huang, Peter Rosin, linux-fbdev, Helge Deller,
	Sam Ravnborg, Geert Uytterhoeven, Samuel Thibault, Tetsuo Handa,
	Shigeru Yoshida


On 2023-04-11 15:44, Daniel Vetter wrote:
> On Tue, Apr 04, 2023 at 09:39:34PM +0200, Daniel Vetter wrote:
>> This is an oversight from dc5bdb68b5b3 ("drm/fb-helper: Fix vt
>> restore") - I failed to realize that nasty userspace could set this.
>>
>> It's not pretty to mix up kernel-internal and userspace uapi flags
>> like this, but since the entire fb_var_screeninfo structure is uapi
>> we'd need to either add a new parameter to the ->fb_set_par callback
>> and fb_set_par() function, which has a _lot_ of users. Or some other
>> fairly ugly side-channel int fb_info. Neither is a pretty prospect.
>>
>> Instead just correct the issue at hand by filtering out this
>> kernel-internal flag in the ioctl handling code.
>>
>> Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
>> Fixes: dc5bdb68b5b3 ("drm/fb-helper: Fix vt restore")
>> Cc: Alex Deucher <alexander.deucher@amd.com>
>> Cc: shlomo@fastmail.com
>> Cc: Michel Dänzer <michel@daenzer.net>
>> Cc: Noralf Trønnes <noralf@tronnes.org>
>> Cc: Thomas Zimmermann <tzimmermann@suse.de>
>> Cc: Daniel Vetter <daniel.vetter@intel.com>
>> Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
>> Cc: Maxime Ripard <mripard@kernel.org>
>> Cc: David Airlie <airlied@linux.ie>
>> Cc: Daniel Vetter <daniel@ffwll.ch>
>> Cc: dri-devel@lists.freedesktop.org
>> Cc: <stable@vger.kernel.org> # v5.7+
>> Cc: Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>
>> Cc: Geert Uytterhoeven <geert@linux-m68k.org>
>> Cc: Nathan Chancellor <natechancellor@gmail.com>
>> Cc: Qiujun Huang <hqjagain@gmail.com>
>> Cc: Peter Rosin <peda@axentia.se>
>> Cc: linux-fbdev@vger.kernel.org
>> Cc: Helge Deller <deller@gmx.de>
>> Cc: Sam Ravnborg <sam@ravnborg.org>
>> Cc: Geert Uytterhoeven <geert+renesas@glider.be>
>> Cc: Samuel Thibault <samuel.thibault@ens-lyon.org>
>> Cc: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
>> Cc: Shigeru Yoshida <syoshida@redhat.com>
> An Ack on this (or a better idea) would be great, so I can stuff it into
> -fixes.
Acked-by: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>

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

* Re: [PATCH] fbmem: Reject FB_ACTIVATE_KD_TEXT from userspace
  2023-04-04 19:39 [PATCH] fbmem: Reject FB_ACTIVATE_KD_TEXT from userspace Daniel Vetter
  2023-04-11 13:44 ` Daniel Vetter
@ 2023-04-11 14:03 ` Javier Martinez Canillas
  2023-04-11 14:25   ` Daniel Vetter
  1 sibling, 1 reply; 6+ messages in thread
From: Javier Martinez Canillas @ 2023-04-11 14:03 UTC (permalink / raw)
  To: Daniel Vetter, Intel Graphics Development
  Cc: linux-fbdev, Shigeru Yoshida, Geert Uytterhoeven, David Airlie,
	Daniel Vetter, dri-devel, Daniel Vetter, Sam Ravnborg,
	Helge Deller, Tetsuo Handa, Geert Uytterhoeven, Samuel Thibault,
	Thomas Zimmermann, Bartlomiej Zolnierkiewicz, Michel Dänzer,
	shlomo, Nathan Chancellor, stable, Noralf Trønnes,
	Alex Deucher, Peter Rosin, Qiujun Huang

Daniel Vetter <daniel.vetter@ffwll.ch> writes:

> This is an oversight from dc5bdb68b5b3 ("drm/fb-helper: Fix vt
> restore") - I failed to realize that nasty userspace could set this.
>
> It's not pretty to mix up kernel-internal and userspace uapi flags
> like this, but since the entire fb_var_screeninfo structure is uapi
> we'd need to either add a new parameter to the ->fb_set_par callback
> and fb_set_par() function, which has a _lot_ of users. Or some other
> fairly ugly side-channel int fb_info. Neither is a pretty prospect.
>
> Instead just correct the issue at hand by filtering out this
> kernel-internal flag in the ioctl handling code.
>
> Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
> Fixes: dc5bdb68b5b3 ("drm/fb-helper: Fix vt restore")

[..]

> diff --git a/drivers/video/fbdev/core/fbmem.c b/drivers/video/fbdev/core/fbmem.c
> index 875541ff185b..3fd95a79e4c3 100644
> --- a/drivers/video/fbdev/core/fbmem.c
> +++ b/drivers/video/fbdev/core/fbmem.c
> @@ -1116,6 +1116,8 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
>  	case FBIOPUT_VSCREENINFO:
>  		if (copy_from_user(&var, argp, sizeof(var)))
>  			return -EFAULT;
> +		/* only for kernel-internal use */
> +		var.activate &= ~FB_ACTIVATE_KD_TEXT;
>  		console_lock();

I don't have a better idea on how to fix this and as you said the whole
struct fb_var_screeninfo is an uAPI anyways...

Reviewed-by: Javier Martinez Canillas <javierm@redhat.com>

-- 
Best regards,

Javier Martinez Canillas
Core Platforms
Red Hat


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

* Re: [PATCH] fbmem: Reject FB_ACTIVATE_KD_TEXT from userspace
  2023-04-11 14:03 ` Javier Martinez Canillas
@ 2023-04-11 14:25   ` Daniel Vetter
  0 siblings, 0 replies; 6+ messages in thread
From: Daniel Vetter @ 2023-04-11 14:25 UTC (permalink / raw)
  To: Javier Martinez Canillas
  Cc: Daniel Vetter, Intel Graphics Development, linux-fbdev,
	Shigeru Yoshida, Geert Uytterhoeven, David Airlie, dri-devel,
	Daniel Vetter, Sam Ravnborg, Helge Deller, Tetsuo Handa,
	Geert Uytterhoeven, Samuel Thibault, Thomas Zimmermann,
	Bartlomiej Zolnierkiewicz, Michel Dänzer, shlomo,
	Nathan Chancellor, stable, Noralf Trønnes, Alex Deucher,
	Peter Rosin, Qiujun Huang

On Tue, Apr 11, 2023 at 04:03:24PM +0200, Javier Martinez Canillas wrote:
> Daniel Vetter <daniel.vetter@ffwll.ch> writes:
> 
> > This is an oversight from dc5bdb68b5b3 ("drm/fb-helper: Fix vt
> > restore") - I failed to realize that nasty userspace could set this.
> >
> > It's not pretty to mix up kernel-internal and userspace uapi flags
> > like this, but since the entire fb_var_screeninfo structure is uapi
> > we'd need to either add a new parameter to the ->fb_set_par callback
> > and fb_set_par() function, which has a _lot_ of users. Or some other
> > fairly ugly side-channel int fb_info. Neither is a pretty prospect.
> >
> > Instead just correct the issue at hand by filtering out this
> > kernel-internal flag in the ioctl handling code.
> >
> > Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
> > Fixes: dc5bdb68b5b3 ("drm/fb-helper: Fix vt restore")
> 
> [..]
> 
> > diff --git a/drivers/video/fbdev/core/fbmem.c b/drivers/video/fbdev/core/fbmem.c
> > index 875541ff185b..3fd95a79e4c3 100644
> > --- a/drivers/video/fbdev/core/fbmem.c
> > +++ b/drivers/video/fbdev/core/fbmem.c
> > @@ -1116,6 +1116,8 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
> >  	case FBIOPUT_VSCREENINFO:
> >  		if (copy_from_user(&var, argp, sizeof(var)))
> >  			return -EFAULT;
> > +		/* only for kernel-internal use */
> > +		var.activate &= ~FB_ACTIVATE_KD_TEXT;
> >  		console_lock();
> 
> I don't have a better idea on how to fix this and as you said the whole
> struct fb_var_screeninfo is an uAPI anyways...
> 
> Reviewed-by: Javier Martinez Canillas <javierm@redhat.com>

Thanks for taking a look, merged to drm-misc-fixes.

> 
> -- 
> Best regards,
> 
> Javier Martinez Canillas
> Core Platforms
> Red Hat
> 

-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch

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

* Re: [PATCH] fbmem: Reject FB_ACTIVATE_KD_TEXT from userspace
  2023-04-11 13:44 ` Daniel Vetter
  2023-04-11 13:58   ` Maarten Lankhorst
@ 2023-04-11 15:57   ` Geert Uytterhoeven
  1 sibling, 0 replies; 6+ messages in thread
From: Geert Uytterhoeven @ 2023-04-11 15:57 UTC (permalink / raw)
  To: Daniel Vetter
  Cc: Intel Graphics Development, Daniel Vetter, Alex Deucher, shlomo,
	Michel Dänzer, Noralf Trønnes, Thomas Zimmermann,
	Maarten Lankhorst, Maxime Ripard, David Airlie, dri-devel, stable,
	Bartlomiej Zolnierkiewicz, Nathan Chancellor, Qiujun Huang,
	Peter Rosin, linux-fbdev, Helge Deller, Sam Ravnborg,
	Samuel Thibault, Tetsuo Handa, Shigeru Yoshida

Hi Daniel,

On Tue, Apr 11, 2023 at 3:44 PM Daniel Vetter <daniel@ffwll.ch> wrote:
> On Tue, Apr 04, 2023 at 09:39:34PM +0200, Daniel Vetter wrote:
> > This is an oversight from dc5bdb68b5b3 ("drm/fb-helper: Fix vt
> > restore") - I failed to realize that nasty userspace could set this.
> >
> > It's not pretty to mix up kernel-internal and userspace uapi flags
> > like this, but since the entire fb_var_screeninfo structure is uapi
> > we'd need to either add a new parameter to the ->fb_set_par callback
> > and fb_set_par() function, which has a _lot_ of users. Or some other
> > fairly ugly side-channel int fb_info. Neither is a pretty prospect.
> >
> > Instead just correct the issue at hand by filtering out this
> > kernel-internal flag in the ioctl handling code.
> >
> > Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
> > Fixes: dc5bdb68b5b3 ("drm/fb-helper: Fix vt restore")

> An Ack on this (or a better idea) would be great, so I can stuff it into
> -fixes.

I don't understand what the original commit this fixes is doing anyway...

> > --- a/drivers/video/fbdev/core/fbmem.c
> > +++ b/drivers/video/fbdev/core/fbmem.c
> > @@ -1116,6 +1116,8 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
> >       case FBIOPUT_VSCREENINFO:
> >               if (copy_from_user(&var, argp, sizeof(var)))
> >                       return -EFAULT;
> > +             /* only for kernel-internal use */
> > +             var.activate &= ~FB_ACTIVATE_KD_TEXT;
> >               console_lock();
> >               lock_fb_info(info);
> >               ret = fbcon_modechange_possible(info, &var);

Perhaps FB_ACTIVATE_KD_TEXT should be removed (marked as
reserved) from include/uapi/linux/fb.h, too?

Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

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

end of thread, other threads:[~2023-04-11 15:58 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-04-04 19:39 [PATCH] fbmem: Reject FB_ACTIVATE_KD_TEXT from userspace Daniel Vetter
2023-04-11 13:44 ` Daniel Vetter
2023-04-11 13:58   ` Maarten Lankhorst
2023-04-11 15:57   ` Geert Uytterhoeven
2023-04-11 14:03 ` Javier Martinez Canillas
2023-04-11 14:25   ` Daniel Vetter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox