linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] regmap: Fix reversed bounds check in regmap_raw_write()
@ 2018-02-08  7:23 Dan Carpenter
  2018-02-08  7:25 ` [PATCH 2/2] regmap-i2c: Off by one in regmap_i2c_smbus_i2c_read/write() Dan Carpenter
  2018-02-08 15:41 ` Applied "regmap: Fix reversed bounds check in regmap_raw_write()" " Mark Brown
  0 siblings, 2 replies; 4+ messages in thread
From: Dan Carpenter @ 2018-02-08  7:23 UTC (permalink / raw)
  To: Mark Brown, Markus Pargmann
  Cc: Greg Kroah-Hartman, linux-kernel, kernel-janitors

We're supposed to be checking that "val_len" is not too large but
instead we check if it is smaller than the max.

The only function affected would be regmap_i2c_smbus_i2c_write() in
drivers/base/regmap/regmap-i2c.c.  Strangely that function has its own
limit check which returns an error if (count >= I2C_SMBUS_BLOCK_MAX) so
it doesn't look like it has ever been able to do anything except return
an error.

Fixes: c335931ed9d2 ("regmap: Add raw_write/read checks for max_raw_write/read sizes")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
This is from code review.  I can't test it.

Is it possible that there are other ways to reach
regmap_i2c_smbus_i2c_write() without going through regmap_raw_write()?
In that case, the temptation would be to just remove this check and the
one in regmap_raw_read().

diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c
index ee302ccdfbc8..453116fd4362 100644
--- a/drivers/base/regmap/regmap.c
+++ b/drivers/base/regmap/regmap.c
@@ -1831,7 +1831,7 @@ int regmap_raw_write(struct regmap *map, unsigned int reg,
 		return -EINVAL;
 	if (val_len % map->format.val_bytes)
 		return -EINVAL;
-	if (map->max_raw_write && map->max_raw_write > val_len)
+	if (map->max_raw_write && map->max_raw_write < val_len)
 		return -E2BIG;
 
 	map->lock(map->lock_arg);

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/2] regmap-i2c: Off by one in regmap_i2c_smbus_i2c_read/write()
  2018-02-08  7:23 [PATCH 1/2] regmap: Fix reversed bounds check in regmap_raw_write() Dan Carpenter
@ 2018-02-08  7:25 ` Dan Carpenter
  2018-02-08 15:41   ` Applied "regmap-i2c: Off by one in regmap_i2c_smbus_i2c_read/write()" to the regmap tree Mark Brown
  2018-02-08 15:41 ` Applied "regmap: Fix reversed bounds check in regmap_raw_write()" " Mark Brown
  1 sibling, 1 reply; 4+ messages in thread
From: Dan Carpenter @ 2018-02-08  7:25 UTC (permalink / raw)
  To: Mark Brown, Markus Pargmann
  Cc: Greg Kroah-Hartman, linux-kernel, kernel-janitors

The commit message says that we are allowed to read and write up to 32
bytes but the code only allows us to write 31 bytes.  In other words,
the ">=" should be changed to ">".  But this is already checked in
regmap_raw_read()/write() so we can just remove the if statemetents.

Fixes: 29332534e2b6 ("regmap-i2c: Add smbus i2c block support")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
Not tested.

diff --git a/drivers/base/regmap/regmap-i2c.c b/drivers/base/regmap/regmap-i2c.c
index 4735318f4268..056acde5e7d3 100644
--- a/drivers/base/regmap/regmap-i2c.c
+++ b/drivers/base/regmap/regmap-i2c.c
@@ -217,8 +217,6 @@ static int regmap_i2c_smbus_i2c_write(void *context, const void *data,
 
 	if (count < 1)
 		return -EINVAL;
-	if (count >= I2C_SMBUS_BLOCK_MAX)
-		return -E2BIG;
 
 	--count;
 	return i2c_smbus_write_i2c_block_data(i2c, ((u8 *)data)[0], count,
@@ -235,8 +233,6 @@ static int regmap_i2c_smbus_i2c_read(void *context, const void *reg,
 
 	if (reg_size != 1 || val_size < 1)
 		return -EINVAL;
-	if (val_size >= I2C_SMBUS_BLOCK_MAX)
-		return -E2BIG;
 
 	ret = i2c_smbus_read_i2c_block_data(i2c, ((u8 *)reg)[0], val_size, val);
 	if (ret == val_size)

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Applied "regmap-i2c: Off by one in regmap_i2c_smbus_i2c_read/write()" to the regmap tree
  2018-02-08  7:25 ` [PATCH 2/2] regmap-i2c: Off by one in regmap_i2c_smbus_i2c_read/write() Dan Carpenter
