Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp2180646iof; Tue, 7 Jun 2022 22:22:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzYrZ+aXMyjUEaeq5c0LbHScHg4//nx4753a4k6UyJy2c05wFJbUMn9FQVF+dSxAYdbEyeK X-Received: by 2002:a65:6a15:0:b0:3f6:1815:f540 with SMTP id m21-20020a656a15000000b003f61815f540mr28214356pgu.45.1654665766373; Tue, 07 Jun 2022 22:22:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654665766; cv=none; d=google.com; s=arc-20160816; b=w0t1eDi2n5vf8LiYBUibPH9LlcgKsBSDg3OhaLMbyOp1yIXJb/HAZYjIMBC4S4nZsz H5me0jPqzWz4RhPJmVuZP8ypzkeLGyyFjv8VoveXPUzmpMh7FuNAklyGtz4dJ6vE8SaV O6201IznhpmsJ/A34E3D0RbzoL0tf0vFWLwlfIr145Rtz9tTywLOhDL+zqvoKpszza4F /+0dbfv7Wbxpk6ihO9xarrxpldFTGaNDKt8wVxniM1PQNGze5AvKuIGgDdU3cKEGoyNG AETWJIDhu+Yut9i9iALUEj4CCZVsiBcyj28RbXLFwMjaG6gqsrUAmsYctf+B+Aws2rBm HEWA== 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=j2aYmM72QbebSORAzrEZWQqASBc0v1TXoKT1idZBjvU=; b=W2gs79l11s5MHoFo2j3gq+YExiAnaGGl6u3pqjFuhxBoYTFIw1m4wWlwrFb/S29stw xjA0zTcCsZagXnoJz1DFaVdSLBsK+FrKvUkryFa/s2PvWU2CyEAS5UzwlpPO3TXrUpOy aj/dgK7xnowJl91UFfAujR+uWH5v6KiwmXWfhLXkwIHeSEBHV2F/HpDm9qhytNW5YVQ7 JtvJoqVgRL/nVrtOTBu8e1WAU7E3wC2H/Lsu9ioy5a0qmbWMUkKbgdZfpcr7Jfw2sEDt vXoENv+b4ppiRoKBHnN8GBVKf/jzRggoW6fwZ0fbnLU8p9xnenwC4SD5kY50gsvjqJZ7 IP3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=NXJK58Ja; 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 n5-20020a654cc5000000b003dbaa0bd8d5si26388081pgt.537.2022.06.07.22.22.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jun 2022 22:22:46 -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=NXJK58Ja; 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 E94F0476C7E; Tue, 7 Jun 2022 21:52:45 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353825AbiFGW2F (ORCPT + 99 others); Tue, 7 Jun 2022 18:28:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56244 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353837AbiFGVRz (ORCPT ); Tue, 7 Jun 2022 17:17:55 -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 0BCA8224109; Tue, 7 Jun 2022 11:59:21 -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 84422612F2; Tue, 7 Jun 2022 18:59:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 94C7FC385A2; Tue, 7 Jun 2022 18:59:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1654628357; bh=zsjmbv4CwpLwHPpbcPnSVnTmO+KVbwQy7o0E/Pbn7LU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NXJK58JaLGjfLnaWnxw9qLAeVrxEUgnCU1PYaq2epQcvIRu7HNdXEIhwW32ze0bD7 T6Bo1Z8EFT2tsjMcm+vHYBFp1hE2dHOxxOmoDeINR9SbdBr2DkIKvoaqL8Cqyp6rff LC6urym+3RjuUMA/JPMZSIeAfEAjCtCxQh8b8PmY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Zhou Qingyang , Liviu Dudau , Sasha Levin Subject: [PATCH 5.18 301/879] drm/komeda: Fix an undefined behavior bug in komeda_plane_add() Date: Tue, 7 Jun 2022 18:56:59 +0200 Message-Id: <20220607165011.584918835@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: Zhou Qingyang [ Upstream commit f5e284bb74ab296f98122673c7ecd22028b2c200 ] In komeda_plane_add(), komeda_get_layer_fourcc_list() is assigned to formats and used in drm_universal_plane_init(). drm_universal_plane_init() passes formats to __drm_universal_plane_init(). __drm_universal_plane_init() further passes formats to memcpy() as src parameter, which could lead to an undefined behavior bug on failure of komeda_get_layer_fourcc_list(). Fix this bug by adding a check of formats. This bug was found by a static analyzer. The analysis employs differential checking to identify inconsistent security operations (e.g., checks or kfrees) between two code paths and confirms that the inconsistent operations are not recovered in the current function or the callers, so they constitute bugs. Note that, as a bug found by static analysis, it can be a false positive or hard to trigger. Multiple researchers have cross-reviewed the bug. Builds with CONFIG_DRM_KOMEDA=m show no new warnings, and our static analyzer no longer warns about this code. Fixes: 61f1c4a8ab75 ("drm/komeda: Attach komeda_dev to DRM-KMS") Signed-off-by: Zhou Qingyang Signed-off-by: Liviu Dudau Link: https://lore.kernel.org/dri-devel/20211201033704.32054-1-zhou1615@umn.edu Signed-off-by: Sasha Levin --- drivers/gpu/drm/arm/display/komeda/komeda_plane.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_plane.c b/drivers/gpu/drm/arm/display/komeda/komeda_plane.c index d646e3ae1a23..517b94c3bcaf 100644 --- a/drivers/gpu/drm/arm/display/komeda/komeda_plane.c +++ b/drivers/gpu/drm/arm/display/komeda/komeda_plane.c @@ -265,6 +265,10 @@ static int komeda_plane_add(struct komeda_kms_dev *kms, formats = komeda_get_layer_fourcc_list(&mdev->fmt_tbl, layer->layer_type, &n_formats); + if (!formats) { + kfree(kplane); + return -ENOMEM; + } err = drm_universal_plane_init(&kms->base, plane, get_possible_crtcs(kms, c->pipeline), -- 2.35.1