* [PATCH] of: overlay: fix null pointer dereferencing in find_dup_cset_node_entry() and find_dup_cset_prop()
@ 2022-12-06 8:36 ruanjinjie
2022-12-09 20:59 ` Rob Herring
0 siblings, 1 reply; 3+ messages in thread
From: ruanjinjie @ 2022-12-06 8:36 UTC (permalink / raw)
To: robh+dt, frowand.list, devicetree, linux-kernel; +Cc: ruanjinjie
when kmalloc() fail to allocate memory in kasprintf(), fn_1 or fn_2 will
be NULL, strcmp() will cause null pointer dereference.
Fixes: 2fe0e8769df9 ("of: overlay: check prevents multiple fragments touching same property")
Signed-off-by: ruanjinjie <ruanjinjie@huawei.com>
---
drivers/of/overlay.c | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/drivers/of/overlay.c b/drivers/of/overlay.c
index bd8ff4df723d..49c066b51148 100644
--- a/drivers/of/overlay.c
+++ b/drivers/of/overlay.c
@@ -545,6 +545,11 @@ static int find_dup_cset_node_entry(struct overlay_changeset *ovcs,
fn_1 = kasprintf(GFP_KERNEL, "%pOF", ce_1->np);
fn_2 = kasprintf(GFP_KERNEL, "%pOF", ce_2->np);
+ if (!fn_1 || !fn_2) {
+ kfree(fn_1);
+ kfree(fn_2);
+ return -ENOMEM;
+ }
node_path_match = !strcmp(fn_1, fn_2);
kfree(fn_1);
kfree(fn_2);
@@ -580,6 +585,11 @@ static int find_dup_cset_prop(struct overlay_changeset *ovcs,
fn_1 = kasprintf(GFP_KERNEL, "%pOF", ce_1->np);
fn_2 = kasprintf(GFP_KERNEL, "%pOF", ce_2->np);
+ if (!fn_1 || !fn_2) {
+ kfree(fn_1);
+ kfree(fn_2);
+ return -ENOMEM;
+ }
node_path_match = !strcmp(fn_1, fn_2);
kfree(fn_1);
kfree(fn_2);
--
2.25.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] of: overlay: fix null pointer dereferencing in find_dup_cset_node_entry() and find_dup_cset_prop()
2022-12-06 8:36 [PATCH] of: overlay: fix null pointer dereferencing in find_dup_cset_node_entry() and find_dup_cset_prop() ruanjinjie
@ 2022-12-09 20:59 ` Rob Herring
2022-12-11 2:14 ` Ruan Jinjie
0 siblings, 1 reply; 3+ messages in thread
From: Rob Herring @ 2022-12-09 20:59 UTC (permalink / raw)
To: ruanjinjie; +Cc: frowand.list, devicetree, linux-kernel
On Tue, Dec 06, 2022 at 04:36:57PM +0800, ruanjinjie wrote:
> when kmalloc() fail to allocate memory in kasprintf(), fn_1 or fn_2 will
> be NULL, strcmp() will cause null pointer dereference.
>
> Fixes: 2fe0e8769df9 ("of: overlay: check prevents multiple fragments touching same property")
> Signed-off-by: ruanjinjie <ruanjinjie@huawei.com>
> ---
> drivers/of/overlay.c | 10 ++++++++++
> 1 file changed, 10 insertions(+)
>
> diff --git a/drivers/of/overlay.c b/drivers/of/overlay.c
> index bd8ff4df723d..49c066b51148 100644
> --- a/drivers/of/overlay.c
> +++ b/drivers/of/overlay.c
> @@ -545,6 +545,11 @@ static int find_dup_cset_node_entry(struct overlay_changeset *ovcs,
>
> fn_1 = kasprintf(GFP_KERNEL, "%pOF", ce_1->np);
> fn_2 = kasprintf(GFP_KERNEL, "%pOF", ce_2->np);
> + if (!fn_1 || !fn_2) {
> + kfree(fn_1);
> + kfree(fn_2);
> + return -ENOMEM;
> + }
> node_path_match = !strcmp(fn_1, fn_2);
We don't actually care what the return code is, so just change this to:
node_path_match = !fn_1 || !fn_2 || !strcmp(fn_1, fn_2);
> kfree(fn_1);
> kfree(fn_2);
> @@ -580,6 +585,11 @@ static int find_dup_cset_prop(struct overlay_changeset *ovcs,
>
> fn_1 = kasprintf(GFP_KERNEL, "%pOF", ce_1->np);
> fn_2 = kasprintf(GFP_KERNEL, "%pOF", ce_2->np);
> + if (!fn_1 || !fn_2) {
> + kfree(fn_1);
> + kfree(fn_2);
> + return -ENOMEM;
> + }
> node_path_match = !strcmp(fn_1, fn_2);
> kfree(fn_1);
> kfree(fn_2);
> --
> 2.25.1
>
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] of: overlay: fix null pointer dereferencing in find_dup_cset_node_entry() and find_dup_cset_prop()
2022-12-09 20:59 ` Rob Herring
@ 2022-12-11 2:14 ` Ruan Jinjie
0 siblings, 0 replies; 3+ messages in thread
From: Ruan Jinjie @ 2022-12-11 2:14 UTC (permalink / raw)
To: Rob Herring; +Cc: frowand.list, devicetree, linux-kernel
On 2022/12/10 4:59, Rob Herring wrote:
> On Tue, Dec 06, 2022 at 04:36:57PM +0800, ruanjinjie wrote:
>> when kmalloc() fail to allocate memory in kasprintf(), fn_1 or fn_2 will
>> be NULL, strcmp() will cause null pointer dereference.
>>
>> Fixes: 2fe0e8769df9 ("of: overlay: check prevents multiple fragments touching same property")
>> Signed-off-by: ruanjinjie <ruanjinjie@huawei.com>
>> ---
>> drivers/of/overlay.c | 10 ++++++++++
>> 1 file changed, 10 insertions(+)
>>
>> diff --git a/drivers/of/overlay.c b/drivers/of/overlay.c
>> index bd8ff4df723d..49c066b51148 100644
>> --- a/drivers/of/overlay.c
>> +++ b/drivers/of/overlay.c
>> @@ -545,6 +545,11 @@ static int find_dup_cset_node_entry(struct overlay_changeset *ovcs,
>>
>> fn_1 = kasprintf(GFP_KERNEL, "%pOF", ce_1->np);
>> fn_2 = kasprintf(GFP_KERNEL, "%pOF", ce_2->np);
>> + if (!fn_1 || !fn_2) {
>> + kfree(fn_1);
>> + kfree(fn_2);
>> + return -ENOMEM;
>> + }
>> node_path_match = !strcmp(fn_1, fn_2);
>
> We don't actually care what the return code is, so just change this to:
>
> node_path_match = !fn_1 || !fn_2 || !strcmp(fn_1, fn_2);
Thank you very much!I'll give the v2 patch soon.
>
>> kfree(fn_1);
>> kfree(fn_2);
>> @@ -580,6 +585,11 @@ static int find_dup_cset_prop(struct overlay_changeset *ovcs,
>>
>> fn_1 = kasprintf(GFP_KERNEL, "%pOF", ce_1->np);
>> fn_2 = kasprintf(GFP_KERNEL, "%pOF", ce_2->np);
>> + if (!fn_1 || !fn_2) {
>> + kfree(fn_1);
>> + kfree(fn_2);
>> + return -ENOMEM;
>> + }
>> node_path_match = !strcmp(fn_1, fn_2);
>> kfree(fn_1);
>> kfree(fn_2);
>> --
>> 2.25.1
>>
>>
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-12-11 2:14 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-12-06 8:36 [PATCH] of: overlay: fix null pointer dereferencing in find_dup_cset_node_entry() and find_dup_cset_prop() ruanjinjie
2022-12-09 20:59 ` Rob Herring
2022-12-11 2:14 ` Ruan Jinjie
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).