@ 2018-02-08 15:41   ` Mark Brown
  0 siblings, 0 replies; 4+ messages in thread
From: Mark Brown @ 2018-02-08 15:41 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Mark Brown, Mark Brown, Markus Pargmann, Greg Kroah-Hartman,
	linux-kernel, kernel-janitors, linux-kernel

The patch

   regmap-i2c: Off by one in regmap_i2c_smbus_i2c_read/write()

has been applied to the regmap tree at

   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/regmap.git 

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.  

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark

>From 86effbe0d198aaf57459ec9ad3855e88e29ecb1c Mon Sep 17 00:00:00 2001
From: Dan Carpenter <dan.carpenter@oracle.com>
Date: Thu, 8 Feb 2018 10:25:28 +0300
Subject: [PATCH] regmap-i2c: Off by one in regmap_i2c_smbus_i2c_read/write()

The commit message says that we are allowed to read and write up to 32
bytes but the code only allows us to write 31 bytes.  In other words,
the ">=" should be changed to ">".  But this is already checked in
regmap_raw_read()/write() so we can just remove the if statemetents.

Fixes: 29332534e2b6 ("regmap-i2c: Add smbus i2c block support")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
---
 drivers/base/regmap/regmap-i2c.c | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/drivers/base/regmap/regmap-i2c.c b/drivers/base/regmap/regmap-i2c.c
index 4735318f4268..056acde5e7d3 100644
--- a/drivers/base/regmap/regmap-i2c.c
+++ b/drivers/base/regmap/regmap-i2c.c
@@ -217,8 +217,6 @@ static int regmap_i2c_smbus_i2c_write(void *context, const void *data,
 
 	if (count < 1)
 		return -EINVAL;
-	if (count >= I2C_SMBUS_BLOCK_MAX)
-		return -E2BIG;
 
 	--count;
 	return i2c_smbus_write_i2c_block_data(i2c, ((u8 *)data)[0], count,
@@ -235,8 +233,6 @@ static int regmap_i2c_smbus_i2c_read(void *context, const void *reg,
 
 	if (reg_size != 1 || val_size < 1)
 		return -EINVAL;
-	if (val_size >= I2C_SMBUS_BLOCK_MAX)
-		return -E2BIG;
 
 	ret = i2c_smbus_read_i2c_block_data(i2c, ((u8 *)reg)[0], val_size, val);
 	if (ret == val_size)
-- 
2.15.1

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Applied "regmap: Fix reversed bounds check in regmap_raw_write()" to the regmap tree
  2018-02-08  7:23 [PATCH 1/2] regmap: Fix reversed bounds check in regmap_raw_write() Dan Carpenter
  2018-02-08  7:25 ` [PATCH 2/2] regmap-i2c: Off by one in regmap_i2c_smbus_i2c_read/write() Dan Carpenter
@ 2018-02-08 15:41 ` Mark Brown
  1 sibling, 0 replies; 4+ messages in thread
From: Mark Brown @ 2018-02-08 15:41 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Mark Brown, stable, Mark Brown, Markus Pargmann,
	Greg Kroah-Hartman, linux-kernel, kernel-janitors, linux-kernel

The patch

   regmap: Fix reversed bounds check in regmap_raw_write()

has been applied to the regmap tree at

   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/regmap.git 

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.  

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark

>From f00e71091ab92eba52122332586c6ecaa9cd1a56 Mon Sep 17 00:00:00 2001
From: Dan Carpenter <dan.carpenter@oracle.com>
Date: Thu, 8 Feb 2018 10:23:44 +0300
Subject: [PATCH] regmap: Fix reversed bounds check in regmap_raw_write()

We're supposed to be checking that "val_len" is not too large but
instead we check if it is smaller than the max.

The only function affected would be regmap_i2c_smbus_i2c_write() in
drivers/base/regmap/regmap-i2c.c.  Strangely that function has its own
limit check which returns an error if (count >= I2C_SMBUS_BLOCK_MAX) so
it doesn't look like it has ever been able to do anything except return
an error.

Fixes: c335931ed9d2 ("regmap: Add raw_write/read checks for max_raw_write/read sizes")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
Cc: stable@vger.kernel.org
---
 drivers/base/regmap/regmap.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c
index ee302ccdfbc8..453116fd4362 100644
--- a/drivers/base/regmap/regmap.c
+++ b/drivers/base/regmap/regmap.c
@@ -1831,7 +1831,7 @@ int regmap_raw_write(struct regmap *map, unsigned int reg,
 		return -EINVAL;
 	if (val_len % map->format.val_bytes)
 		return -EINVAL;
-	if (map->max_raw_write && map->max_raw_write > val_len)
+	if (map->max_raw_write && map->max_raw_write < val_len)
 		return -E2BIG;
 
 	map->lock(map->lock_arg);
-- 
2.15.1

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2018-02-08 15:41 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-02-08  7:23 [PATCH 1/2] regmap: Fix reversed bounds check in regmap_raw_write() Dan Carpenter
2018-02-08  7:25 ` [PATCH 2/2] regmap-i2c: Off by one in regmap_i2c_smbus_i2c_read/write() Dan Carpenter
2018-02-08 15:41   ` Applied "regmap-i2c: Off by one in regmap_i2c_smbus_i2c_read/write()" to the regmap tree Mark Brown
2018-02-08 15:41 ` Applied "regmap: Fix reversed bounds check in regmap_raw_write()" " Mark Brown

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).