Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp975349iob; Thu, 12 May 2022 08:32:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyve/0utSkDbp1iIcZ49G0Nh6XTD2BPUkOI6pH+akXyCzWUDdiQ5dQyp1oVUHlgxkcomSY+ X-Received: by 2002:a17:907:97d5:b0:6f4:29cb:399c with SMTP id js21-20020a17090797d500b006f429cb399cmr427725ejc.530.1652369567170; Thu, 12 May 2022 08:32:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652369567; cv=none; d=google.com; s=arc-20160816; b=xuojVg9MsQYd0Jj2f6ZSobsG9zVXVrKmN5oDZgrogsRCFH5r+xF2CvPVlh3rBugeHb MW/4zvC5nYeVMoZ9edmBr4bJRfNc0QmArJZuJTvrm8Dw65qV4QVACei2K4whN0Y5s6lo nKA/y1/ptRxFr5zbVG3BSrB4Uc6H/9T2cD7JqeoWZ9wVSUjUmGUhXEkklv/7wPQ/mHYG V7ByW20J+onyu/xAXjhhATi9U3sIOrYDIzzqnbm1q+NPriRQHO+hSbt+39b9jPKDslXV kqCSU/FtdiylJZB0SgP1rIK8wH7uVELEvRn5AJOAHdEGAvfIqEzfs0yxxPygNbAMzZWb +HYQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:mail-followup-to:message-id:subject:cc:to:from:date :dkim-signature; bh=yKAX1BFitoF5KnIE0atLfue5Z05Vzelo2xc7M7PzQVc=; b=t7kqB0quXpoW+RHCDd47gXcES791dxaniDP15Zdfrb87XcIiL+L0qQKnYfZ+kAwy1P 0uQydwaOtHvIR/Vl7UxoKSpGa3qTQvYCB3v4GGDGNGeh8MIabD8z2zXFdzsCHQH61pim Q7e15Tjho7y2m8KXXpzeLjCc+gTQ2sSX4E86X9GRjfIdIu0i21moCAIKY/YpRBgYzNjs K6tJQewbrpwDabff4XkwLIhJ4P+offVijHfhCcDzDYEkxOyuZKouNfNYic1rOmZpMe4i oGvxeg+vnmikyr3KsAt9/vLHW0kgvRxW85swyyA8HglhM5cvpBBj2UQKxCcIiU5F7La9 /ZQg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ffwll.ch header.s=google header.b=Uven7JTz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id nd12-20020a170907628c00b006f3d331b455si6912489ejc.231.2022.05.12.08.32.19; Thu, 12 May 2022 08:32:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@ffwll.ch header.s=google header.b=Uven7JTz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243213AbiEKNQH (ORCPT + 99 others); Wed, 11 May 2022 09:16:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54734 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242588AbiEKNQE (ORCPT ); Wed, 11 May 2022 09:16:04 -0400 Received: from mail-ej1-x631.google.com (mail-ej1-x631.google.com [IPv6:2a00:1450:4864:20::631]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 40C9D2EA01 for ; Wed, 11 May 2022 06:16:02 -0700 (PDT) Received: by mail-ej1-x631.google.com with SMTP id ch13so3932882ejb.12 for ; Wed, 11 May 2022 06:16:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=date:from:to:cc:subject:message-id:mail-followup-to:references :mime-version:content-disposition:in-reply-to; bh=yKAX1BFitoF5KnIE0atLfue5Z05Vzelo2xc7M7PzQVc=; b=Uven7JTz762OOS3tIRaxkeeai+ObuaVDKDLwAeDRBCUN6bYFLFApz3TVF/1+VDO5TY IzqFAx87iX/LKixBIaJlt4Iih8fknchC+UWxXykiAGVO+NCAyhNBsyM6Ot9suClErx2v i3VjKym9eq6P1dW2YnbQOX6Ny5L5C9mf+cRz8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id :mail-followup-to:references:mime-version:content-disposition :in-reply-to; bh=yKAX1BFitoF5KnIE0atLfue5Z05Vzelo2xc7M7PzQVc=; b=en2aVjRLFfwD3djwgvHAHxCRtA/2Yg1VRAgTN21f8Hk3hYDDXub119bQtAXf287LNI F9BP2894HkmTCgbi/hzx7yNGVnPraPyMS2pceWPuUrijmDmMGDftDLp79u5Y9TnetPPt YJKZohA9ABojdAEEDO9clNwJlU0TTeJka4FQ42rYwiVrkcWrg/wBjtk/PEuqxYu1R/nG 6EswP8ow8+glfw6/9rviJ1C1iEBkUP2aSH2GhHBak2i6bEyXHI0k7/MszT8qfmjiScaK QngtVceX8wLxhsld3ucL5pIOmaz/0UYlneowhMWHIIgWqZyva3vM8+4DunbH2LamB8xf Y/Xw== X-Gm-Message-State: AOAM532QFg8EWOYOsXeq7tng0R0Z/zvZNXg08+ZL7LVoUoY4vTSn2K8Y 2gF/NYAlEd1kgknstIGkyYrGQg== X-Received: by 2002:a17:907:6e8b:b0:6fa:82f5:14bd with SMTP id sh11-20020a1709076e8b00b006fa82f514bdmr12877746ejc.182.1652274960045; Wed, 11 May 2022 06:16:00 -0700 (PDT) Received: from phenom.ffwll.local ([2a02:168:57f4:0:efd0:b9e5:5ae6:c2fa]) by smtp.gmail.com with ESMTPSA id md26-20020a170906ae9a00b006f3ef214e26sm974974ejb.140.2022.05.11.06.15.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 May 2022 06:15:58 -0700 (PDT) Date: Wed, 11 May 2022 15:15:56 +0200 From: Daniel Vetter To: Javier Martinez Canillas Cc: Thomas Zimmermann , Andrzej Hajda , linux-kernel@vger.kernel.org, linux-fbdev@vger.kernel.org, Daniel Vetter , Helge Deller , dri-devel@lists.freedesktop.org, Daniel Vetter Subject: Re: [PATCH v3 1/4] fbdev: Prevent possible use-after-free in fb_release() Message-ID: Mail-Followup-To: Javier Martinez Canillas , Thomas Zimmermann , Andrzej Hajda , linux-kernel@vger.kernel.org, linux-fbdev@vger.kernel.org, Helge Deller , dri-devel@lists.freedesktop.org, Daniel Vetter References: <20220505215947.364694-1-javierm@redhat.com> <20220505220413.365977-1-javierm@redhat.com> <753d0350-42dc-389b-b10b-4533ddcf32ac@intel.com> <1f788b8f-0bea-1818-349e-b1bc907bf251@redhat.com> <3b7fe4fe-fdec-cef2-4e0e-309d9dc4a8af@redhat.com> <51254d3d-af8d-61b3-e8a2-8fd0e583e783@suse.de> <2c59cd79-76d4-7829-e1db-88bc31396c8a@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <2c59cd79-76d4-7829-e1db-88bc31396c8a@redhat.com> X-Operating-System: Linux phenom 5.10.0-8-amd64 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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