kernel-janitors.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mtd: core: Potential NULL dereference in mtd_otp_size()
@ 2021-05-14 14:27 Dan Carpenter
  2021-05-14 18:35 ` Michael Walle
  2021-05-26  9:02 ` Miquel Raynal
  0 siblings, 2 replies; 3+ messages in thread
From: Dan Carpenter @ 2021-05-14 14:27 UTC (permalink / raw)
  To: Miquel Raynal, Michael Walle
  Cc: Richard Weinberger, Vignesh Raghavendra, linux-mtd, kernel-janitors

If kmalloc() fails then it could lead to a NULL dereference.  Check and
return -ENOMEM on error.

Fixes: 4b361cfa8624 ("mtd: core: add OTP nvmem provider support")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
 drivers/mtd/mtdcore.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c
index 3ae261661eea..9624ad1b999c 100644
--- a/drivers/mtd/mtdcore.c
+++ b/drivers/mtd/mtdcore.c
@@ -779,12 +779,16 @@ static void mtd_set_dev_defaults(struct mtd_info *mtd)
 
 static ssize_t mtd_otp_size(struct mtd_info *mtd, bool is_user)
 {
-	struct otp_info *info = kmalloc(PAGE_SIZE, GFP_KERNEL);
+	struct otp_info *info;
 	ssize_t size = 0;
 	unsigned int i;
 	size_t retlen;
 	int ret;
 
+	info = kmalloc(PAGE_SIZE, GFP_KERNEL);
+	if (!info)
+		return -ENOMEM;
+
 	if (is_user)
 		ret = mtd_get_user_prot_info(mtd, PAGE_SIZE, &retlen, info);
 	else
-- 
2.30.2


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

* Re: [PATCH] mtd: core: Potential NULL dereference in mtd_otp_size()
  2021-05-14 14:27 [PATCH] mtd: core: Potential NULL dereference in mtd_otp_size() Dan Carpenter
@ 2021-05-14 18:35 ` Michael Walle
  2021-05-26  9:02 ` Miquel Raynal
  1 sibling, 0 replies; 3+ messages in thread
From: Michael Walle @ 2021-05-14 18:35 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Miquel Raynal, Richard Weinberger, Vignesh Raghavendra,
	linux-mtd, kernel-janitors

Am 2021-05-14 16:27, schrieb Dan Carpenter:
> If kmalloc() fails then it could lead to a NULL dereference.  Check and
> return -ENOMEM on error.
> 
> Fixes: 4b361cfa8624 ("mtd: core: add OTP nvmem provider support")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

Thanks, were was my head..

Reviewed-by: Michael Walle <michael@walle.cc>

-michael

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

* Re: [PATCH] mtd: core: Potential NULL dereference in mtd_otp_size()
  2021-05-14 14:27 [PATCH] mtd: core: Potential NULL dereference in mtd_otp_size() Dan Carpenter
  2021-05-14 18:35 ` Michael Walle
@ 2021-05-26  9:02 ` Miquel Raynal
  1 sibling, 0 replies; 3+ messages in thread
From: Miquel Raynal @ 2021-05-26  9:02 UTC (permalink / raw)
  To: Dan Carpenter, Miquel Raynal, Michael Walle
  Cc: Richard Weinberger, Vignesh Raghavendra, linux-mtd, kernel-janitors

On Fri, 2021-05-14 at 14:27:15 UTC, Dan Carpenter wrote:
> If kmalloc() fails then it could lead to a NULL dereference.  Check and
> return -ENOMEM on error.
> 
> Fixes: 4b361cfa8624 ("mtd: core: add OTP nvmem provider support")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> Reviewed-by: Michael Walle <michael@walle.cc>

Applied to https://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git mtd/next, thanks.

Miquel

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

end of thread, other threads:[~2021-05-26  9:03 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-14 14:27 [PATCH] mtd: core: Potential NULL dereference in mtd_otp_size() Dan Carpenter
2021-05-14 18:35 ` Michael Walle
2021-05-26  9:02 ` Miquel Raynal

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).