All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Heiner Kallweit <hkallweit1@gmail.com>,
	Jean Delvare <jdelvare@suse.de>, Wolfram Sang <wsa@kernel.org>,
	Sasha Levin <sashal@kernel.org>,
	jdelvare@suse.com, linux-i2c@vger.kernel.org
Subject: [PATCH AUTOSEL 4.4 05/12] i2c: i801: Don't silently correct invalid transfer size
Date: Mon, 17 Jan 2022 12:07:49 -0500	[thread overview]
Message-ID: <20220117170757.1473318-5-sashal@kernel.org> (raw)
In-Reply-To: <20220117170757.1473318-1-sashal@kernel.org>

From: Heiner Kallweit <hkallweit1@gmail.com>

[ Upstream commit effa453168a7eeb8a562ff4edc1dbf9067360a61 ]

If an invalid block size is provided, reject it instead of silently
changing it to a supported value. Especially critical I see the case of
a write transfer with block length 0. In this case we have no guarantee
that the byte we would write is valid. When silently reducing a read to
32 bytes then we don't return an error and the caller may falsely
assume that we returned the full requested data.

If this change should break any (broken) caller, then I think we should
fix the caller.

Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
Reviewed-by: Jean Delvare <jdelvare@suse.de>
Signed-off-by: Wolfram Sang <wsa@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 drivers/i2c/busses/i2c-i801.c | 15 +++++----------
 1 file changed, 5 insertions(+), 10 deletions(-)

diff --git a/drivers/i2c/busses/i2c-i801.c b/drivers/i2c/busses/i2c-i801.c
index 4399016a6caba..73026c00220c2 100644
--- a/drivers/i2c/busses/i2c-i801.c
+++ b/drivers/i2c/busses/i2c-i801.c
@@ -669,6 +669,11 @@ static int i801_block_transaction(struct i801_priv *priv,
 	int result = 0;
 	unsigned char hostc;
 
+	if (read_write == I2C_SMBUS_READ && command == I2C_SMBUS_BLOCK_DATA)
+		data->block[0] = I2C_SMBUS_BLOCK_MAX;
+	else if (data->block[0] < 1 || data->block[0] > I2C_SMBUS_BLOCK_MAX)
+		return -EPROTO;
+
 	if (command == I2C_SMBUS_I2C_BLOCK_DATA) {
 		if (read_write == I2C_SMBUS_WRITE) {
 			/* set I2C_EN bit in configuration register */
@@ -682,16 +687,6 @@ static int i801_block_transaction(struct i801_priv *priv,
 		}
 	}
 
-	if (read_write == I2C_SMBUS_WRITE
-	 || command == I2C_SMBUS_I2C_BLOCK_DATA) {
-		if (data->block[0] < 1)
-			data->block[0] = 1;
-		if (data->block[0] > I2C_SMBUS_BLOCK_MAX)
-			data->block[0] = I2C_SMBUS_BLOCK_MAX;
-	} else {
-		data->block[0] = 32;	/* max for SMBus block reads */
-	}
-
 	/* Experience has shown that the block buffer can only be used for
 	   SMBus (not I2C) block transactions, even though the datasheet
 	   doesn't mention this limitation. */
-- 
2.34.1


  parent reply	other threads:[~2022-01-17 17:13 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-17 17:07 [PATCH AUTOSEL 4.4 01/12] powerpc/6xx: add missing of_node_put Sasha Levin
2022-01-17 17:07 ` Sasha Levin
2022-01-17 17:07 ` [PATCH AUTOSEL 4.4 02/12] powerpc/powernv: " Sasha Levin
2022-01-17 17:07   ` Sasha Levin
2022-01-17 17:07 ` [PATCH AUTOSEL 4.4 03/12] powerpc/cell: " Sasha Levin
2022-01-17 17:07   ` Sasha Levin
2022-01-17 17:07 ` [PATCH AUTOSEL 4.4 04/12] powerpc/btext: " Sasha Levin
2022-01-17 17:07   ` Sasha Levin
2022-01-17 17:07 ` Sasha Levin [this message]
2022-01-17 17:07 ` [PATCH AUTOSEL 4.4 06/12] powerpc/smp: Move setup_profiling_timer() under CONFIG_PROFILING Sasha Levin
2022-01-17 17:07   ` Sasha Levin
2022-01-17 17:07 ` [PATCH AUTOSEL 4.4 07/12] i2c: mpc: Correct I2C reset procedure Sasha Levin
2022-01-17 17:07 ` [PATCH AUTOSEL 4.4 08/12] w1: Misuse of get_user()/put_user() reported by sparse Sasha Levin
2022-01-17 17:07 ` [PATCH AUTOSEL 4.4 09/12] ALSA: seq: Set upper limit of processed events Sasha Levin
2022-01-17 17:07   ` Sasha Levin
2022-01-17 17:07 ` [PATCH AUTOSEL 4.4 10/12] i2c: designware-pci: Fix to change data types of hcnt and lcnt parameters Sasha Levin
2022-01-17 17:07 ` [PATCH AUTOSEL 4.4 11/12] MIPS: Octeon: Fix build errors using clang Sasha Levin
2022-01-17 17:07 ` [PATCH AUTOSEL 4.4 12/12] scsi: sr: Don't use GFP_DMA Sasha Levin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220117170757.1473318-5-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=hkallweit1@gmail.com \
    --cc=jdelvare@suse.com \
    --cc=jdelvare@suse.de \
    --cc=linux-i2c@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=wsa@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.