* [PATCH] firmware: Google VPD: fix error handling on allocation failures
@ 2017-05-03 15:49 Colin King
2017-05-03 15:58 ` walter harms
0 siblings, 1 reply; 2+ messages in thread
From: Colin King @ 2017-05-03 15:49 UTC (permalink / raw)
To: Greg Kroah-Hartman, Wei-Ning Huang, Thierry Escande, Wei Yongjun
Cc: kernel-janitors, linux-kernel
From: Colin Ian King <colin.king@canonical.com>
Fix two allocation failure checks. Firstly, ensure info is checked
for a failed allocation; this fixes a potential null pointer
dereference issue on info->key. Secondly, free info is info->key
fails to allocate to fix a memory leak.
Detected by CoverityScan, CID#1430064 ("Resource Leak")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
drivers/firmware/google/vpd.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/drivers/firmware/google/vpd.c b/drivers/firmware/google/vpd.c
index 3ce813110d5e..2eb15b1dabcc 100644
--- a/drivers/firmware/google/vpd.c
+++ b/drivers/firmware/google/vpd.c
@@ -116,9 +116,13 @@ static int vpd_section_attrib_add(const u8 *key, s32 key_len,
return VPD_OK;
info = kzalloc(sizeof(*info), GFP_KERNEL);
+ if (!info)
+ return -ENOMEM;
info->key = kzalloc(key_len + 1, GFP_KERNEL);
- if (!info->key)
+ if (!info->key) {
+ kfree(info);
return -ENOMEM;
+ }
memcpy(info->key, key, key_len);
--
2.11.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] firmware: Google VPD: fix error handling on allocation failures
2017-05-03 15:49 [PATCH] firmware: Google VPD: fix error handling on allocation failures Colin King
@ 2017-05-03 15:58 ` walter harms
0 siblings, 0 replies; 2+ messages in thread
From: walter harms @ 2017-05-03 15:58 UTC (permalink / raw)
To: Colin King
Cc: Greg Kroah-Hartman, Wei-Ning Huang, Thierry Escande, Wei Yongjun,
kernel-janitors, linux-kernel
Am 03.05.2017 17:49, schrieb Colin King:
> From: Colin Ian King <colin.king@canonical.com>
>
> Fix two allocation failure checks. Firstly, ensure info is checked
> for a failed allocation; this fixes a potential null pointer
> dereference issue on info->key. Secondly, free info is info->key
> fails to allocate to fix a memory leak.
>
> Detected by CoverityScan, CID#1430064 ("Resource Leak")
>
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
> drivers/firmware/google/vpd.c | 6 +++++-
> 1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/firmware/google/vpd.c b/drivers/firmware/google/vpd.c
> index 3ce813110d5e..2eb15b1dabcc 100644
> --- a/drivers/firmware/google/vpd.c
> +++ b/drivers/firmware/google/vpd.c
> @@ -116,9 +116,13 @@ static int vpd_section_attrib_add(const u8 *key, s32 key_len,
> return VPD_OK;
>
> info = kzalloc(sizeof(*info), GFP_KERNEL);
> + if (!info)
> + return -ENOMEM;
> info->key = kzalloc(key_len + 1, GFP_KERNEL);
> - if (!info->key)
> + if (!info->key) {
> + kfree(info);
> return -ENOMEM;
> + }
>
> memcpy(info->key, key, key_len);
>
the use of key_len+1 looks like preparing space for a string.
so kstrdup() seems more fitting. If this is not a string
there is also a kmemdup().
re,
wh
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2017-05-03 15:58 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-05-03 15:49 [PATCH] firmware: Google VPD: fix error handling on allocation failures Colin King
2017-05-03 15:58 ` walter harms
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).