Skip to content

Commit

Permalink
mac80211_hwsim: Fix possible null-pointer dereferences in hwsim_dump_…
Browse files Browse the repository at this point in the history
…radio_nl()

In hwsim_dump_radio_nl(), when genlmsg_put() on line 3617 fails, hdr is
assigned to NULL. Then hdr is used on lines 3622 and 3623:
    genl_dump_check_consistent(cb, hdr);
    genlmsg_end(skb, hdr);

Thus, possible null-pointer dereferences may occur.

To fix these bugs, hdr is used here when it is not NULL.

This bug is found by a static analysis tool STCheck written by us.

Signed-off-by: Jia-Ju Bai <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
[put braces on all branches]
Signed-off-by: Johannes Berg <[email protected]>
  • Loading branch information
XidianGeneral authored and jmberg-intel committed Jul 29, 2019
1 parent 05aaa5c commit b55f3b8
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions drivers/net/wireless/mac80211_hwsim.c
Original file line number Diff line number Diff line change
Expand Up @@ -3617,10 +3617,12 @@ static int hwsim_dump_radio_nl(struct sk_buff *skb,
hdr = genlmsg_put(skb, NETLINK_CB(cb->skb).portid,
cb->nlh->nlmsg_seq, &hwsim_genl_family,
NLM_F_MULTI, HWSIM_CMD_GET_RADIO);
if (!hdr)
if (hdr) {
genl_dump_check_consistent(cb, hdr);
genlmsg_end(skb, hdr);
} else {
res = -EMSGSIZE;
genl_dump_check_consistent(cb, hdr);
genlmsg_end(skb, hdr);
}
}

done:
Expand Down

0 comments on commit b55f3b8

Please sign in to comment.