Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp3596078iob; Tue, 17 May 2022 03:32:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxKcj5n4T9UXFcf4A3GygKya+oq2iv2PU0TjAOmcwwL7Da1bTlcXy2AcP7W/BrhvVO8eR5Y X-Received: by 2002:a05:6402:3585:b0:427:ccd4:bec3 with SMTP id y5-20020a056402358500b00427ccd4bec3mr18357855edc.2.1652783563362; Tue, 17 May 2022 03:32:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652783563; cv=none; d=google.com; s=arc-20160816; b=S0AGcJ1WXMNNoTNlNv+FZEvBfhxb8eFJPG59L8gy87zSc64wqGtEllpK5wBDBody3M 4FTuR/8O+nRXLhUirFS0JAXfriXbO3kF0WR0XZBW4u4wyK7My/+kh0vMCkVx8wuxp/Lz MQpHCDq5zwOvWeyyUUjD4laxwZPSwuE1n/lptRUgsRD49CAAt6CGtW2U1fs1IdtNRAKN bR2WTyywXU8sy5GmhcRykgr08Ske9W+VVA89YyvNNAnv7DTNtQkd1TKV72l4Znq90DEm 4ESc329sbQZA4VMHs0kGUcbUeefwwuUFwcg3g3XJ7X3EAu/DJ2XRcKprY5owS41axwU3 lfTg== 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=XF3qtBkgsx5OWOeh7SYoJcVh5x2IcMGJIbPN7OcwjoA=; b=F8EpBudYfljSn0Ih84+cfyYql63RhfcEaC3LH21QNjQ/6+S9+lwvQkxsUbz0bRotJy Y9F8jFeL58NY5Xyr9mwwZ5f+mOCRb33sGPDy+shj5ujIbFWknCtIGFMTs/xZc2TsePul R13HKXh5Y8PLbb8r73vbu+iFMk/2gK/ibOoocF3JLZTqLSbN+JcEyKHWI5hpNM5otCVN Ypyb5QOlbnX2+Bxg4u+Zer2/suxJQvWvZ4fYMXXPeHj5kQ3cnqo6u2vAAr7BSofsN0u/ oSf1TAyCRiNzQVDlDE9+2LK0o1rxF7grz4U9A4VO00WDVEfV4lV1XpJZ2xv4RIKfVzwO KdBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="jio/O7u2"; 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 b12-20020aa7c6cc000000b0042ac704e68bsi1705905eds.225.2022.05.17.03.32.16; Tue, 17 May 2022 03:32:43 -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="jio/O7u2"; 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 S1347612AbiEPUWA (ORCPT + 99 others); Mon, 16 May 2022 16:22:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44160 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349146AbiEPT7R (ORCPT ); Mon, 16 May 2022 15:59:17 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6881540E4F; Mon, 16 May 2022 12:53:25 -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 70B7760EE8; Mon, 16 May 2022 19:53:24 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 73C08C36AE5; Mon, 16 May 2022 19:53:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1652730803; bh=IbgkNa3Guz0qgnKUphoyCTvQihicvFTMv/ZnW1y5jqg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jio/O7u203V8NUaZLx/SVFluL5j0Rw+G/2R/KxhFIIZzn3VGW9Fvjzk2RtzAdt7l5 0A4wgmWxSdJ8KvXXinHDDqQam8GEly7G/JLLADOKlMPGaYkgaLA9oWH/L97wH7MK7i TZ+rHI1K+TRfgnmpzrPEUejDcPwQAFu82gdq0ksk= 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.17 011/114] fbdev: simplefb: Cleanup fb_info in .fb_destroy rather than .remove Date: Mon, 16 May 2022 21:35:45 +0200 Message-Id: <20220516193625.820751003@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220516193625.489108457@linuxfoundation.org> References: <20220516193625.489108457@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 666b90b3ce9e4aac1e1deba266c3a230fb3913b0 ] 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/20220505220456.366090-1-javierm@redhat.com Signed-off-by: Sasha Levin --- drivers/video/fbdev/simplefb.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/video/fbdev/simplefb.c b/drivers/video/fbdev/simplefb.c index 57541887188b..efce6ef8532d 100644 --- a/drivers/video/fbdev/simplefb.c +++ b/drivers/video/fbdev/simplefb.c @@ -70,12 +70,18 @@ struct simplefb_par; static void simplefb_clocks_destroy(struct simplefb_par *par); static void simplefb_regulators_destroy(struct simplefb_par *par); +/* + * 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 simplefb_destroy(struct fb_info *info) { simplefb_regulators_destroy(info->par); simplefb_clocks_destroy(info->par); if (info->screen_base) iounmap(info->screen_base); + + framebuffer_release(info); } static const struct fb_ops simplefb_ops = { @@ -520,8 +526,8 @@ static int simplefb_remove(struct platform_device *pdev) { struct fb_info *info = platform_get_drvdata(pdev); + /* simplefb_destroy takes care of info cleanup */ unregister_framebuffer(info); - framebuffer_release(info); return 0; } -- 2.35.1