From patchwork Tue Sep 13 08:53:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 605886 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 288ECC6FA8E for ; Tue, 13 Sep 2022 08:58:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231376AbiIMI60 (ORCPT ); Tue, 13 Sep 2022 04:58:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37090 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231425AbiIMI6X (ORCPT ); Tue, 13 Sep 2022 04:58:23 -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 A374843E69; Tue, 13 Sep 2022 01:58:20 -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 40F576135B; Tue, 13 Sep 2022 08:58:20 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 88F9CC433B5; Tue, 13 Sep 2022 08:58:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1663059499; bh=UesYWvFKNzKIUaFJBsc/VB+FJHKodJ1Cgw5lzNNC0l4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tjGQbFiswH2c+W5sZ9H+PgiDVNeDXoaLU5oJYnrV5gLohCxcDRwm8GQsH92BJ3nDe aioESzTbKLFnOW41jaPY5Ni/5JWPrNqjMWYT9TE4JrCELKRGc2MTKl3cE887iDxidR NG33ZaLEwuPN3TSxJqbudGYFvgNZhwKJ0/Uev8/DPpQImYhyRklxKakAUXWd3b0t6n YpcoGL+DHLwO/HK1Eeca0waIPx1ZNJVmxGVpQs57N5poO5RneeIeXKSQDEUokgyhit +upTObdyoj2DVeYWSC7EOd8Xw5msilZW/PRq0LheuehXxm5iK1Sc+xus0RtsPFw+9X tfnnQVvusjYow== Received: from johan by xi.lan with local (Exim 4.94.2) (envelope-from ) id 1oY1kI-0002H4-Fl; Tue, 13 Sep 2022 10:58:18 +0200 From: Johan Hovold To: Douglas Anderson , Dmitry Baryshkov , Rob Clark , Abhinav Kumar Cc: Andrzej Hajda , Neil Armstrong , Robert Foss , Laurent Pinchart , Jonas Karlman , Jernej Skrabec , Daniel Vetter , Sean Paul , Stephen Boyd , Bjorn Andersson , Manivannan Sadhasivam , Kuogee Hsieh , Steev Klimaszewski , dri-devel@lists.freedesktop.org, linux-arm-msm@vger.kernel.org, freedreno@lists.freedesktop.org, linux-kernel@vger.kernel.org, Johan Hovold , stable@vger.kernel.org Subject: [PATCH v2 02/10] drm/msm/dp: fix memory corruption with too many bridges Date: Tue, 13 Sep 2022 10:53:12 +0200 Message-Id: <20220913085320.8577-3-johan+linaro@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220913085320.8577-1-johan+linaro@kernel.org> References: <20220913085320.8577-1-johan+linaro@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org Add the missing sanity check on the bridge counter to avoid corrupting data beyond the fixed-sized bridge array in case there are ever more than eight bridges. Fixes: 8a3b4c17f863 ("drm/msm/dp: employ bridge mechanism for display enable and disable") Cc: stable@vger.kernel.org # 5.17 Signed-off-by: Johan Hovold Tested-by: Kuogee Hsieh Reviewed-by: Kuogee Hsieh Reviewed-by: Dmitry Baryshkov --- drivers/gpu/drm/msm/dp/dp_display.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/gpu/drm/msm/dp/dp_display.c b/drivers/gpu/drm/msm/dp/dp_display.c index 3e284fed8d30..fbe950edaefe 100644 --- a/drivers/gpu/drm/msm/dp/dp_display.c +++ b/drivers/gpu/drm/msm/dp/dp_display.c @@ -1604,6 +1604,12 @@ int msm_dp_modeset_init(struct msm_dp *dp_display, struct drm_device *dev, return -EINVAL; priv = dev->dev_private; + + if (priv->num_bridges == ARRAY_SIZE(priv->bridges)) { + DRM_DEV_ERROR(dev->dev, "too many bridges\n"); + return -ENOSPC; + } + dp_display->drm_dev = dev; dp_priv = container_of(dp_display, struct dp_display_private, dp_display);