Skip to content

Commit

Permalink
of: overlay: fix null pointer dereferencing in find_dup_cset_node_ent…
Browse files Browse the repository at this point in the history
…ry() and find_dup_cset_prop()

[ Upstream commit ee9d7a0 ]

When kmalloc() fail to allocate memory in kasprintf(), fn_1 or fn_2 will
be NULL, and strcmp() will cause null pointer dereference.

Fixes: 2fe0e87 ("of: overlay: check prevents multiple fragments touching same property")
Signed-off-by: ruanjinjie <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Rob Herring <[email protected]>
Signed-off-by: Sasha Levin <[email protected]>
  • Loading branch information
ruanjinjie authored and gregkh committed Dec 31, 2022
1 parent 8399b98 commit ce1b3a4
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions drivers/of/overlay.c
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ 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);
node_path_match = !strcmp(fn_1, fn_2);
node_path_match = !fn_1 || !fn_2 || !strcmp(fn_1, fn_2);
kfree(fn_1);
kfree(fn_2);
if (node_path_match) {
Expand Down Expand Up @@ -582,7 +582,7 @@ 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);
node_path_match = !strcmp(fn_1, fn_2);
node_path_match = !fn_1 || !fn_2 || !strcmp(fn_1, fn_2);
kfree(fn_1);
kfree(fn_2);
if (node_path_match &&
Expand Down

0 comments on commit ce1b3a4

Please sign in to comment.