From patchwork Thu Dec 14 20:32:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Anderson X-Patchwork-Id: 13493594 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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3A692C4332F for ; Thu, 14 Dec 2023 20:32:35 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 2DDCE10E260; Thu, 14 Dec 2023 20:32:34 +0000 (UTC) Received: from mail-pf1-x431.google.com (mail-pf1-x431.google.com [IPv6:2607:f8b0:4864:20::431]) by gabe.freedesktop.org (Postfix) with ESMTPS id 4E34F10E260 for ; Thu, 14 Dec 2023 20:32:31 +0000 (UTC) Received: by mail-pf1-x431.google.com with SMTP id d2e1a72fcca58-6d0a679fca7so2299160b3a.2 for ; Thu, 14 Dec 2023 12:32:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1702585950; x=1703190750; darn=lists.freedesktop.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=f60jMhHn2NrJuxYV7wfhO+MfVtVZGHjXqg7DUtfV+AE=; b=ZnB0VEJmvr1z+NwrDzpBSd4owsCpWVTMUshDDMMGZY/Kd2TdoCrQBRaPZP8FzZUfqV 3qLpty7nGj9oJlvC8YwhqR1RS/VAXgyOuGRUYdk06bdphwnzHhQB/Fx312Y3Ib+Ewc3q /sgI+Gca8PklMx7n+6qQF60My6BhWVkw4B49o= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702585950; x=1703190750; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=f60jMhHn2NrJuxYV7wfhO+MfVtVZGHjXqg7DUtfV+AE=; b=ubgMHhhXdyiLLejmfNmtrWwHMxYx+7FlU79rC1Odrmru4IC549OEgSj6hjnTpsW7fi wJi52LJKIR+FMs53z3Ge6D+KbI+yKNnllXjol9tuBhIcIjXCVTdfGlmfnQJVqYsmrOmY 4EpWAohwXlcsgQ2lBjXhJMfosiIv53+ur11evHObPnGTr995GdnPnaAYY596CCjsmn0q gb8mer30sdSuDLBrLPVd9dn4KP6ip3VkyLLGVUSO/RpvGgnOgVzliAZQwF4tIzHjhH/m L4eaSFhq2iPffKCHhPUl/Xy1HF+y8bWLEfbvnhFWM8XwhNc81P0mk8JEoykNXl5kT3cL /rJg== X-Gm-Message-State: AOJu0YzT2mJbp+rIISv+TsYG5a29EPOAiXhv/9nvH59BFqw0v7Aq4Whl Cpq0JasUUcg09FgDoG+P4T6frfXBwilnj9RSwjhOkg== X-Google-Smtp-Source: AGHT+IEGOaFAhYexjfwieKxbwPZ2Kk2OttwK4zxJvf+kkUnKqypsKNE1O7AnNxvzBqtTxzEABU/lKA== X-Received: by 2002:a05:6a21:19c:b0:187:8bd4:e1b6 with SMTP id le28-20020a056a21019c00b001878bd4e1b6mr6533286pzb.31.1702585949943; Thu, 14 Dec 2023 12:32:29 -0800 (PST) Received: from tictac2.mtv.corp.google.com ([2620:15c:9d:2:9d0c:9bd0:17f6:8236]) by smtp.gmail.com with ESMTPSA id 5-20020a17090a018500b0028658657e9csm14636228pjc.46.2023.12.14.12.32.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Dec 2023 12:32:29 -0800 (PST) From: Douglas Anderson To: dri-devel@lists.freedesktop.org Subject: [PATCH v2 1/2] drm/bridge: parade-ps8640: Never store more than msg->size bytes in AUX xfer Date: Thu, 14 Dec 2023 12:32:05 -0800 Message-ID: <20231214123205.v2.1.I9d1afcaad76a3e2c0ca046dc4adbc2b632c22eda@changeid> X-Mailer: git-send-email 2.43.0.472.g3155946c3a-goog MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Maxime Ripard , Neil Armstrong , Philip Chen , Robert Foss , Andrzej Hajda , Thomas Zimmermann , Jonas Karlman , Sam Ravnborg , Douglas Anderson , Jernej Skrabec , Stephen Boyd , Laurent Pinchart , Guenter Roeck , linux-kernel@vger.kernel.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" While testing, I happened to notice a random crash that looked like: Kernel panic - not syncing: stack-protector: Kernel stack is corrupted in: drm_dp_dpcd_probe+0x120/0x120 Analysis of drm_dp_dpcd_probe() shows that we pass in a 1-byte buffer (allocated on the stack) to the aux->transfer() function. Presumably if the aux->transfer() writes more than one byte to this buffer then we're in a bad shape. Dropping into kgdb, I noticed that "aux->transfer" pointed at ps8640_aux_transfer(). Reading through ps8640_aux_transfer(), I can see that there are cases where it could write more bytes to msg->buffer than were specified by msg->size. This could happen if the hardware reported back something bogus to us. Let's fix this so we never write more than msg->size bytes. We'll still read all the bytes from the hardware just in case the hardware requires it since the aux transfer data comes through an auto-incrementing register. NOTE: I have no actual way to reproduce this issue but it seems likely this is what was happening in the crash I looked at. Fixes: 13afcdd7277e ("drm/bridge: parade-ps8640: Add support for AUX channel") Signed-off-by: Douglas Anderson --- Changes in v2: - Still read all the bytes; just don't write them all to the buffer. drivers/gpu/drm/bridge/parade-ps8640.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/bridge/parade-ps8640.c b/drivers/gpu/drm/bridge/parade-ps8640.c index 8161b1a1a4b1..dfb97fbb5be6 100644 --- a/drivers/gpu/drm/bridge/parade-ps8640.c +++ b/drivers/gpu/drm/bridge/parade-ps8640.c @@ -330,7 +330,8 @@ static ssize_t ps8640_aux_transfer_msg(struct drm_dp_aux *aux, return ret; } - buf[i] = data; + if (i < msg->size) + buf[i] = data; } } From patchwork Thu Dec 14 20:32:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Anderson X-Patchwork-Id: 13493595 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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1320CC4332F for ; Thu, 14 Dec 2023 20:32:39 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 7C00B10E266; Thu, 14 Dec 2023 20:32:34 +0000 (UTC) Received: from mail-pj1-x1036.google.com (mail-pj1-x1036.google.com [IPv6:2607:f8b0:4864:20::1036]) by gabe.freedesktop.org (Postfix) with ESMTPS id 1D96C10E260 for ; Thu, 14 Dec 2023 20:32:33 +0000 (UTC) Received: by mail-pj1-x1036.google.com with SMTP id 98e67ed59e1d1-286b45c5a8dso8894543a91.1 for ; Thu, 14 Dec 2023 12:32:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1702585952; x=1703190752; darn=lists.freedesktop.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=a2YE6Q1lspxSdRvHtWt0D327Ubgh2oADnGrrLN11Egc=; b=PlpjO1lSO7ZUMs2w/nqPpZmdcYJ1MztCWVgaZ+VLM99qY+NktASHUMAAn2id5hTvDQ GlN76BZHLhEK8itl95iMM6JQnq1vOf9xTaJ6xj5UovE0hFLi3zG2HY7wb6gU/8nc0nus v/G3BeAX9PF1hWKKBFC1RU4ZEbVL+15mv5U7s= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702585952; x=1703190752; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=a2YE6Q1lspxSdRvHtWt0D327Ubgh2oADnGrrLN11Egc=; b=w0OLI8cGGOHwBDSvcUlxmtTVpsDJiWRrksXJxKE0cZaUP6MHnKoIb1/eHGyxjH44gf EMvQ4ZXfoj3h1R9OrI+nTSgAdW2v3MDh3RVEhx/el7xpAxrUoA1swJ03ExEloZQwXC0k DmqnHqq1vZbyw3mcA6kYK7RldlOyVaf+Fr8jWLUTHyAkiQODox+EWOeGmKM+DaK/8oGu pqhjLbhF5vH6kBxTJasq/7YCk3hdS6PJbl+riCjkO70wG7r2DNjZEz8E8nxrThU19sqq 2QB0OetdaYplecbwLtpU5OStq3aqpBiFXNuGkWNpqHpkLLQl6SWbXT/73+EqKLTUpCaK /pjw== X-Gm-Message-State: AOJu0YzoQSEcbg7hXFavgWu3vsVdXxrYHCZ3tmsfZTxuyJgGQmQHlR7/ O6LbEmw5bYkP8QqBHEquvgKOrEN+kqmFCB3ojl/Bjg== X-Google-Smtp-Source: AGHT+IGNPg13lWVuRvuzTZ1e20CqXVgpjSGrsj9auMAxG5qBysEZ8PL64spXTG5LUtb8S2nor6ulXg== X-Received: by 2002:a17:90a:8543:b0:28a:ce23:af33 with SMTP id a3-20020a17090a854300b0028ace23af33mr3823080pjw.42.1702585951955; Thu, 14 Dec 2023 12:32:31 -0800 (PST) Received: from tictac2.mtv.corp.google.com ([2620:15c:9d:2:9d0c:9bd0:17f6:8236]) by smtp.gmail.com with ESMTPSA id 5-20020a17090a018500b0028658657e9csm14636228pjc.46.2023.12.14.12.32.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Dec 2023 12:32:31 -0800 (PST) From: Douglas Anderson To: dri-devel@lists.freedesktop.org Subject: [PATCH v2 2/2] drm/bridge: ti-sn65dsi86: Never store more than msg->size bytes in AUX xfer Date: Thu, 14 Dec 2023 12:32:06 -0800 Message-ID: <20231214123205.v2.2.I7b83c0f31aeedc6b1dc98c7c741d3e1f94f040f8@changeid> X-Mailer: git-send-email 2.43.0.472.g3155946c3a-goog In-Reply-To: <20231214123205.v2.1.I9d1afcaad76a3e2c0ca046dc4adbc2b632c22eda@changeid> References: <20231214123205.v2.1.I9d1afcaad76a3e2c0ca046dc4adbc2b632c22eda@changeid> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Maxime Ripard , Neil Armstrong , Robert Foss , Andrzej Hajda , Thomas Zimmermann , Jonas Karlman , Sam Ravnborg , Douglas Anderson , Jernej Skrabec , Stephen Boyd , Laurent Pinchart , Guenter Roeck , linux-kernel@vger.kernel.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" For aux reads, the value `msg->size` indicates the size of the buffer provided by `msg->buffer`. We should never in any circumstances write more bytes to the buffer since it may overflow the buffer. In the ti-sn65dsi86 driver there is one code path that reads the transfer length from hardware. Even though it's never been seen to be a problem, we should make extra sure that the hardware isn't increasing the length since doing so would cause us to overrun the buffer. Fixes: 982f589bde7a ("drm/bridge: ti-sn65dsi86: Update reply on aux failures") Signed-off-by: Douglas Anderson Reviewed-by: Robert Foss --- Changes in v2: - Updated patch subject to match ps8640 patch. drivers/gpu/drm/bridge/ti-sn65dsi86.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/bridge/ti-sn65dsi86.c b/drivers/gpu/drm/bridge/ti-sn65dsi86.c index 9095d1453710..62cc3893dca5 100644 --- a/drivers/gpu/drm/bridge/ti-sn65dsi86.c +++ b/drivers/gpu/drm/bridge/ti-sn65dsi86.c @@ -527,6 +527,7 @@ static ssize_t ti_sn_aux_transfer(struct drm_dp_aux *aux, u32 request_val = AUX_CMD_REQ(msg->request); u8 *buf = msg->buffer; unsigned int len = msg->size; + unsigned int short_len; unsigned int val; int ret; u8 addr_len[SN_AUX_LENGTH_REG + 1 - SN_AUX_ADDR_19_16_REG]; @@ -600,7 +601,8 @@ static ssize_t ti_sn_aux_transfer(struct drm_dp_aux *aux, } if (val & AUX_IRQ_STATUS_AUX_SHORT) { - ret = regmap_read(pdata->regmap, SN_AUX_LENGTH_REG, &len); + ret = regmap_read(pdata->regmap, SN_AUX_LENGTH_REG, &short_len); + len = min(len, short_len); if (ret) goto exit; } else if (val & AUX_IRQ_STATUS_NAT_I2C_FAIL) {