Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp1405308iob; Wed, 4 May 2022 23:53:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzf7d4+Y3eA5Kkxc/Hn2yu2vBauVJ7/Z+Ia89FEgTtXjHdr1+Fr6QjG2WR0dEFjDTYHZKzx X-Received: by 2002:a65:6bd6:0:b0:39d:4f85:9ecf with SMTP id e22-20020a656bd6000000b0039d4f859ecfmr21627308pgw.336.1651733580740; Wed, 04 May 2022 23:53:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651733580; cv=none; d=google.com; s=arc-20160816; b=yhK9cMuTEBUgeZ6pt54jVaxch0u+X+MahW1eYsKA61OuUdHSSqZiI8Faj2SnhsRsgk nQplEjCDt2e4zgjLVVAp0jfKXBd7CfENJDNqUtcogYj/lC/vjoXvHmA/TFE9xcOzv7+r 64npPGS5yeOFSW4a9TL9zq8ayeZZzGT1dwa4z3d7wL1SC/2GOnsVVGIXhwzqk9O/+14U euD6J8aYysnZuxHEqk0XwhcgFEVw1d6YlJuG6DsA++BHUB52gulHdFsTNoqwAq/mkqeH rz+IbZPmzFWSEJ7279JmPRLaXFhQftMEBD9ZMZsuruePfgrY61zpTjSuoPzgbfvIe2iQ 7j7A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:mail-followup-to:message-id:subject:cc:to:from:date :dkim-signature; bh=pt2TRLKQnwY3ta64YfqAq6YtRrVzSU8ZCieIxo+HibQ=; b=WMn6d3jkwM0DDgRxtqC9bKpLMwVDeO48PwdpRudAlco0w8ntITTbnGKMqYA575CJvx rs8wng5igKjEENWhbjAHAemMhcq/8qln5YZxFWU63MStip8PyNGVZfHgKLV3QaKxCNEy zml9RDWxursYRPSYhw3eL62drNcOlod5yJ2UIjeBuVsVeSzWKnYtXzTa9dg+0WGG3RCs 2kSXQMTnzDNCoxO22dUVMQFvA4iXBrIMFDVKX2YmYQLrHkm1NFmGgowjwfZWoW/3DR49 8slTGh/Bu6ZQCfJzTKLYZ5h5YvK3ZrUGHQ1QGwmXRMYBqchYMH2rmR2nk2hhd0o/UvxX FckQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ffwll.ch header.s=google header.b=NzWxRgjW; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j25-20020a635519000000b003a9fb8f68b5si749043pgb.213.2022.05.04.23.52.44; Wed, 04 May 2022 23:53:00 -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=@ffwll.ch header.s=google header.b=NzWxRgjW; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348493AbiEDLIT (ORCPT + 99 others); Wed, 4 May 2022 07:08:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41394 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238897AbiEDLIS (ORCPT ); Wed, 4 May 2022 07:08:18 -0400 Received: from mail-ej1-x629.google.com (mail-ej1-x629.google.com [IPv6:2a00:1450:4864:20::629]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7559023BE7 for ; Wed, 4 May 2022 04:04:41 -0700 (PDT) Received: by mail-ej1-x629.google.com with SMTP id y3so2126836ejo.12 for ; Wed, 04 May 2022 04:04:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=date:from:to:cc:subject:message-id:mail-followup-to:references :mime-version:content-disposition:in-reply-to; bh=pt2TRLKQnwY3ta64YfqAq6YtRrVzSU8ZCieIxo+HibQ=; b=NzWxRgjWaJ8cPpwY9gvgAUuop+qGDVwiYic7pmIWcXyzzOBcfNiKWRzkRcM8Jw6G32 uVvah/flCkBXeajVH1blE7XssB73CDMuhF8mDidJwqtaFZosF76rDlWHgXFESVDRuJix ziaaekuqmtOgP+0TK7fChiLLKcioScxsyBI0Y= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id :mail-followup-to:references:mime-version:content-disposition :in-reply-to; bh=pt2TRLKQnwY3ta64YfqAq6YtRrVzSU8ZCieIxo+HibQ=; b=7wdeYLYTx66eGL4oZ9KcrVwqJjuHA2Ze65GYIm2rRltabuc96abCZMqv/gslm2mFh/ 9bKj2bP813ciVRSHAD5QD/ZNI5VfHiFydne6we78vKPF69iuq2ZJzHvikhb1isrPQxMv XusBFmUqjdCKcKqtoK+MteAIGz/igUiOURgkyWVIW0aEdaW7JhzkrcA67Jr8hOvNL83s tk3fRnetb9kJ+Cckoe1CitmEgCt6ycKmJtdITz6zVWu/Nvt/neYc8H2g5cKiT8/uJnHj YV9KiN76VSe3MRW4mxbCVIJ2Do91GhfQPIy8bIlm+n6xzGmRy6yPExnpUxA0KeK0LlNN Kc6A== X-Gm-Message-State: AOAM530hvE5Xt0Obd1JPCzoNK5vkvz+bbmM8cgCnoUSnKwmOyLr2wwFg +eRjZBdnWy8WUm8yMFl+j9e0Ng== X-Received: by 2002:a17:907:1b14:b0:6ef:a5c8:afbd with SMTP id mp20-20020a1709071b1400b006efa5c8afbdmr20130483ejc.151.1651662278526; Wed, 04 May 2022 04:04:38 -0700 (PDT) Received: from phenom.ffwll.local ([2a02:168:57f4:0:efd0:b9e5:5ae6:c2fa]) by smtp.gmail.com with ESMTPSA id s8-20020aa7cb08000000b0042617ba638csm8916830edt.22.2022.05.04.04.04.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 May 2022 04:04:37 -0700 (PDT) Date: Wed, 4 May 2022 13:04:35 +0200 From: Daniel Vetter To: Javier Martinez Canillas Cc: linux-kernel@vger.kernel.org, Maxime Ripard , Thomas Zimmermann , Daniel Vetter , Daniel Vetter , Helge Deller , dri-devel@lists.freedesktop.org, linux-fbdev@vger.kernel.org Subject: Re: [PATCH] Revert "fbdev: Make fb_release() return -ENODEV if fbdev was unregistered" Message-ID: Mail-Followup-To: Javier Martinez Canillas , linux-kernel@vger.kernel.org, Maxime Ripard , Thomas Zimmermann , Helge Deller , dri-devel@lists.freedesktop.org, linux-fbdev@vger.kernel.org References: <20220504105140.746344-1-javierm@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220504105140.746344-1-javierm@redhat.com> X-Operating-System: Linux phenom 5.10.0-8-amd64 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_NONE,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 On Wed, May 04, 2022 at 12:51:40PM +0200, Javier Martinez Canillas wrote: > This reverts commit aafa025c76dcc7d1a8c8f0bdefcbe4eb480b2f6a. That commit > attempted to fix a NULL pointer dereference, caused by the struct fb_info > associated with a framebuffer device to not longer be valid when the file > descriptor was closed. > > But the solution was wrong since it was just papering over the issue, and > also would leak any resources that might be reference counted in fb_open. > > Instead, the fbdev drivers that are releasing the fb_info too soon should > be fixed to prevent this situation to happen. Maybe add a bit more detail here why this goes boom: The issue was uncovered by 27599aacbaef ("fbdev: Hot-unplug firmware fb devices on forced removal"), which added an new path that goes through the struct device removal instead of directly unregistering the fb. Most fbdev drivers have issues with the fb_info lifetime, because they directly call framebuffer_release() from their device driver's ->remove callback, instead of from fbops->fb_destroy callback. This meant that due to this switch the fb_info was now destroyed too early, while references still existed, while before it was simply leaked. The patch we're reverting here reinstated that leak, hence "fixed" the regression. With that or similar added: Reviewed-by: Daniel Vetter Also thinking about this, maybe we should have a WARN_ON in framebuffer_release if the refcount is elevated, and simply bail out in that case? That would make this bug a lot easier to debug and less confusing. Maybe include that in your series to fix this properly. -Daniel > > Suggested-by: Daniel Vetter > Signed-off-by: Javier Martinez Canillas > --- > > drivers/video/fbdev/core/fbmem.c | 5 +---- > 1 file changed, 1 insertion(+), 4 deletions(-) > > diff --git a/drivers/video/fbdev/core/fbmem.c b/drivers/video/fbdev/core/fbmem.c > index 97eb0dee411c..a6bb0e438216 100644 > --- a/drivers/video/fbdev/core/fbmem.c > +++ b/drivers/video/fbdev/core/fbmem.c > @@ -1434,10 +1434,7 @@ fb_release(struct inode *inode, struct file *file) > __acquires(&info->lock) > __releases(&info->lock) > { > - struct fb_info * const info = file_fb_info(file); > - > - if (!info) > - return -ENODEV; > + struct fb_info * const info = file->private_data; > > lock_fb_info(info); > if (info->fbops->fb_release) > -- > 2.35.1 > -- Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch