From: Daniel Vetter <daniel@ffwll.ch>
To: Javier Martinez Canillas <javierm@redhat.com>
Cc: Thomas Zimmermann <tzimmermann@suse.de>,
Andrzej Hajda <andrzej.hajda@intel.com>,
linux-kernel@vger.kernel.org, linux-fbdev@vger.kernel.org,
Daniel Vetter <daniel.vetter@ffwll.ch>,
Helge Deller <deller@gmx.de>,
dri-devel@lists.freedesktop.org,
Daniel Vetter <daniel.vetter@intel.com>
Subject: Re: [PATCH v3 1/4] fbdev: Prevent possible use-after-free in fb_release()
Date: Wed, 11 May 2022 15:15:56 +0200 [thread overview]
Message-ID: <Ynu3DJJJV7TaSzfl@phenom.ffwll.local> (raw)
In-Reply-To: <2c59cd79-76d4-7829-e1db-88bc31396c8a@redhat.com>
On Mon, May 09, 2022 at 10:00:41PM +0200, Javier Martinez Canillas wrote:
> Hello Thomas,
>
> On 5/9/22 20:32, Thomas Zimmermann wrote:
> > Hi
> >
> > Am 09.05.22 um 18:33 schrieb Javier Martinez Canillas:
> >> On 5/9/22 17:51, Andrzej Hajda wrote:
> >>
> >> [snip]
> >>
> >>>>>> +
> >>>>> Regarding drm:
> >>>>> What about drm_fb_helper_fini? It calls also framebuffer_release and is
> >>>>> called often from _remove paths (checked intel/radeon/nouveau). I guess
> >>>>> it should be fixed as well. Do you plan to fix it?
> >>>>>
> >>>> I think you are correct. Maybe we need something like the following?
> >>>>
> >>>> diff --git a/drivers/gpu/drm/drm_fb_helper.c b/drivers/gpu/drm/drm_fb_helper.c
> >>>> index d265a73313c9..b09598f7af28 100644
> >>>> --- a/drivers/gpu/drm/drm_fb_helper.c
> >>>> +++ b/drivers/gpu/drm/drm_fb_helper.c
> >>>> @@ -631,7 +631,6 @@ void drm_fb_helper_fini(struct drm_fb_helper *fb_helper)
> >>>> if (info) {
> >>>> if (info->cmap.len)
> >>>> fb_dealloc_cmap(&info->cmap);
> >>>> - framebuffer_release(info);
> >
> > After reviewing that code, drm_fb_helper_fini() appears to be called
> > from .fb_destroy (see drm_fbdev_release). The code is hard to follow
> > though. If there another way of releasing the framebuffer here?
> >
>
> Andrzej mentioned intel/radeon/nouveau as example, I only looked at i915
> and the call chain is the following as far as I can tell:
>
> struct pci_driver i915_pci_driver = {
> ...
> .remove = i915_pci_remove,
> ...
> };
>
>
> i915_driver_remove
> intel_modeset_driver_remove_noirq
> intel_fbdev_fini
> intel_fbdev_destroy
> drm_fb_helper_fini
> framebuffer_release
>
> So my underdestanding is that if a program has the emulated fbdev device
> opened and the i915 module is removed, then a use-after-free would be
> triggered on drm_fbdev_fb_destroy() once the program closes the device:
>
> drm_fbdev_fb_destroy
> drm_fbdev_release(info->par); <-- info was already freed on .remove
Yeah the old drivers that haven't switched over to the drm_client based
fbdev emulations are all kinds of wrong and release it too early.
Note that they don't use the provided ->remove hook, since that would
result in double-cleanup like you point out. Those old drivers work more
like all the other fbdev drivers where all the cleanup is done in
->remove, and if it's a real hotunplug you just die in fire :-/
Switching them all over to the drm_client based fbdev helpers and
unexporting these old (dangerous!) functions would be really neat. But
it's also a loooooot of work, and generally those big drivers don't get
hotunplugged.
-Daniel
--
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
next prev parent reply other threads:[~2022-05-11 13:16 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-05 21:59 [PATCH v3 0/4] fbdev: Fix use-after-free caused by wrong fb_info cleanup in drivers Javier Martinez Canillas
2022-05-05 22:04 ` [PATCH v3 1/4] fbdev: Prevent possible use-after-free in fb_release() Javier Martinez Canillas
2022-05-09 14:56 ` Andrzej Hajda
2022-05-09 15:30 ` Javier Martinez Canillas
2022-05-09 15:51 ` Andrzej Hajda
2022-05-09 16:33 ` Javier Martinez Canillas
2022-05-09 18:12 ` Thomas Zimmermann
2022-05-09 20:03 ` Javier Martinez Canillas
2022-05-09 22:22 ` Andrzej Hajda
2022-05-09 22:42 ` Javier Martinez Canillas
2022-05-10 7:19 ` Andrzej Hajda
2022-05-10 7:50 ` Javier Martinez Canillas
2022-05-11 13:18 ` Daniel Vetter
2022-05-10 8:04 ` Thomas Zimmermann
2022-05-10 8:30 ` Javier Martinez Canillas
2022-05-10 8:37 ` Thomas Zimmermann
2022-05-10 8:50 ` Thomas Zimmermann
2022-05-10 9:06 ` Javier Martinez Canillas
2022-05-10 9:39 ` Thomas Zimmermann
2022-05-10 9:44 ` Javier Martinez Canillas
2022-05-09 18:32 ` Thomas Zimmermann
2022-05-09 20:00 ` Javier Martinez Canillas
2022-05-11 13:15 ` Daniel Vetter [this message]
2022-05-05 22:04 ` [PATCH v3 2/4] fbdev: simplefb: Cleanup fb_info in .fb_destroy rather than .remove Javier Martinez Canillas
2022-05-05 22:05 ` [PATCH v3 3/4] fbdev: efifb: " Javier Martinez Canillas
2022-05-06 13:07 ` Andrzej Hajda
2022-05-06 13:18 ` Javier Martinez Canillas
2022-05-08 15:40 ` [fbdev] c6a2b1a999: BUG:KASAN:use-after-free_in_efifb_destroy kernel test robot
2022-05-05 22:06 ` [PATCH v3 4/4] fbdev: vesafb: Cleanup fb_info in .fb_destroy rather than .remove Javier Martinez Canillas
2022-05-06 7:34 ` [PATCH v3 0/4] fbdev: Fix use-after-free caused by wrong fb_info cleanup in drivers Javier Martinez Canillas
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=Ynu3DJJJV7TaSzfl@phenom.ffwll.local \
--to=daniel@ffwll.ch \
--cc=andrzej.hajda@intel.com \
--cc=daniel.vetter@ffwll.ch \
--cc=daniel.vetter@intel.com \
--cc=deller@gmx.de \
--cc=dri-devel@lists.freedesktop.org \
--cc=javierm@redhat.com \
--cc=linux-fbdev@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=tzimmermann@suse.de \
/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