mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Heiner Kallweit <hkallweit1@gmail.com>
To: Jonas Malaco <jonas@protocubo.io>, Arnd Bergmann <arnd@arndb.de>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: stable@vger.kernel.org, Wolfram Sang <wsa@kernel.org>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] eeprom: ee1004: limit i2c reads to I2C_SMBUS_BLOCK_MAX
Date: Thu, 3 Feb 2022 18:10:57 +0100	[thread overview]
Message-ID: <84f17973-96c3-6513-ca4f-20750c896e6b@gmail.com> (raw)
In-Reply-To: <20220203165024.47767-1-jonas@protocubo.io>

On 03.02.2022 17:49, Jonas Malaco wrote:
> Commit effa453168a7 ("i2c: i801: Don't silently correct invalid transfer
> size") revealed that ee1004_eeprom_read() did not properly limit how
> many bytes to read at once.
> 
> In particular, i2c_smbus_read_i2c_block_data_or_emulated() takes the
> length to read as an u8.  If count == 256 after taking into account the
> offset and page boundary, the cast to u8 overflows.  And this is common
> when user space tries to read the entire EEPROM at once.
> 
> To fix it, limit each read to I2C_SMBUS_BLOCK_MAX (32) bytes, already
> the maximum length i2c_smbus_read_i2c_block_data_or_emulated() allows.
> 
> Fixes: effa453168a7 ("i2c: i801: Don't silently correct invalid transfer size")
> Cc: stable@vger.kernel.org
> Signed-off-by: Jonas Malaco <jonas@protocubo.io>
> ---
>  drivers/misc/eeprom/ee1004.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/drivers/misc/eeprom/ee1004.c b/drivers/misc/eeprom/ee1004.c
> index bb9c4512c968..9fbfe784d710 100644
> --- a/drivers/misc/eeprom/ee1004.c
> +++ b/drivers/misc/eeprom/ee1004.c
> @@ -114,6 +114,9 @@ static ssize_t ee1004_eeprom_read(struct i2c_client *client, char *buf,
>  	if (offset + count > EE1004_PAGE_SIZE)
>  		count = EE1004_PAGE_SIZE - offset;
>  
> +	if (count > I2C_SMBUS_BLOCK_MAX)
> +		count = I2C_SMBUS_BLOCK_MAX;
> +
>  	return i2c_smbus_read_i2c_block_data_or_emulated(client, offset, count, buf);
>  }
>  
> 
> base-commit: 88808fbbead481aedb46640a5ace69c58287f56a

Reviewed-by: Heiner Kallweit <hkallweit1@gmail.com>

      reply	other threads:[~2022-02-03 17:11 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-03 16:49 Jonas Malaco
2022-02-03 17:10 ` Heiner Kallweit [this message]

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=84f17973-96c3-6513-ca4f-20750c896e6b@gmail.com \
    --to=hkallweit1@gmail.com \
    --cc=arnd@arndb.de \
    --cc=gregkh@linuxfoundation.org \
    --cc=jonas@protocubo.io \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®