mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] regmap: Fix possible ZERO_SIZE_PTR pointer dereferencing error.
@ 2014-04-30  9:31 Xiubo Li
  2014-05-01  3:34 ` Mark Brown
  0 siblings, 1 reply; 6+ messages in thread
From: Xiubo Li @ 2014-04-30  9:31 UTC (permalink / raw)
  To: broonie; +Cc: linux-kernel, Xiubo Li

Since we cannot make sure the 'len = pair_size * num_regs' will always
be none zero from the users, and then if 'num_regs' equals to zero by
mistake or other reasons, the kzalloc() will return ZERO_SIZE_PTR, which
equals to ((void *)16).

So this patch fix this with just doing the 'len' zero check before calling
kzalloc().

Signed-off-by: Xiubo Li <Li.Xiubo@freescale.com>
---
 drivers/base/regmap/regmap.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c
index 18d193f..4ef7a24 100644
--- a/drivers/base/regmap/regmap.c
+++ b/drivers/base/regmap/regmap.c
@@ -1685,6 +1685,9 @@ static int _regmap_raw_multi_reg_write(struct regmap *map,
 	size_t pair_size = reg_bytes + pad_bytes + val_bytes;
 	size_t len = pair_size * num_regs;
 
+	if (!len)
+		return -EINVAL;
+
 	buf = kzalloc(len, GFP_KERNEL);
 	if (!buf)
 		return -ENOMEM;
-- 
1.8.4


^ permalink raw reply	[flat|nested] 6+ messages in thread
* [PATCH] regmap: fix possible ZERO_SIZE_PTR pointer dereferencing error.
@ 2014-09-28  9:09 Xiubo Li
  2014-09-28  9:25 ` Li.Xiubo
  2014-09-28 10:56 ` Mark Brown
  0 siblings, 2 replies; 6+ messages in thread
From: Xiubo Li @ 2014-09-28  9:09 UTC (permalink / raw)
  To: broonie; +Cc: gregkh, linux-kernel, Xiubo Li

Since we cannot make sure the 'val_count' will always be none zero
here, and then if it equals to zero, the kmemdup() will return
ZERO_SIZE_PTR, which equals to ((void *)16).

So this patch fix this with just doing the zero check before calling
kmemdup().

Signed-off-by: Xiubo Li <Li.Xiubo@freescale.com>
---
 drivers/base/regmap/regmap.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c
index 455a877..3d93e38 100644
--- a/drivers/base/regmap/regmap.c
+++ b/drivers/base/regmap/regmap.c
@@ -1716,6 +1716,9 @@ out:
 	} else {
 		void *wval;
 
+		if (!val_count)
+			return -EINVAL;
+
 		wval = kmemdup(val, val_count * val_bytes, GFP_KERNEL);
 		if (!wval) {
 			dev_err(map->dev, "Error in memory allocation\n");
-- 
2.1.0.27.g96db324


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

end of thread, other threads:[~2014-09-30  5:06 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-04-30  9:31 [PATCH] regmap: Fix possible ZERO_SIZE_PTR pointer dereferencing error Xiubo Li
2014-05-01  3:34 ` Mark Brown
2014-09-28  9:09 [PATCH] regmap: fix " Xiubo Li
2014-09-28  9:25 ` Li.Xiubo
2014-09-28 10:56 ` Mark Brown
2014-09-30  5:05   ` Li.Xiubo

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®