mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Thomas Zimmermann <tzimmermann@suse.de>
To: Sui Jingfeng <15330273260@189.cn>,
	Maarten Lankhorst <maarten.lankhorst@linux.intel.com>,
	Maxime Ripard <mripard@kernel.org>,
	David Airlie <airlied@gmail.com>, Li Yi <liyi@loongson.cn>,
	Helge Deller <deller@gmx.de>,
	Lucas De Marchi <lucas.demarchi@intel.com>,
	linux-kernel@vger.kernel.org, linux-fbdev@vger.kernel.org,
	dri-devel@lists.freedesktop.org,
	loongson-kernel@lists.loongnix.cn
Subject: Re: [PATCH] drm/fbdev-generic: fix potential out-of-bounds access
Date: Thu, 13 Apr 2023 21:20:23 +0200	[thread overview]
Message-ID: <1bbc7228-c2fe-0af0-c15c-b378bc4d111c@suse.de> (raw)
In-Reply-To: <ZDhQW6El6ztyHK4M@phenom.ffwll.local>


[-- Attachment #1.1: Type: text/plain, Size: 2503 bytes --]

Hi

Am 13.04.23 um 20:56 schrieb Daniel Vetter:
[...]
> 
> This should switch the existing code over to using drm_framebuffer instead
> of fbdev:
> 
> 
> diff --git a/drivers/gpu/drm/drm_fb_helper.c b/drivers/gpu/drm/drm_fb_helper.c
> index ef4eb8b12766..99ca69dd432f 100644
> --- a/drivers/gpu/drm/drm_fb_helper.c
> +++ b/drivers/gpu/drm/drm_fb_helper.c
> @@ -647,22 +647,26 @@ static void drm_fb_helper_damage(struct drm_fb_helper *helper, u32 x, u32 y,
>   static void drm_fb_helper_memory_range_to_clip(struct fb_info *info, off_t off, size_t len,
>   					       struct drm_rect *clip)
>   {
> +	struct drm_fb_helper *helper = info->par;
> +
>   	off_t end = off + len;
>   	u32 x1 = 0;
>   	u32 y1 = off / info->fix.line_length;
> -	u32 x2 = info->var.xres;
> -	u32 y2 = DIV_ROUND_UP(end, info->fix.line_length);
> +	u32 x2 = helper->fb->height;
> +	unsigned stride = helper->fb->pitches[0];
> +	u32 y2 = DIV_ROUND_UP(end, stride);
> +	int bpp = drm_format_info_bpp(helper->fb->format, 0);

Please DONT do that. The code here is fbdev code and shouldn't bother 
about DRM data structures. Actually, it shouldn't be here: a number of 
fbdev drivers with deferred I/O contain similar code and the fbdev 
module should provide us with a helper. (I think I even had some patches 
somewhere.)

Best regards
Thomas

>   
>   	if ((y2 - y1) == 1) {
>   		/*
>   		 * We've only written to a single scanline. Try to reduce
>   		 * the number of horizontal pixels that need an update.
>   		 */
> -		off_t bit_off = (off % info->fix.line_length) * 8;
> -		off_t bit_end = (end % info->fix.line_length) * 8;
> +		off_t bit_off = (off % stride) * 8;
> +		off_t bit_end = (end % stride) * 8;
>   
> -		x1 = bit_off / info->var.bits_per_pixel;
> -		x2 = DIV_ROUND_UP(bit_end, info->var.bits_per_pixel);
> +		x1 = bit_off / bpp;
> +		x2 = DIV_ROUND_UP(bit_end, bpp);
>   	}
>   
>   	drm_rect_init(clip, x1, y1, x2 - x1, y2 - y1);
> 
>>
>>>>>>>> +  screen_size = sizes->surface_height * buffer->fb->pitches[0];
>>>>>>>> +
>>>>>>>>              screen_buffer = vzalloc(screen_size);
>>>>>>>>              if (!screen_buffer) {
>>>>>>>>                      ret = -ENOMEM;
>>>>>>> Cheers, Daniel
>>>>>>>
>>>>>>>> --
>>>>>>>> 2.25.1
>>>>>>>>
>>>
>>>
> 

-- 
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Maxfeldstr. 5, 90409 Nürnberg, Germany
(HRB 36809, AG Nürnberg)
Geschäftsführer: Ivo Totev

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 840 bytes --]

  reply	other threads:[~2023-04-13 19:20 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-09 13:21 Sui Jingfeng
2023-04-11 14:53 ` Daniel Vetter
2023-04-12 17:13   ` Sui Jingfeng
2023-04-12 17:22     ` Sui Jingfeng
2023-04-12 17:44     ` Daniel Vetter
2023-04-13 15:35       ` Sui Jingfeng
2023-04-13 15:56         ` Daniel Vetter
2023-04-13 17:00           ` Sui Jingfeng
2023-04-13 18:56             ` Daniel Vetter
2023-04-13 19:20               ` Thomas Zimmermann [this message]
2023-04-13 20:01                 ` Daniel Vetter
2023-04-14  4:23                   ` Sui Jingfeng
2023-04-14  5:36                     ` Daniel Vetter
2023-04-14  7:34                       ` Thomas Zimmermann
2023-04-14  7:39                         ` Thomas Zimmermann
2023-04-14  7:56                         ` Daniel Vetter
2023-04-14 11:30                           ` Sui Jingfeng
2023-04-16  7:54                             ` Daniel Vetter
2023-04-17  7:17                           ` Thomas Zimmermann
2023-04-14  7:28                   ` Thomas Zimmermann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1bbc7228-c2fe-0af0-c15c-b378bc4d111c@suse.de \
    --to=tzimmermann@suse.de \
    --cc=15330273260@189.cn \
    --cc=airlied@gmail.com \
    --cc=deller@gmx.de \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=linux-fbdev@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=liyi@loongson.cn \
    --cc=loongson-kernel@lists.loongnix.cn \
    --cc=lucas.demarchi@intel.com \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=mripard@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®