Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp3319985iob; Mon, 16 May 2022 19:16:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw3xXxXwgrLf1FFZHDuvkFberRUKmI/pEXUVUfAgCuL/eJN9lf98aXAvbkToo4YwsvblUT8 X-Received: by 2002:aa7:d4c4:0:b0:42a:9de1:fe38 with SMTP id t4-20020aa7d4c4000000b0042a9de1fe38mr13961819edr.323.1652753797058; Mon, 16 May 2022 19:16:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652753797; cv=none; d=google.com; s=arc-20160816; b=HAHm5op6DjOteOUBBQegjvnQ0ji5hj8yfiDoyM2fGOmQc1YjmDu9jJSqRPrpWS/ap4 Kj2LGscHAfPwmGnCXjIVVu4204ojk96DIg1yd3zYkwNGN0CV1on5sx3o8KELCjMxgCof rF4Kv+ykD0xUxtZJjAziyDgwiRx6x5+urcMveLvS4J8kLMihesFYye9xyQChb/2eRUpi 9JKN3z9BxotHznA45PTPjU2RUzXrHhgr7lHljZDAqD0hoIhnDKn0mRvbmuU25RRN+GyJ rHOJ/CkbPhsXNcWOov/qLSh0/JlSCPmVu47uxlZEQZnZnvtJ+8Ol4E36/aaiecvrVAwo lrrg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=diF8O60l7WFS/S/d+wQanQHAFUBnILl6dfjwdEbwAGE=; b=rSLz9/9HO9MYzAppvj9qJjYzSM4TomOuN0WSoEHFUy870EEHHE3DmYggqHAFu6ejqt qA0HKm7VsS0y34j8lKc6s/kZOlO4l0v6cyfxeOIiWre6rfAIpZ+y2sDznZJpFxrRRb7v SBxTtcMr6ftWgY+XwgBxeT6+kishfeWgw5jCYll9ErMqFMT5RuCzAPdQSWKFeKu4/uAp NPqgCpLWm7zGR6ivvSMIeLf0Y35VZ+zfcYxwRNut0OoMCdoT2hCcDLWyaZiKP6x++CjL ssfq4v0Nx/GcphPwo8e6Hgn3x3jddcF+6ih46+6V8lNEEVNb1ZCcVR8thNcExCYa0jn7 1/yg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=SJqYpIpC; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ji11-20020a170907980b00b006e834c6948dsi1183050ejc.574.2022.05.16.19.16.11; Mon, 16 May 2022 19:16:37 -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=@linuxfoundation.org header.s=korg header.b=SJqYpIpC; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343897AbiEPUKG (ORCPT + 99 others); Mon, 16 May 2022 16:10:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48940 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347094AbiEPT4c (ORCPT ); Mon, 16 May 2022 15:56:32 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3BF364831A; Mon, 16 May 2022 12:49:26 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 9D2DA60AC3; Mon, 16 May 2022 19:49:22 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A6590C385AA; Mon, 16 May 2022 19:49:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1652730562; bh=gYuOSwOplNOZ86rx3lwd6aBtKMyJJ7fBekEVduqVy0s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SJqYpIpCb7/wD1Wryg+ZOXC5ZIcgqc42Poyx+31zkTO29zS9hJQQxT43xRWBYa4lb Usw5DRYCO7rVvlR9vDNJVPIPBMwUOlFYt571BJYhonvWE+uYRoA3ebJWCcZAN8Jj6/ clUDFece5KaBA2np0L9pxmW3JU0VtWqTSKfga1yQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Daniel Vetter , Javier Martinez Canillas , Thomas Zimmermann , Sasha Levin Subject: [PATCH 5.15 011/102] fbdev: efifb: Cleanup fb_info in .fb_destroy rather than .remove Date: Mon, 16 May 2022 21:35:45 +0200 Message-Id: <20220516193624.319357282@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220516193623.989270214@linuxfoundation.org> References: <20220516193623.989270214@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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 From: Javier Martinez Canillas [ Upstream commit d258d00fb9c7c0cdf9d10c1ded84f10339d2d349 ] The driver is calling framebuffer_release() in its .remove callback, but this will cause the struct fb_info to be freed too early. Since it could be that a reference is still hold to it if user-space opened the fbdev. This would lead to a use-after-free error if the framebuffer device was unregistered but later a user-space process tries to close the fbdev fd. To prevent this, move the framebuffer_release() call to fb_ops.fb_destroy instead of doing it in the driver's .remove callback. Strictly speaking, the code flow in the driver is still wrong because all the hardware cleanupd (i.e: iounmap) should be done in .remove while the software cleanup (i.e: releasing the framebuffer) should be done in the .fb_destroy handler. But this at least makes to match the behavior before commit 27599aacbaef ("fbdev: Hot-unplug firmware fb devices on forced removal"). Fixes: 27599aacbaef ("fbdev: Hot-unplug firmware fb devices on forced removal") Suggested-by: Daniel Vetter Signed-off-by: Javier Martinez Canillas Reviewed-by: Thomas Zimmermann Reviewed-by: Daniel Vetter Link: https://patchwork.freedesktop.org/patch/msgid/20220505220540.366218-1-javierm@redhat.com Signed-off-by: Sasha Levin --- drivers/video/fbdev/efifb.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/drivers/video/fbdev/efifb.c b/drivers/video/fbdev/efifb.c index ea42ba6445b2..cfa3dc0b4eee 100644 --- a/drivers/video/fbdev/efifb.c +++ b/drivers/video/fbdev/efifb.c @@ -243,6 +243,10 @@ static void efifb_show_boot_graphics(struct fb_info *info) static inline void efifb_show_boot_graphics(struct fb_info *info) {} #endif +/* + * fb_ops.fb_destroy is called by the last put_fb_info() call at the end + * of unregister_framebuffer() or fb_release(). Do any cleanup here. + */ static void efifb_destroy(struct fb_info *info) { if (efifb_pci_dev) @@ -254,6 +258,9 @@ static void efifb_destroy(struct fb_info *info) else memunmap(info->screen_base); } + + framebuffer_release(info); + if (request_mem_succeeded) release_mem_region(info->apertures->ranges[0].base, info->apertures->ranges[0].size); @@ -620,9 +627,9 @@ static int efifb_remove(struct platform_device *pdev) { struct fb_info *info = platform_get_drvdata(pdev); + /* efifb_destroy takes care of info cleanup */ unregister_framebuffer(info); sysfs_remove_groups(&pdev->dev.kobj, efifb_groups); - framebuffer_release(info); return 0; } -- 2.35.1