From patchwork Tue Sep 13 08:53:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 12974562 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 1CAEFC6FA8A for ; Tue, 13 Sep 2022 08:58:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231506AbiIMI60 (ORCPT ); Tue, 13 Sep 2022 04:58:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37088 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231216AbiIMI6X (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 A35363DF1F; 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 3F2DB61355; Tue, 13 Sep 2022 08:58:20 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8B8B0C433D7; 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=OxlY1wqQsLgLsZL8UM+h11nCPJtAdLLq4mxJl0UHIGw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HdFZsnvDfetEuZ9OOsaqe4P3XkCn6W8iV5G29D9GPmOToOSPYZkbEE1l52kOkQSca j27BIh2w2t0LCq4aOyNPO/ofXfJbQwoZsRDTfL8AnWtjk0XxfZEMKexa0+M9E1IIjT 56AsIttLFTLUK9MrlFL7+JV/ZX4Xyq3DO7m2AUOnHaIJxlvK+W/h/7PiavPh+GQvEH EI06cyBWoIzxSGBjlQKYyjVc039GCTaws3fffOqJOkX6rWwGoK8CvInyjFdMMYAQJU buqsXsvTM3LbM1Ocxu/rNV5mcWksHgoR7JttMYzWHEwUIK55rgJ1HTROfZB/pZJsAO DHNw9ry6NA7mQ== Received: from johan by xi.lan with local (Exim 4.94.2) (envelope-from ) id 1oY1kI-0002H6-Il; 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 03/10] drm/msm/dsi: fix memory corruption with too many bridges Date: Tue, 13 Sep 2022 10:53:13 +0200 Message-Id: <20220913085320.8577-4-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: a689554ba6ed ("drm/msm: Initial add DSI connector support") Cc: stable@vger.kernel.org # 4.1 Signed-off-by: Johan Hovold Tested-by: Kuogee Hsieh Reviewed-by: Kuogee Hsieh Reviewed-by: Dmitry Baryshkov --- drivers/gpu/drm/msm/dsi/dsi.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/gpu/drm/msm/dsi/dsi.c b/drivers/gpu/drm/msm/dsi/dsi.c index 39bbabb5daf6..8a95c744972a 100644 --- a/drivers/gpu/drm/msm/dsi/dsi.c +++ b/drivers/gpu/drm/msm/dsi/dsi.c @@ -218,6 +218,12 @@ int msm_dsi_modeset_init(struct msm_dsi *msm_dsi, 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; + } + msm_dsi->dev = dev; ret = msm_dsi_host_modeset_init(msm_dsi->host, dev);