mtd: core: Potential NULL dereference in mtd_otp_size()
Subsystems (2)
PATCH 1/1 mtd: core: Potential NULL dereference in mtd_otp_size()
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 <[email protected]>
--- drivers/mtd/mtdcore.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/mtd/mtdcore.c +5 -1
@@ -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
Signature · 1 line
2.30.2
Am 2021-05-14 16:27, schrieb Dan Carpenter:
Quoted 5 lines
If
kmalloc()fails then it could lead to a NULL dereference. Check and return-ENOMEMon error.Fixes 4b361cfa8624 ("mtd: core: add OTP nvmem provider support")Signed-off-by Dan Carpenter <[email protected]>
Thanks, were was my head..
Reviewed-by Michael Walle <[email protected]>
-michael
Quoted 6 lines · Dan Carpenter
If
kmalloc()fails then it could lead to a NULL dereference. Check and return-ENOMEMon error.Fixes 4b361cfa8624 ("mtd: core: add OTP nvmem provider support")Signed-off-by Dan Carpenter <[email protected]>Reviewed-by Michael Walle <[email protected]>
Applied to https://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git mtd/next, thanks.
Miquel