Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp2176953iof; Tue, 7 Jun 2022 22:16:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxS5wyc1tpKEMZieMpICdBT7QFP5JJSpM4YSdOsB03+ulRZlcdSnjuc4aq4XZCrMFymXxmr X-Received: by 2002:a63:fd0f:0:b0:3fa:5e0b:a434 with SMTP id d15-20020a63fd0f000000b003fa5e0ba434mr28401308pgh.493.1654665374920; Tue, 07 Jun 2022 22:16:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654665374; cv=none; d=google.com; s=arc-20160816; b=NbJHJ1NBkzIJUnRg5F6Bud784c4TFg4s3DXBKngu0/xUec3eWTJRf3iQ0yej+byvDC kbW0r9gQhoGPOCystg4HMHB0ToEFr1X4hnlVnHYThvtFXRRQ7LBkFt1E/Po8GaMH607m 2ft6/hZRBq0637aHHQYNxkf7oFINtFyfe8ugLKLCXhgeSAMS4B/9NgEWQKqZtebKTvrA u0mcNDS6MLkpM5CKL2y6+YMkwdlykoxF4XxuzFAwOqVQGw0fOODT/4gwtFpUDPO/aQVd BldZzB5u//qCMCDpAiciAhTg2FOPOkkTPOy17FHomH66U27Xe8xgMYLBe+yDA5dmKLrU qQNQ== 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=Je2bFmZSh0GvFyzVXfuEPwx0SC/OtfX2+UuP+2xBmVb1N135vv6oFZD35xamTTvVp7 fYmqsfxra3v5okUxSoqQDsYwRO9SRicr9aY6IEU15lSngEXlaixf0Nwzdka1Ev49p0R2 hQhS7V/Rq81kj8dhaZaPUB72mrgZWsPfBnmjD2qrjJWt3UquRUcIz7YwJYZXUzjuNGOS /LNzq2XrCvHlGHOW7TW5pChSJB9v9JYLqNEvkLk8uC1/e7ivxF8o4upcZcINDSf/UySa 6RXOBN1NCiQgpe0pvL9HVXqi/k5RQx0+uh6SZuLPs/glkyf/d7vwfhnrwxE7ZbZlYFCT JibQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="wIdhD/zy"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id j5-20020aa78005000000b005183163dfa7si17757048pfi.267.2022.06.07.22.16.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jun 2022 22:16:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="wIdhD/zy"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 BA98546922E; Tue, 7 Jun 2022 21:45:43 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1379732AbiFGVif (ORCPT + 99 others); Tue, 7 Jun 2022 17:38:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37212 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1376737AbiFGUqL (ORCPT ); Tue, 7 Jun 2022 16:46:11 -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 B31671F5749; Tue, 7 Jun 2022 11:39:31 -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 EB978612EC; Tue, 7 Jun 2022 18:39:28 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 07C11C385A2; Tue, 7 Jun 2022 18:39:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1654627168; bh=aGyWqYvWyjA/1VAtWXlscfe1t8nAwgekUlQyFJv6zs0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wIdhD/zy9BpjSq+aGPB7EAFAhLabPgLfS4BLmzjDr0l7GAFeT4ZtwJvaGuRExKCxA s58zA5ucz2WuPcsNeLWmyDSOzjGajsvDOpMAAH23iKDBJDE9UdW1Trc2Z4sKJObJOK NlHat7gX6FcvWLpnP/snTUkM3unkRLh7gnkZl0Ws= 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.17 605/772] video: fbdev: vesafb: Fix a use-after-free due early fb_info cleanup Date: Tue, 7 Jun 2022 19:03:17 +0200 Message-Id: <20220607165006.768209733@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220607164948.980838585@linuxfoundation.org> References: <20220607164948.980838585@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