From patchwork Tue Sep 14 14:02:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sven Peter X-Patchwork-Id: 511431 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2459AC433F5 for ; Tue, 14 Sep 2021 14:02:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0371560F92 for ; Tue, 14 Sep 2021 14:02:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233517AbhINOEE (ORCPT ); Tue, 14 Sep 2021 10:04:04 -0400 Received: from out3-smtp.messagingengine.com ([66.111.4.27]:48053 "EHLO out3-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232989AbhINOED (ORCPT ); Tue, 14 Sep 2021 10:04:03 -0400 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id CACFB5C0115; Tue, 14 Sep 2021 10:02:45 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Tue, 14 Sep 2021 10:02:45 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=svenpeter.dev; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; s=fm2; bh=0ZwXiZhi1QvrQjegd1Fbj2eOT8 sE6gEZauag+r4fBZA=; b=mVl9l/jsH6bPWuum34e9qxaaD/1Yo6p81jAOnw8kwe IlPgSIvCurASBPi0xbYYL3HdCJxNbfKV6+uObiRacQaGhI9oG8Yk+yu7svb4EgDn Ea+t1uaXPSPEndcxQBv6IekBCE73P5yQ7cFDCNConFB05ivphgioj0p8OgVLh2cI VcUTBirLnZNIEnIlzjxnMdsiWPGnd5JPlCYdl8SqK0z/qdMSBcSBwAEAFK5u64ju yqkHvRpePbqVP57AGR3GCogzHzjnqynvi77dWRaI1ZXcC4tXfNpv4cax6v29Goja H5REoeNQr7JT+AxKbxaS6+P+lxoMf5jBDDDUP2Q65rdg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :message-id:mime-version:subject:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; bh=0ZwXiZhi1QvrQjegd 1Fbj2eOT8sE6gEZauag+r4fBZA=; b=A679T0hg++tIr+hMnYrzytIOG3tVb/J7N saPp90aCdxt/J952eDfJKpfWYz6r3TERfIK4qWVW1fqfxzvQ1XR+GxM+QjuQZpZr XkzRjbYq2R40cUWFlvLIQp3Y1v3R3cf6B1ry7lT6JUzxWvqozyLszm7aDTLmw79/ HU0GHKe8U9LIglm/MrNzGAY/vZpXjrt7xfgjTnZnjqeA0LjBfTz8uAC4UO5gSMEs HLW1NTGZHzCpL49d0Op/beiEDG2t+znnTPvoTFfbyriJPWd/wXOrtd6PK0xpCOtD DkYGlXknNT/pL+Ea0OVrDhwFHcmBcoiOC/KO47lcFW/7HGK4yCbwg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvtddrudegledgjedtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvufffkffoggfgsedtkeertdertddtnecuhfhrohhmpefuvhgvnhcurfgv thgvrhcuoehsvhgvnhesshhvvghnphgvthgvrhdruggvvheqnecuggftrfgrthhtvghrnh epuefgleekvddtjefffeejheevleefveekgfduudfhgefhfeegtdehveejfefffffgnecu vehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepshhvvghnse hsvhgvnhhpvghtvghrrdguvghv X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 14 Sep 2021 10:02:44 -0400 (EDT) From: Sven Peter To: Heikki Krogerus Cc: Greg Kroah-Hartman , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Sven Peter Subject: [PATCH v2 1/3] usb: typec: tipd: Don't read/write more bytes than required Date: Tue, 14 Sep 2021 16:02:33 +0200 Message-Id: <20210914140235.65955-1-sven@svenpeter.dev> X-Mailer: git-send-email 2.30.1 (Apple Git-130) MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org tps6598x_block_read/write always read 65 bytes of data even when much less is required when I2C_FUNC_I2C is used. Reduce this to the correct number. Signed-off-by: Sven Peter Reviewed-by: Heikki Krogerus Reviewed-by: Heikki Krogerus --- no changes for v2 drivers/usb/typec/tipd/core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/usb/typec/tipd/core.c b/drivers/usb/typec/tipd/core.c index 21b3ae25c76d..c18ec3785592 100644 --- a/drivers/usb/typec/tipd/core.c +++ b/drivers/usb/typec/tipd/core.c @@ -123,7 +123,7 @@ tps6598x_block_read(struct tps6598x *tps, u8 reg, void *val, size_t len) if (!tps->i2c_protocol) return regmap_raw_read(tps->regmap, reg, val, len); - ret = regmap_raw_read(tps->regmap, reg, data, sizeof(data)); + ret = regmap_raw_read(tps->regmap, reg, data, len + 1); if (ret) return ret; @@ -145,7 +145,7 @@ static int tps6598x_block_write(struct tps6598x *tps, u8 reg, data[0] = len; memcpy(&data[1], val, len); - return regmap_raw_write(tps->regmap, reg, data, sizeof(data)); + return regmap_raw_write(tps->regmap, reg, data, len + 1); } static inline int tps6598x_read16(struct tps6598x *tps, u8 reg, u16 *val) From patchwork Tue Sep 14 14:02:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sven Peter X-Patchwork-Id: 512730 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D5803C433EF for ; Tue, 14 Sep 2021 14:02:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BCFB760F92 for ; Tue, 14 Sep 2021 14:02:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233593AbhINOEF (ORCPT ); Tue, 14 Sep 2021 10:04:05 -0400 Received: from out3-smtp.messagingengine.com ([66.111.4.27]:51613 "EHLO out3-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233550AbhINOEE (ORCPT ); Tue, 14 Sep 2021 10:04:04 -0400 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.nyi.internal (Postfix) with ESMTP id 41C3B5C01C0; Tue, 14 Sep 2021 10:02:47 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Tue, 14 Sep 2021 10:02:47 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=svenpeter.dev; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=fm2; bh=wLpknvgdOyW6A 0yW8l9BGg3ldSZFzQqA07ke3tiZCkY=; b=G/G6AZlq7M6KNE68rloL5gKhhboOu 15yU7TxQchD7JBBLMmkYJVBzkvvpOGZkSs7RUBsQy+DBOWLExqZGrZ3V/Aw2T4iL bVAEzpCIchVEXU2sOitsH1vSLXroRExvPYGhEoHI+k60YEf3RIWynNVbpD4aGtf/ zB6Z3PQR5ISyLlBnPGuqOS+G1hiagb0dVPQ6x9+7H5EAja/L8Nzwb/qo5CM8CXuq R1cJ6jGZ/dlHuY4dcevesgrD1ivAjo9+iJmK+H29boKxKDZqefbQVG3bIYrmSBmA UAH0/Vnn4yGosVODNW5Bl4Ds0Y3WxCFCm+xqHKtE08NhyhaipbZoc31Gg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; bh=wLpknvgdOyW6A0yW8l9BGg3ldSZFzQqA07ke3tiZCkY=; b=ekyFh0hd 5e1n/msTTWiP8z40ZRMbnS4SPqks+VA+ulQwhkV3KWe+OT574n0KrhMsTaR6y0sh 3ocrujen29xhCz2YHpipjC2Kuci0gsbyooeVIWo9i0gLmuubEczo01OgKKV3FfSc zuGHk3u8JxcmWO/UFFPbdzughDKm3obWVlD95AHL8KydEXeOmHUjJ5Vw55yLwDba g0F9o0hDW8R1hoOF86UzuZWKd9Kzg7DMfkTebK9GRupVgcjwyx4w5d0CuC75SYlZ K6vvVPpkmCHrsXXuuuH0Ir/HHcGM8lFPu9HO3JIKev3QQY8Cs82O+lkALrpI1KLf sC+JnpG9+e2I7Q== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvtddrudegledgjedtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpefuvhgvnhcu rfgvthgvrhcuoehsvhgvnhesshhvvghnphgvthgvrhdruggvvheqnecuggftrfgrthhtvg hrnheptedvkeetleeuffffhfekteetffeggffgveehieelueefvddtueffveevlefhfeej necuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepshhvvg hnsehsvhgvnhhpvghtvghrrdguvghv X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 14 Sep 2021 10:02:45 -0400 (EDT) From: Sven Peter To: Heikki Krogerus Cc: Greg Kroah-Hartman , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Sven Peter Subject: [PATCH v2 2/3] usb: typec: tipd: Add an additional overflow check Date: Tue, 14 Sep 2021 16:02:34 +0200 Message-Id: <20210914140235.65955-2-sven@svenpeter.dev> X-Mailer: git-send-email 2.30.1 (Apple Git-130) In-Reply-To: <20210914140235.65955-1-sven@svenpeter.dev> References: <20210914140235.65955-1-sven@svenpeter.dev> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org tps6598x_block_read already checks for the maximum length of the read but tps6598x_block_write does not. Add the symmetric check there as well. Signed-off-by: Sven Peter Reviewed-by: Heikki Krogerus --- v1 -> v2: - removed the WARN_ON to not crash machines running with panic-on-warn as pointed out by greg k-h drivers/usb/typec/tipd/core.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/usb/typec/tipd/core.c b/drivers/usb/typec/tipd/core.c index c18ec3785592..8c79ba17a157 100644 --- a/drivers/usb/typec/tipd/core.c +++ b/drivers/usb/typec/tipd/core.c @@ -139,6 +139,9 @@ static int tps6598x_block_write(struct tps6598x *tps, u8 reg, { u8 data[TPS_MAX_LEN + 1]; + if (len + 1 > sizeof(data)) + return -EINVAL; + if (!tps->i2c_protocol) return regmap_raw_write(tps->regmap, reg, val, len); From patchwork Tue Sep 14 14:02:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sven Peter X-Patchwork-Id: 511430 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 53D62C433EF for ; Tue, 14 Sep 2021 14:02:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 37F2160F92 for ; Tue, 14 Sep 2021 14:02:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233604AbhINOEJ (ORCPT ); Tue, 14 Sep 2021 10:04:09 -0400 Received: from out3-smtp.messagingengine.com ([66.111.4.27]:55511 "EHLO out3-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233572AbhINOEG (ORCPT ); Tue, 14 Sep 2021 10:04:06 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id B1E6B5C01C0; Tue, 14 Sep 2021 10:02:48 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Tue, 14 Sep 2021 10:02:48 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=svenpeter.dev; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=fm2; bh=9FXyPXkwkycT7 FpDBprBIlpPCJk+3RJgiVL3MbYdviE=; b=bKMd6ghzLgrKYQk8XadO3FM8GCSCw eRWRkjAM21IQ+Z2WCJVDDh0FFyNelPRfeewZnfWsCD6ea2zye+59QAlZMjt6rYk4 5R75UfmuFsYmqz776a+qVyQUXstIqIlvnNGMLCav6cyHsPsxxpaiBoTpKUxwZf8T y+9vkAc0UkkH4h0r2rm0VGbHa76U1MQJwEAN8zYUvaL8Mb7RHc/ahnW6Le/SN9gQ HyQOOcfAdmQ9Nkg35lZcQrOXO7bVm29nqthLFLs7ADhUMD0CU3L3zNr7txqo0wKW QkPhmDGiiY6wvBz56yfuPjRefRViYjAtvZWf2PTD259bwrmXnO9LBLVXg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; bh=9FXyPXkwkycT7FpDBprBIlpPCJk+3RJgiVL3MbYdviE=; b=EUe6hKO5 m6M6Ib2Pc29ULZbERVZyQpfN40C0lbci26ar3b0XUoP/OOvpPyqXwTJ7wxPn0UK3 KSS22yTHHiGhwFCZKJ40PH0Kf/uPhSI6UY3/p6HiMdY9YBLyPXVh1MfTKdwMeHdG x2kjFDmdLtdNvTuCWjC8ra5UPKAO1UpUf5+eji7eGVsmzTnztN1+LTTBrUxR452U ZkO7jHDC2gShD1Zk3lrr68aX8+q/02FyhMRsmEPTkqd8X2NHyfEYhe02l0ItFWAb nNWbH9Bo80JdtpI7z/DZVcWnwcfo1yMTMFpZ4Ki2nyZ1+TYOmL9ywHCr5aNOFvjH 2u38RUczPsNJWQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvtddrudegledgjedtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpefuvhgvnhcu rfgvthgvrhcuoehsvhgvnhesshhvvghnphgvthgvrhdruggvvheqnecuggftrfgrthhtvg hrnheptedvkeetleeuffffhfekteetffeggffgveehieelueefvddtueffveevlefhfeej necuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepshhvvg hnsehsvhgvnhhpvghtvghrrdguvghv X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 14 Sep 2021 10:02:47 -0400 (EDT) From: Sven Peter To: Heikki Krogerus Cc: Greg Kroah-Hartman , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Sven Peter Subject: [PATCH v2 3/3] usb: typec: tipd: Remove WARN_ON in tps6598x_block_read Date: Tue, 14 Sep 2021 16:02:35 +0200 Message-Id: <20210914140235.65955-3-sven@svenpeter.dev> X-Mailer: git-send-email 2.30.1 (Apple Git-130) In-Reply-To: <20210914140235.65955-1-sven@svenpeter.dev> References: <20210914140235.65955-1-sven@svenpeter.dev> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Calling tps6598x_block_read with a higher than allowed len can be handled by just returning an error. There's no need to crash systems with panic-on-warn enabled. Signed-off-by: Sven Peter Reviewed-by: Heikki Krogerus --- v1 -> v2: - added this patch to also remove the WARN_ON in tps6598x_block_read as suggested by greg k-h drivers/usb/typec/tipd/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/usb/typec/tipd/core.c b/drivers/usb/typec/tipd/core.c index 8c79ba17a157..93e56291f0cf 100644 --- a/drivers/usb/typec/tipd/core.c +++ b/drivers/usb/typec/tipd/core.c @@ -117,7 +117,7 @@ tps6598x_block_read(struct tps6598x *tps, u8 reg, void *val, size_t len) u8 data[TPS_MAX_LEN + 1]; int ret; - if (WARN_ON(len + 1 > sizeof(data))) + if (len + 1 > sizeof(data)) return -EINVAL; if (!tps->i2c_protocol)