Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp3329337iob; Mon, 16 May 2022 19:36:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyL9BjqjiJL+ZXwcRcsnkfzkG1Thc7cv19xgw5vVoDyky7mBStJSgf16HCztF0WqoVouqUY X-Received: by 2002:a17:907:7242:b0:6f5:2904:5354 with SMTP id ds2-20020a170907724200b006f529045354mr18306349ejc.452.1652754993110; Mon, 16 May 2022 19:36:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652754993; cv=none; d=google.com; s=arc-20160816; b=cPvtWm+T5jkBkane2rsMWEmFKrqhumZQpLa/P6VT4B/DnVKvsgpKBwnJ79mjx4WU+G f/HvHKfL+hdjUYoCbX0fRv4gY42tmZl5gxnlkT4lbQb5vHd02vQwWLe9Hef8/CtMKae7 h3NuL08eMYsWn3QwQfvIYcXXoqZLdN8xuVgJ3GeOmNBYWOCDJNWQqy/uY3WoZk5jvmpg eLPhx2D7JVGefCOmx4GjhmIpeYPNPmJAKWAhTI7r6qSLnK/n9qANHBw2aKJ67LowB0El DOPlDXveliseaWrVVmTBawFd64/AG+9r1F4nb7jEa1SMGoUkZ590D/5K+j2MLhTp0haB Bulw== 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=ztFx28tZdHcMEslIIFBHPJPqPzLdz69F5Zi4VcA+w9M=; b=VUAhJ4RoZW3bL4jciAgB5G7T2oWo/2t8l5ZKzKGfFjbXL9J3HTcIULl/NQBH0074qs 7WfCAA3u9ofU65+0I3KtSXHeIG2TMHFFgO1uMXO51wBZYKRiuIPxXUcUSZsBQBZqkJNC Z9hgHJZrNVmQyu71rHT49VN5Rdn6nG/Ao6lOizDKnv37v58cgG4kWQ0Uzrh/fCaCiQbM oUhAVB31yyy0qqfCjDM6LLVK81SQ42tRl/87u608f3crAoKj1bGN8tyfvsk4ZJqqM5r7 wsyp0WXsyYwxIqiHZXAX51LQzUDHVertG+EQtERuQv8CWIAUMf8dNe9Jo1o8r+Q80byq 2xCA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=mw2hmIta; 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 qx9-20020a170906fcc900b006e893bdaefesi867069ejb.884.2022.05.16.19.36.07; Mon, 16 May 2022 19:36:33 -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=mw2hmIta; 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 S1351619AbiEPUGu (ORCPT + 99 others); Mon, 16 May 2022 16:06:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33094 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346402AbiEPTxn (ORCPT ); Mon, 16 May 2022 15:53:43 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C016346B06; Mon, 16 May 2022 12:49:02 -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 ams.source.kernel.org (Postfix) with ESMTPS id B9E22B81616; Mon, 16 May 2022 19:48:49 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 30305C385AA; Mon, 16 May 2022 19:48:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1652730528; bh=UE+UaX07cuhVOKJs+zw6BCy4MVc8XhQSHHVFf1r1FHE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mw2hmIta+/2rLJZGDj75WeMcBZvBG3Qx+CRfKV80t39HHsZGJzI0jHYiTDBz491WM YjG6eVQhOvWxehZ2Vxm9c+lmiC3ctFFQGKXz7ID7SAqCuG8pvOIIAjcKUEodpQJZBo TMvYIGP4ilCQT9nEIB1xWLvj5e+WmPksdo1O5KEk= 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 010/102] fbdev: simplefb: Cleanup fb_info in .fb_destroy rather than .remove Date: Mon, 16 May 2022 21:35:44 +0200 Message-Id: <20220516193624.290501139@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 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 b63074fd892e..a2e3a4690025 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