Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp2212080iof; Tue, 7 Jun 2022 23:21:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwE1horbnT++92BRVMdx0pnyPM2JKxxqK3o6YOdb4NmKAuFDa4Cfve1NEZNh1xoHGGpLLnJ X-Received: by 2002:a63:2ccb:0:b0:3fe:1929:b30b with SMTP id s194-20020a632ccb000000b003fe1929b30bmr4360096pgs.64.1654669290981; Tue, 07 Jun 2022 23:21:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654669290; cv=none; d=google.com; s=arc-20160816; b=tvptBKutLbkJO9wjQ1k+qgNb8FTQtiyRvrY4NeeQtRuacStYfrhZ6t11pTV1iea9T+ QQGBOJutZM7+NkUw69TIAKAc0UY6zltoMtezuxyZKOOnAR8G6TRugBv2VCcSX2elzIlK HBm5EWaOOrU0bvcTMD+8ueMZJNQPL16eDUIu3JbVTYotXNp+ClnhcL6YyAaLAqAuAby/ 7yC6SzF6qzW+MLdK/9RnS0fhaZN7TpcaQC02LcTW+6o9+tme4Muc3PFjudxWh/i5ucLJ 2PYPXDLXm/LuE0F04ce7SR7inzOxxvM+lWULUXSzJEaUutoIMTLAhcp0CAiKGyMYdvMP mlwQ== 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=EF+e96dvcIIjVSBFk3D9I1TzC/gqiHD8YEFnnAo+pow=; b=QAnQWrWFkMb4KCIn6WFGFh6h7WMpjd+QX6DjvYD3rwAPi9+u9Row4hRM24biLlcGs7 cAj4ppEIcmT3MFaQ05ZR45WaSVxU82kYdorp6uk801krnjZaWHsV5t3uoGWKY8M2VPqi UV0YEWNEq9BxlUmE05Z4IRPCmHyRGYVtddNH4r87ao3Y0kXoteKcK/8TjP2dBRUijCJN N3boVQpPY2mpXWj9YsKbwu5JClT+hzhP7KW9Y9t4c4NFqF2uq/QuvcPEELCIxcybN6FH oK5h4keHXmsL86DzLCPaM5O3lHe/RrPzxxKtyfGBCRT+n7ihDj3CbIGdIdKM20bkip0T 0kbQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=pmGiBPps; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id c4-20020a056a00248400b0051c306c363csi6986134pfv.143.2022.06.07.23.21.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jun 2022 23:21:30 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=pmGiBPps; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id C1D4A3C2DC1; Tue, 7 Jun 2022 22:42:17 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1442673AbiFHCAw (ORCPT + 99 others); Tue, 7 Jun 2022 22:00:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32942 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1838769AbiFHACJ (ORCPT ); Tue, 7 Jun 2022 20:02:09 -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 4F61E2BB28; Tue, 7 Jun 2022 12:18:01 -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 E210561931; Tue, 7 Jun 2022 19:18:00 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EDAB1C385A2; Tue, 7 Jun 2022 19:17:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1654629480; bh=aGyWqYvWyjA/1VAtWXlscfe1t8nAwgekUlQyFJv6zs0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pmGiBPpsUUksReR9sJ5CeNBmhOtZHY0Yaf0NoYTgbL7BvNQFZl/eyA48TbBWo5nuC gSQxf1tsM/4o/pd7HRfRlvHrDAaTyR5IuitAAsbledtOjCDO42PMAn2TD3F7ETdeSA ejUn6eHPCHk+NtDXl76iKWEOZVLYqTXC16ZAyRN4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Pascal Ernster , Javier Martinez Canillas , Helge Deller , Sasha Levin Subject: [PATCH 5.18 705/879] video: fbdev: vesafb: Fix a use-after-free due early fb_info cleanup Date: Tue, 7 Jun 2022 19:03:43 +0200 Message-Id: <20220607165023.310688894@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220607165002.659942637@linuxfoundation.org> References: <20220607165002.659942637@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=-3.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE 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 From: Javier Martinez Canillas [ Upstream commit acde4003efc16480375543638484d8f13f2e99a3 ] Commit b3c9a924aab6 ("fbdev: vesafb: Cleanup fb_info in .fb_destroy rather than .remove") fixed a use-after-free error due the vesafb driver freeing the fb_info in the .remove handler instead of doing it in .fb_destroy. This can happen if the .fb_destroy callback is executed after the .remove callback, since the former tries to access a pointer freed by the latter. But that change didn't take into account that another possible scenario is that .fb_destroy is called before the .remove callback. For example, if no process has the fbdev chardev opened by the time the driver is removed. If that's the case, fb_info will be freed when unregister_framebuffer() is called, making the fb_info pointer accessed in vesafb_remove() after that to no longer be valid. To prevent that, move the expression containing the info->par to happen before the unregister_framebuffer() function call. Fixes: b3c9a924aab6 ("fbdev: vesafb: Cleanup fb_info in .fb_destroy rather than .remove") Reported-by: Pascal Ernster Signed-off-by: Javier Martinez Canillas Tested-by: Pascal Ernster Signed-off-by: Helge Deller Signed-off-by: Sasha Levin --- drivers/video/fbdev/vesafb.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/video/fbdev/vesafb.c b/drivers/video/fbdev/vesafb.c index e25e8de5ff67..929d4775cb4b 100644 --- a/drivers/video/fbdev/vesafb.c +++ b/drivers/video/fbdev/vesafb.c @@ -490,11 +490,12 @@ 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); + /* vesafb_destroy takes care of info cleanup */ + unregister_framebuffer(info); + return 0; } -- 2.35.1