Received: by 2002:ab2:60d1:0:b0:1f7:5705:b850 with SMTP id i17csp559018lqm; Wed, 1 May 2024 08:48:17 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWyo9ci2kphJOitqXxQkJUsU71me5ob4+lyhwDXBC+cTwpD4HQfkeyEJsBpibGeQYu+/56vA87gR7oJbD+RZlkrUzENnG2RbUTTQ0C95A== X-Google-Smtp-Source: AGHT+IEiIH+9sBcsvMhFuB73z56aMtcH9UKFXU1nhvyWSJ8XwuKvqHFUCrNOp5iLRGhxAlO/5W5C X-Received: by 2002:a05:6a20:7483:b0:1a7:a2f2:c70b with SMTP id p3-20020a056a20748300b001a7a2f2c70bmr3804113pzd.22.1714578496863; Wed, 01 May 2024 08:48:16 -0700 (PDT) Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id c6-20020a631c46000000b0060764a6a26fsi13307767pgm.532.2024.05.01.08.48.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 May 2024 08:48:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-165503-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@chromium.org header.s=google header.b=j6aJ4JYp; arc=fail (body hash mismatch); spf=pass (google.com: domain of linux-kernel+bounces-165503-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-165503-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 0ECD6281CB1 for ; Wed, 1 May 2024 15:43:36 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 72D9512FF67; Wed, 1 May 2024 15:43:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="j6aJ4JYp" Received: from mail-pf1-f180.google.com (mail-pf1-f180.google.com [209.85.210.180]) (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 2F38912FB09 for ; Wed, 1 May 2024 15:43:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.180 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714578202; cv=none; b=XWQclD5UWd7sOAVhRNLYgfzvnEeDGiKBmKRlX6dL5pgsimfWzEfO10ekv9HT4LmaGcMGfQs7TBwN3MyhjFUQorCU4UtPJKXmceOg+Kh71/te7b2mbeqKIuAwt/HFmyo1E47DgXGLqRCXLpHJ+NKlNDxN75HMa+BUtV2XSdnrg6s= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714578202; c=relaxed/simple; bh=CHn6dd9juJ7QU5kf8EIUTCmIhfjE5Sww12t5qi+aUgg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tP9WV0/PBdoV2+1B1HSMim47lzMWVnQB55Ul1mvGClwwKtRZqW6KCLNrL6PjM5EIGFHNMo2xmZr1g4VQIFsGeVKLpEm6fyjLUSHgwVkFP059fbD/x0jm2vy4E762JWINs1G4g5aXRfK/5wdZzoHqWkJpCTQh9vP3Mri/Mz2Eg2U= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=j6aJ4JYp; arc=none smtp.client-ip=209.85.210.180 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-pf1-f180.google.com with SMTP id d2e1a72fcca58-6edb76d83d0so5978443b3a.0 for ; Wed, 01 May 2024 08:43:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1714578200; x=1715183000; darn=vger.kernel.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=IqSRaJ+I/NgAMp1CRzQlMWp8eVTN4Fv5wLPbhbxPoyI=; b=j6aJ4JYpowemZ8CpNRS0SWwYCLoo4QD+CzHSz+cmugY7cc/mT/YsotZ1lAj9ZCKnrJ tqKTqwUiUmlY9J+08bC/UbYrZ7ZYSU7i5dtvdNFcj4BX6Rio06/WItBIklS3UvifuvSA 9ROBBay844DA2zQjkNu/R4SlhR7TWJea0W2a4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714578200; x=1715183000; 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=IqSRaJ+I/NgAMp1CRzQlMWp8eVTN4Fv5wLPbhbxPoyI=; b=TeFLjENDBrGZtdgmiH9YARhoUfYdGsb9rkXNxyAlSlO3rqfuLfIKhFgzv4MWCTYIts HDCjWWoi8NR2lUGBW6uIXieNCOnH9XqOSOWrfLOZLpwE844tYsEKuwjxKVy3IQ4wJQdC g0JAaDJYR3UP2hRVfIi8v6rfsQwAt5omsKIPMLrdwAem+XQJHuu0Wvtxy/OP43wK0xHD vGJ2p97WibMMidGbhsX9BPdPQ05tLtGhcyrjYX+VHXUtq6cxx20g+mA+bqUOHHZgZhF5 iqea4NzCAeZpAEnT/zntOdIoXDnXbG9dqhHjsj1VCKJMSk6aXjW4GvoKuIPTS6WscJYp U/rA== X-Forwarded-Encrypted: i=1; AJvYcCUnJ1+WLBL1iK+Qnh87VhU5A1A5BAknbxrbVwfUdje3J0rrDDJWVJXi1wVhLpmKqdPFbAeGlgFXqKAuB4+SuMEowwg1roh/0vGNlBo0 X-Gm-Message-State: AOJu0YwFvMCdUogMRD5hVWLAQqgmP8ztVwtsMTcEO1OOHxfip19vsYwZ B52nhr4pb5Pz9fM5FWjknftQWW0u8dxfMYcO1ye7mKP46dVAD8UDT/FgToVQwg== X-Received: by 2002:a05:6a20:2593:b0:1a9:8251:41ba with SMTP id k19-20020a056a20259300b001a9825141bamr3504545pzd.51.1714578200409; Wed, 01 May 2024 08:43:20 -0700 (PDT) Received: from dianders.sjc.corp.google.com ([2620:15c:9d:2:e886:8de:19a2:55b0]) by smtp.gmail.com with ESMTPSA id fb12-20020a056a002d8c00b006f3ec69bc09sm7717924pfb.75.2024.05.01.08.43.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 May 2024 08:43:19 -0700 (PDT) From: Douglas Anderson To: dri-devel@lists.freedesktop.org Cc: Linus Walleij , Jani Nikula , Dmitry Baryshkov , Cong Yang , Hsin-Yi Wang , Brian Norris , Sam Ravnborg , Neil Armstrong , Javier Martinez Canillas , Joel Selvaraj , lvzhaoxiong@huaqin.corp-partner.google.com, Douglas Anderson , Daniel Vetter , David Airlie , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , linux-kernel@vger.kernel.org Subject: [PATCH v3 1/9] drm/mipi-dsi: Fix theoretical int overflow in mipi_dsi_dcs_write_seq() Date: Wed, 1 May 2024 08:41:04 -0700 Message-ID: <20240501084109.v3.1.I30fa4c8348ea316c886ef8a522a52fed617f930d@changeid> X-Mailer: git-send-email 2.45.0.rc0.197.gbae5840b3b-goog In-Reply-To: <20240501154251.3302887-1-dianders@chromium.org> References: <20240501154251.3302887-1-dianders@chromium.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit The mipi_dsi_dcs_write_seq() macro makes a call to mipi_dsi_dcs_write_buffer() which returns a type ssize_t. The macro then stores it in an int and checks to see if it's negative. This could theoretically be a problem if "ssize_t" is larger than "int". To see the issue, imagine that "ssize_t" is 32-bits and "int" is 16-bits, you could see a problem if there was some code out there that looked like: mipi_dsi_dcs_write_seq(dsi, cmd, <32767 bytes as arguments>); ..since we'd get back that 32768 bytes were transferred and 32768 stored in a 16-bit int would look negative. Though there are no callsites where we'd actually hit this (even if "int" was only 16-bit), it's cleaner to make the types match so let's fix it. Fixes: 2a9e9daf7523 ("drm/mipi-dsi: Introduce mipi_dsi_dcs_write_seq macro") Signed-off-by: Douglas Anderson --- Changes in v3: - Use %zd in print instead of casting errors to int. Changes in v2: - New include/drm/drm_mipi_dsi.h | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/include/drm/drm_mipi_dsi.h b/include/drm/drm_mipi_dsi.h index 82b1cc434ea3..70ce0b8cbc68 100644 --- a/include/drm/drm_mipi_dsi.h +++ b/include/drm/drm_mipi_dsi.h @@ -333,18 +333,18 @@ int mipi_dsi_dcs_get_display_brightness_large(struct mipi_dsi_device *dsi, * @cmd: Command * @seq: buffer containing data to be transmitted */ -#define mipi_dsi_dcs_write_seq(dsi, cmd, seq...) \ - do { \ - static const u8 d[] = { cmd, seq }; \ - struct device *dev = &dsi->dev; \ - int ret; \ - ret = mipi_dsi_dcs_write_buffer(dsi, d, ARRAY_SIZE(d)); \ - if (ret < 0) { \ - dev_err_ratelimited( \ - dev, "sending command %#02x failed: %d\n", \ - cmd, ret); \ - return ret; \ - } \ +#define mipi_dsi_dcs_write_seq(dsi, cmd, seq...) \ + do { \ + static const u8 d[] = { cmd, seq }; \ + struct device *dev = &dsi->dev; \ + ssize_t ret; \ + ret = mipi_dsi_dcs_write_buffer(dsi, d, ARRAY_SIZE(d)); \ + if (ret < 0) { \ + dev_err_ratelimited( \ + dev, "sending command %#02x failed: %zd\n", \ + cmd, ret); \ + return ret; \ + } \ } while (0) /** -- 2.45.0.rc0.197.gbae5840b3b-goog