Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp4628010iob; Sun, 8 May 2022 19:47:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyu73Yt8qQSI91LEE3fUlMSGvJrNd4arv6qP7dibjJBuOxkGdo8K+uIa12fCAxK7iKwd00+ X-Received: by 2002:a65:6216:0:b0:39d:5e6c:7578 with SMTP id d22-20020a656216000000b0039d5e6c7578mr11257587pgv.114.1652064453545; Sun, 08 May 2022 19:47:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652064453; cv=none; d=google.com; s=arc-20160816; b=QGJ0s7H0WKZ3LbEcdwIQHBIL3cfMbHxDrD9gd6/ydXLX1/GWF1NerBIiltAmxXR1qO Adc3FbuYIHPxZYLHG2KgjcjNvluelRb84vkWsEL8rTDi+Wom6GJ72sfBdpV6Ybq6F1AL Pr5w0WywYgiHsKYdd1wQPPpQFDBOA+mOziSyhYpE4E2bkn8L6x6krZUqchA/yWtcZd/y SKp3miEo/F0n6L64fCLm6C92FwBccyzqp/Vm8nbMrfeaIK4dRqqlJQ5sCvSkXjmd1xxz 3Gp1YieEiU6O33lZ4rhnqTf1XN71ln44EfzY7lFEwml0GdoQBrrlpmZ09pvb9B/CXgoF 6ADg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=XOMIAnnTamSRotiOWkLRdWbDfwtm7Vtf7J5gIUBLvsY=; b=lhqqkgCLYbfkclI7hDJU0XD7Uqr5dzuxndrDyakNOmjZN620Ms/Ib5Wppzqodl8BKb lMNKueMMhnJwN2fb3j/NEU2rHFg7uWE4bEYBLezaljnlcPucyj0LHBtMa8Vr3gpLFyxp cnRtbYbbhw0HZXc6GbQj7F6/qVm9ofaCrq9/bTbo/CmUh4+6ex5yGUspK8T/CHLHmEWM VODIjW0TGcnAsLqGOlK4PsOmjmIStrnSHkOQCN5ty8APYF3aZq9HXfrC9CUBM7qgGtiN 4ZcHuG9woPfv56ivlwZhxXk68MpA3CqycXDW3v31q8bOPNR/ctDtKg235PRvgTDoPhFA 4EQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Ba1xRvzB; 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=redhat.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id s6-20020a632146000000b003aba3fbf0fcsi11374803pgm.180.2022.05.08.19.47.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 May 2022 19:47:33 -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=@redhat.com header.s=mimecast20190719 header.b=Ba1xRvzB; 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=redhat.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 83EBE7DAB7; Sun, 8 May 2022 19:47:21 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1381747AbiEEWJn (ORCPT + 99 others); Thu, 5 May 2022 18:09:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58268 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236520AbiEEWJj (ORCPT ); Thu, 5 May 2022 18:09:39 -0400 Received: from us-smtp-delivery-74.mimecast.com (us-smtp-delivery-74.mimecast.com [170.10.133.74]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 638FD5DD38 for ; Thu, 5 May 2022 15:05:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1651788357; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=XOMIAnnTamSRotiOWkLRdWbDfwtm7Vtf7J5gIUBLvsY=; b=Ba1xRvzB9SAXzBEcc7v3Ut+zYDe2RBV33jCalF3XsLrAW3XtcdZVtzzLVzO7fa7eCxeiPu GI2paM6ysQt+cMJODb8LtFpA7WFU5P8Vt+6q1Cri7LPfax4uoXseBdTO2eo6EUnhd27qxl od8dfrpQ2gvCHswWY5g2/W6t/ZaPtoU= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-664-naRzLUubPlSJKy_MnNkwOg-1; Thu, 05 May 2022 18:05:56 -0400 X-MC-Unique: naRzLUubPlSJKy_MnNkwOg-1 Received: by mail-wr1-f71.google.com with SMTP id k29-20020adfb35d000000b0020adc94662dso1867431wrd.12 for ; Thu, 05 May 2022 15:05:56 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=XOMIAnnTamSRotiOWkLRdWbDfwtm7Vtf7J5gIUBLvsY=; b=x+fs1NMwaAV2QMHOYf8HbG7ltf2EWaLWA78nag66doHOl5aKrtX2YVxIoXxfzgSnez V9EZqabN0qXeU1eHQ/W/m8hSEh+WBu5r6997S3iUu5hxmcBKZiwnh+jaASpNg2sf5Uhd HzECxF/n2xo66UBX2jKsTdSjzPshux+mFQgIRKX9E3LGM8PMdkSDR9foOEniXWzLDPaT RZANL26j50AxI/Zh+lKxA2U+FOteAtw5j/QJRgRhgkvq4DCQDs9jojGArV1OuPLC64BF mn/XtyY8izrfy1/NNRbhfyZK4hl52du1FeAnyHVZNmbrPZ7C1w1voIy0MFuV09wPzXmc PgEQ== X-Gm-Message-State: AOAM533p1zIqCSrRHAL3oJMRU2HzgCFeiapWOT4EMVA35N0uJ1wuqtiU tcM3YoS06jbcckItM+cT6QHb7Qi448jLH+9uMrD+RC5/MaIPznt6VVJ2sDUZGvnI8iLmHZUaUex OiVQzgSyQiPP2EOgLeIAW3rjzrpf30VDGRFEfHGaWxjKSpbfx+FFlq50Qktxbipf1P6yNJH+hG1 s= X-Received: by 2002:a05:600c:214c:b0:394:2dfe:2754 with SMTP id v12-20020a05600c214c00b003942dfe2754mr287451wml.135.1651788355019; Thu, 05 May 2022 15:05:55 -0700 (PDT) X-Received: by 2002:a05:600c:214c:b0:394:2dfe:2754 with SMTP id v12-20020a05600c214c00b003942dfe2754mr287430wml.135.1651788354747; Thu, 05 May 2022 15:05:54 -0700 (PDT) Received: from minerva.home (205.pool92-176-231.dynamic.orange.es. [92.176.231.205]) by smtp.gmail.com with ESMTPSA id j28-20020a05600c1c1c00b003942a244f39sm7291679wms.18.2022.05.05.15.05.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 May 2022 15:05:54 -0700 (PDT) From: Javier Martinez Canillas To: linux-kernel@vger.kernel.org Cc: dri-devel@lists.freedesktop.org, linux-fbdev@vger.kernel.org, Daniel Vetter , Helge Deller , Peter Jones , Javier Martinez Canillas , Thomas Zimmermann Subject: [PATCH v3 3/4] fbdev: efifb: Cleanup fb_info in .fb_destroy rather than .remove Date: Fri, 6 May 2022 00:05:40 +0200 Message-Id: <20220505220540.366218-1-javierm@redhat.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220505215947.364694-1-javierm@redhat.com> References: <20220505215947.364694-1-javierm@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.6 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 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 --- (no changes since v1) drivers/video/fbdev/efifb.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/drivers/video/fbdev/efifb.c b/drivers/video/fbdev/efifb.c index ea42ba6445b2..cfa3dc0b4eee 100644 --- a/drivers/video/fbdev/efifb.c +++ b/drivers/video/fbdev/efifb.c @@ -243,6 +243,10 @@ static void efifb_show_boot_graphics(struct fb_info *info) static inline void efifb_show_boot_graphics(struct fb_info *info) {} #endif +/* + * 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 efifb_destroy(struct fb_info *info) { if (efifb_pci_dev) @@ -254,6 +258,9 @@ static void efifb_destroy(struct fb_info *info) else memunmap(info->screen_base); } + + framebuffer_release(info); + if (request_mem_succeeded) release_mem_region(info->apertures->ranges[0].base, info->apertures->ranges[0].size); @@ -620,9 +627,9 @@ static int efifb_remove(struct platform_device *pdev) { struct fb_info *info = platform_get_drvdata(pdev); + /* efifb_destroy takes care of info cleanup */ unregister_framebuffer(info); sysfs_remove_groups(&pdev->dev.kobj, efifb_groups); - framebuffer_release(info); return 0; } -- 2.35.1