From patchwork Thu Dec 14 20:37:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Anderson X-Patchwork-Id: 178897 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:3b04:b0:fb:cd0c:d3e with SMTP id c4csp8834392dys; Thu, 14 Dec 2023 12:38:35 -0800 (PST) X-Google-Smtp-Source: AGHT+IH8GfyL2otXwQNy4HcZ4Hh65foEtXCf/UVcTiarfhTPwK/ZbiG3txhLRfddZK26ecwVqxXv X-Received: by 2002:a05:620a:19a6:b0:77d:98c3:1eda with SMTP id bm38-20020a05620a19a600b0077d98c31edamr13782795qkb.43.1702586315094; Thu, 14 Dec 2023 12:38:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702586315; cv=none; d=google.com; s=arc-20160816; b=GglJucmcyWhtav8nKhhCTmWZAhE7yDoEccAE9ATUOwKAVaE7NYJ8OUu5Fm77gLZZUi 6MbZN6hrtz2EjY7fC3KkGcdY4GNA+CItLqKsZyVkrqiIH03rzvcFA1IkKBRX+JW7d3S9 aUt9RQQNNxkOb6x5cWLk6FlbsJQcESq5JoAWRdv6vTjAE99fciCxi7eLXsqLbQT+Iqtf BJI25gmLhUiE0+JTbVuMmcZ4Z5DW1FDLpU3uFNq1HJw/gZ9ocs10UlteFyRAyOq06IX8 RIxPslyFcS1OiGt249BYtANyJeYv1oEHAOXnL0szEKlClesGaP/9VZ5Y0Q6jNoB/PizO SDEQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=CEbYOeExhWxrQcvIrSnW0dzfFwJIoL+EWRTjsEQRQR4=; fh=0uTLTr2riDmlYDujtHZf/aXqxPzrYy60z/zevNy6jwI=; b=H9WX0um0TCE9S16HjMvcDaHd8frvOsHzIZ1qlgsv6a523DWHnE6XRnA1KM0PCp5KWB +i8sxxNQ9YUQ/1gnjnl9obUR6lJhRYmjijMEVBiVKzmTWtBR9PdZgt5JtQ/e3i2e7snO LbC1Hx7nkViMXK44WZAdiJMnBELiBZe1pJFS0YLLNDElS33Z58GQqRt1rfXsaHDZwBGl IGJiW89Au0LO3Mj31crmqdqqmHsZZdF9e/N5U6rmbohzWFCaduy/3bfGkCLOv8E6cW1O daK4hvRuSMVtvPg80u50VF1TJpzTqsRsv7dEXhffr1U5lyz5a9u2yrV5P0SUyyrT27z8 iurA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=iduOy+Fy; spf=pass (google.com: domain of linux-kernel+bounces-77-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-77-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id s17-20020a05620a29d100b0077f63268fd3si13303701qkp.48.2023.12.14.12.38.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Dec 2023 12:38:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-77-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=iduOy+Fy; spf=pass (google.com: domain of linux-kernel+bounces-77-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-77-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id DE6591C21B4D for ; Thu, 14 Dec 2023 20:38:34 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E5ED06D1AB; Thu, 14 Dec 2023 20:38:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="iduOy+Fy" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-pl1-f172.google.com (mail-pl1-f172.google.com [209.85.214.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E695A2112 for ; Thu, 14 Dec 2023 20:38:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Received: by mail-pl1-f172.google.com with SMTP id d9443c01a7336-1d307cf18fdso31313485ad.3 for ; Thu, 14 Dec 2023 12:38:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1702586290; x=1703191090; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=CEbYOeExhWxrQcvIrSnW0dzfFwJIoL+EWRTjsEQRQR4=; b=iduOy+FypuQQ7pXz+XyjB+/lRThjfh9ttCsMv8zreqNCWM5WTv2La6OOI45l7Y13sg RoW6l87zpZB0Y/jmLzcpXM6pPlPYEo1bG6yen4KwUri8ELKBdeHBwhCXk2zffU9trDE2 YNhbh1i/KL1vomXJzonBC2PQweZVQMNCqkNiA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702586290; x=1703191090; 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=CEbYOeExhWxrQcvIrSnW0dzfFwJIoL+EWRTjsEQRQR4=; b=thyTXEuI9nUGXyffmrj+e70HfHXX3tG+zACETkFEvyZ/xhkz29z/pg0AAnbZH1JstF X8995G9IFWCCdqusQ+RArU92G+72euy/8toIxLxRWyhAhMfBaPlDlXLvBVVNgkgfEgu1 xiXRzcZ0X0nIlpVRGndAxZXKarF/0chqmPW0HQS8iU8xr+nSS38mQPt1ifMqqRj79SVx NDlq+rjs8ImigIeMxXev+QD/hjOQm1R59Zqw7hO22Vvm9D1WvdVjycA2fRIPcoGYvdft yEsCPPwC/Iu+1p0/t+YeOrroJUtpqBM42D/N9deI1XgdIfCqeOZJfwye9FrH0ugL88Z9 L3Eg== X-Gm-Message-State: AOJu0Yx6lvACBIjLeEC8z6UqYUJfXzmjT6+gVhivMS7QHaVJFZdYrRmL jsSHE3Pdqn1dzXsKh+Okd/f4Lw== X-Received: by 2002:a17:902:ec89:b0:1d0:c26d:e509 with SMTP id x9-20020a170902ec8900b001d0c26de509mr6417151plg.108.1702586290186; Thu, 14 Dec 2023 12:38:10 -0800 (PST) Received: from tictac2.mtv.corp.google.com ([2620:15c:9d:2:9d0c:9bd0:17f6:8236]) by smtp.gmail.com with ESMTPSA id y18-20020a170902b49200b001cfc2e0a82fsm12799081plr.26.2023.12.14.12.38.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Dec 2023 12:38:09 -0800 (PST) From: Douglas Anderson To: dri-devel@lists.freedesktop.org Cc: Guenter Roeck , Douglas Anderson , Andrzej Hajda , Daniel Vetter , David Airlie , Jernej Skrabec , Jonas Karlman , Laurent Pinchart , Maarten Lankhorst , Maxime Ripard , Neil Armstrong , Philip Chen , Robert Foss , Sam Ravnborg , Stephen Boyd , Thomas Zimmermann , linux-kernel@vger.kernel.org Subject: [PATCH v3 1/2] drm/bridge: parade-ps8640: Never store more than msg->size bytes in AUX xfer Date: Thu, 14 Dec 2023 12:37:51 -0800 Message-ID: <20231214123752.v3.1.I9d1afcaad76a3e2c0ca046dc4adbc2b632c22eda@changeid> X-Mailer: git-send-email 2.43.0.472.g3155946c3a-goog Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785290800195907108 X-GMAIL-MSGID: 1785291148056465713 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 Reviewed-by: Guenter Roeck Reviewed-by: Stephen Boyd --- Changes in v3: - Never return more than msg->size as the number of bytes we read. Changes in v2: - Still read all the bytes; just don't write them all to the buffer. drivers/gpu/drm/bridge/parade-ps8640.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/bridge/parade-ps8640.c b/drivers/gpu/drm/bridge/parade-ps8640.c index 8161b1a1a4b1..d264b80d909d 100644 --- a/drivers/gpu/drm/bridge/parade-ps8640.c +++ b/drivers/gpu/drm/bridge/parade-ps8640.c @@ -330,11 +330,12 @@ static ssize_t ps8640_aux_transfer_msg(struct drm_dp_aux *aux, return ret; } - buf[i] = data; + if (i < msg->size) + buf[i] = data; } } - return len; + return min(len, msg->size); } static ssize_t ps8640_aux_transfer(struct drm_dp_aux *aux,