Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp2191022iof; Tue, 7 Jun 2022 22:42:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx5wKg6Z4oV/szuhQTP+7QWsSqptcND8jJuIhUaAPMDpVij+nShY4/gy5ljh7cDTuVzHXA/ X-Received: by 2002:a17:90b:20d4:b0:1e2:fadf:3f09 with SMTP id ju20-20020a17090b20d400b001e2fadf3f09mr35998406pjb.236.1654666925941; Tue, 07 Jun 2022 22:42:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654666925; cv=none; d=google.com; s=arc-20160816; b=qxIlucn0BePaTlGXnwiP5dCCbIwXgIxqFhrIzR8EsL6Vykb3lLX4+7/hH2eHvwKyRz FF5uxZMHRkp6XIxkqp5OsTnAAuB4lXqONHxeQa9n2nvgo1iYYKObLXktRFjpjLmiUWDH SO3d8G0UWxtUOC/qjiZmHdgJtBfA99wgXhoRNFHg3Dy/irpKhW8GvgQbLv4FFn6rj/7D kMBgBBHxR9MEx2fvU7jzgNLnbgk+eWInxFeR8TtTeYsp2EqzvcmYCZwaoax8MLipiB+t Cuxhr7q0TChFrO0Y6SqKPefqnrcQ0cl+9/nd8QwQOESQnw5cR3bapUC5q72W17wr/ryE HTmQ== 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=S6tqVlANUu9+wZw/bK9AmHptkUCx6/FIdFd9BML9wFsjkLO0/8K/t0rtU6nvFmhKe7 N+W44yYgz0gkARK7WqQFyuzIXZsNtnkT0UojnephiOxe/tiuxA68cHGKEHy+/5sOXk5m /roQqBx1ALK8rLtA1MotT21DXYMzhK6TZXOLp2tKFxmL5FiRgRhLy5Ko6jk/xvPZY/tk 8IznQYeYIU5A3atziEqH30wiPfKXokrpT3lYBfP/yBi/EfsdzPzCcTzkyNY+QeHZr4jy ScANC8NcVrgQ4oyNIwlgQqUETTUdLZ5TSWxtSOR26+BHmHQDC29jww6E7XwT4LhElDKI SQAA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="1H/v7H6b"; 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=linuxfoundation.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id pf17-20020a17090b1d9100b001e858850fbcsi17456088pjb.50.2022.06.07.22.42.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jun 2022 22:42:05 -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=@linuxfoundation.org header.s=korg header.b="1H/v7H6b"; 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=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 810A7390244; Tue, 7 Jun 2022 22:07:40 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377588AbiFGU7w (ORCPT + 99 others); Tue, 7 Jun 2022 16:59:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49962 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1356551AbiFGTyM (ORCPT ); Tue, 7 Jun 2022 15:54:12 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 42B088D68E; Tue, 7 Jun 2022 11:23:35 -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 4C8C4B822C0; Tue, 7 Jun 2022 18:23:34 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id ADCB1C385A5; Tue, 7 Jun 2022 18:23:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1654626213; bh=zsjmbv4CwpLwHPpbcPnSVnTmO+KVbwQy7o0E/Pbn7LU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1H/v7H6bCes+t+69V2f6bOvxiZShc3HAo6xXclViWdZ6maqyvG+JPsLOZrnEWyNmr AChci2BQYL9vrn9TdALXoEgdiodz4XSPuaQpONaOadkyXn1c0bQRG0qluvDZ7GKAsv ii9k7dp60coxhbjzvI2wsuzvw2VIgo+I2FFJpaZk= 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.17 257/772] drm/komeda: Fix an undefined behavior bug in komeda_plane_add() Date: Tue, 7 Jun 2022 18:57:29 +0200 Message-Id: <20220607164956.595798329@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: 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