Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp432065iob; Wed, 18 May 2022 05:29:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzllsd+EvxlkFODeMTLfHKswNXZZX33P99Muywu2M21v8rSa9+kW/d+xp6/9MgsXXOgJuIg X-Received: by 2002:a17:902:f78d:b0:14d:522e:deb3 with SMTP id q13-20020a170902f78d00b0014d522edeb3mr27393385pln.173.1652876988027; Wed, 18 May 2022 05:29:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652876988; cv=none; d=google.com; s=arc-20160816; b=R/YogypVYsLKOcQygh1RtS7kDHgmi87cRCBtYqZrkvZt9qF2LSzoQp4V2IYYFNC1Vi qrrsGMZQcQsKm/WQOyeqzaIhr2GZxNbWkxZwmY0r5zbBW9ftkaVXscnuu8NFmk3r+ooc K+N1BskJwHuetJZEujjrbB3/evX9hqqP6Z4jga3PjM906yDQp9AI3+gi+9tRgaPZjjDb 6VdU2UuTKsIre8ASAlhCxmv8ULkROhx7n6jhmqkPdidv73nVov7wV4ykP8ulT6ZNJmBm /qYfrSGO2WEjxaEkaWCMwAZZuCnH5QdqkU/hGxfa+WmXOMWkI4U9Mk6NqrMifa5L+4j4 i+9Q== 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=FexbkD27rDwHCQTDTN1qzEA8YYKkb652PlPxphwYzPo=; b=UK3Z0ZE9Bu3LIuV4bAsEbda9JayUsImhK/tSs0guldsSNSAz0HCOYyMZtn5kpnKztw CjFJAIgpoA/U8ENTD81YCYKU0H2ETmceqWpibqEU1OlUn6Hj1QrMjC8SiiVcFyhG+zLO GeqbBV6EL4NSWmsdFS1tPM6qhrwBQ/ULHBIJjsKxJmlidXm+JZF27f0Ksf/DSfcfSdTV pFo5AucNB9fZt8wVlNrtrS3vxMDNXtolhewVLnHRwy85iqLxYCgwBM9LAdUHA220xFxJ KZP8xQtxm5YjvgSJuOa0rHKBZ5aH8M15wE4wCqwVPwV/vi1Ngw025RXyAJR8YoWu5eu2 /i0w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=uTE9CK8k; 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=kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id co10-20020a17090afe8a00b001df7618121bsi6324829pjb.72.2022.05.18.05.29.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 May 2022 05:29:48 -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=@kernel.org header.s=k20201202 header.b=uTE9CK8k; 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=kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 110DC199B20; Wed, 18 May 2022 05:28:43 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236600AbiERM1r (ORCPT + 99 others); Wed, 18 May 2022 08:27:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47660 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236483AbiERM1O (ORCPT ); Wed, 18 May 2022 08:27:14 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 77BE18DDCE; Wed, 18 May 2022 05:27:07 -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 ams.source.kernel.org (Postfix) with ESMTPS id C923DB81FB6; Wed, 18 May 2022 12:27:05 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 407DDC385AA; Wed, 18 May 2022 12:27:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1652876824; bh=doQRzfdvKQcqj96z7UMVJeMF3Ya4m94Bf6rITo95dKE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uTE9CK8kHOpcgsW4skP3AYCrsPD5jlqZA0wckV3P8PejKR4zOlKKGzHWZS1FbzR6d i6rw8Q0s5fvovFzBH+P+ogzFuK76axYa9CM9w7UZkMnK3374bF2Twj0cjhmwVW4fBR sYvIzl03GN+qGkesa7AAcVs+0LdN9I3QdswiICZeR4/FxsZizn5JglmrGyxqiPi1tS ad7MePLICIj31QyMzo/fikfftOfRD5FZ9alhCGkCnW/twrbk7hmKyRFEMwtXw5zk9B b08PWiqCW6erupdG1sT7kz5ttZLDR+YAD1zbmgXJsgovqJ7ktepS6J4rAks8RSBXmy WSt5Vvlet+E6w== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Daniel Vetter , Daniel Vetter , Javier Martinez Canillas , Thomas Zimmermann , Sasha Levin , daniel@ffwll.ch, deller@gmx.de, sam@ravnborg.org, wangqing@vivo.com, linux-fbdev@vger.kernel.org, dri-devel@lists.freedesktop.org Subject: [PATCH AUTOSEL 5.17 08/23] fbdev: Prevent possible use-after-free in fb_release() Date: Wed, 18 May 2022 08:26:21 -0400 Message-Id: <20220518122641.342120-8-sashal@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220518122641.342120-1-sashal@kernel.org> References: <20220518122641.342120-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore 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,DKIM_VALID_EF,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: Daniel Vetter [ Upstream commit 89bfd4017e58faaf70411555e7f508495114e90b ] Most fbdev drivers have issues with the fb_info lifetime, because call to framebuffer_release() from their driver's .remove callback, rather than doing from fbops.fb_destroy callback. Doing that will destroy the fb_info too early, while references to it may still exist, leading to a use-after-free error. To prevent this, check the fb_info reference counter when attempting to kfree the data structure in framebuffer_release(). That will leak it but at least will prevent the mentioned error. Signed-off-by: Daniel Vetter Signed-off-by: Javier Martinez Canillas Reviewed-by: Thomas Zimmermann Link: https://patchwork.freedesktop.org/patch/msgid/20220505220413.365977-1-javierm@redhat.com Signed-off-by: Sasha Levin --- drivers/video/fbdev/core/fbsysfs.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/video/fbdev/core/fbsysfs.c b/drivers/video/fbdev/core/fbsysfs.c index 26892940c213..82e31a2d845e 100644 --- a/drivers/video/fbdev/core/fbsysfs.c +++ b/drivers/video/fbdev/core/fbsysfs.c @@ -80,6 +80,10 @@ void framebuffer_release(struct fb_info *info) { if (!info) return; + + if (WARN_ON(refcount_read(&info->count))) + return; + kfree(info->apertures); kfree(info); } -- 2.35.1