Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp3362283iob; Mon, 16 May 2022 20:42:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxgFUqVNnykBHmPsn3yK4xagD1BE3Dqe/OIRQ4AbmMZWQWD1zAEFhBHy0nAhq7ttUzlcYLU X-Received: by 2002:a17:907:1622:b0:6fe:22bb:7f8 with SMTP id hb34-20020a170907162200b006fe22bb07f8mr10890601ejc.767.1652758939751; Mon, 16 May 2022 20:42:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652758939; cv=none; d=google.com; s=arc-20160816; b=o9/sWKHhX0nIgC2Muw8aStmH3oU9+UypnbIIjGyrs54YpnkgBNQccZjFES5bIuXS6j mndVCo3AnqLf76ukF9eeU4nLrb/aGljt+m9Ki7piPiGnEo9wkOS7c44/S7hs9BQCKRUd kcTVkXhXa+ypI+puzLci+OfyaiDJUOCVvfdL36PCb3szuLBoy/jCZjGeCuaZjluCnh11 rKGwJKHzZGTX+f+81XVARelt/KDdhPyFQfusU6Gp/bkkiPlTOZ+4ea5779MMr0EXieTS AaSGA5vU8dhPAophWPghaRYqchn8owcIhAWM5i9cduXqGI+KcwzSD4LyvznwBcGz7L7g /6iA== 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=NweCmZC7RZUvj4lzuZd0p3X5jeovyJ0UMenJZDp8wbw=; b=ZDwZtib1ecNmrFQrXdu5kUpInVTF3809yq7yFaJD7m9WQZ3J1GoHKCOqui+YhQzBVq C2d18l7kq2DIh31qIkcnA96/plSL7A65q53FyrnMdFL8Wub53zxoIAE8FpntVhzxATMI 7eFSDePje1QMc+/K/tEtAwMAMJtWTa8GWOmpDwKgfAGn09bk8BNOGlrEKe8E27nM306Y gOZj+HQ5lMc9wOQqtCaeVuM5TVILfuSlS6NIFzaoU5Jkdde2rupLGLQ4dtsyPHAZ1pHD a6v7sBaCQNl8H5OJA/yV3GFm/eRApXQb5s5jFq/rvAVzEQU7c2u1R2+gz0+OT+cV2ksk 9lPg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=2nhjifId; 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 cs18-20020a170906dc9200b006f385307f95si1305448ejc.649.2022.05.16.20.41.54; Mon, 16 May 2022 20:42:19 -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=2nhjifId; 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 S234282AbiEPUZl (ORCPT + 99 others); Mon, 16 May 2022 16:25:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44926 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347921AbiEPT6Q (ORCPT ); Mon, 16 May 2022 15:58:16 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4658143498; Mon, 16 May 2022 12:49:59 -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 7B5B460AC3; Mon, 16 May 2022 19:49:58 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1AF33C385AA; Mon, 16 May 2022 19:49:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1652730597; bh=Z3rLPS+jBk9yzNvGeXe6K5znMwWULIfK34dAsS47NhQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=2nhjifIdOBE7ndmD2A/NaVNEpExnDwJr0CWOW8ne1d58Od8hsILpTtsuzqPx+ZOcE CD/dyv/9IKit5icKVwqGxZYmAOT/VEdFqmH1gnwsLBmji6nyIaoipLUNlEtHwR2g0G wl6LPHEwOzoqCG985/88iNbw5ttaq9VC/n2Deg04= 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 012/102] fbdev: vesafb: Cleanup fb_info in .fb_destroy rather than .remove Date: Mon, 16 May 2022 21:35:46 +0200 Message-Id: <20220516193624.349174778@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 b3c9a924aab61adbc29df110006aa03afe1a78ba ] 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/20220505220631.366371-1-javierm@redhat.com Signed-off-by: Sasha Levin --- drivers/video/fbdev/vesafb.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/video/fbdev/vesafb.c b/drivers/video/fbdev/vesafb.c index df6de5a9dd4c..e25e8de5ff67 100644 --- a/drivers/video/fbdev/vesafb.c +++ b/drivers/video/fbdev/vesafb.c @@ -179,6 +179,10 @@ static int vesafb_setcolreg(unsigned regno, unsigned red, unsigned green, return err; } +/* + * 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 vesafb_destroy(struct fb_info *info) { struct vesafb_par *par = info->par; @@ -188,6 +192,8 @@ static void vesafb_destroy(struct fb_info *info) if (info->screen_base) iounmap(info->screen_base); release_mem_region(info->apertures->ranges[0].base, info->apertures->ranges[0].size); + + framebuffer_release(info); } static struct fb_ops vesafb_ops = { @@ -484,10 +490,10 @@ static int vesafb_remove(struct platform_device *pdev) { struct fb_info *info = platform_get_drvdata(pdev); + /* vesafb_destroy takes care of info cleanup */ unregister_framebuffer(info); if (((struct vesafb_par *)(info->par))->region) release_region(0x3c0, 32); - framebuffer_release(info); return 0; } -- 2.35.1