Skip to content

Commit b15ca18

Browse files
tgrafdavem330
authored andcommitted
netlink: Add nla_memdup() to wrap kmemdup() use on nlattr
Wrap several common instances of: kmemdup(nla_data(attr), nla_len(attr), GFP_KERNEL); Signed-off-by: Thomas Graf <tgraf@suug.ch> Acked-by: Johannes Berg <johannes@sipsolutions.net> Acked-by: Daniel Borkmann <daniel@iogearbox.net> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent f8da977 commit b15ca18

4 files changed

Lines changed: 13 additions & 8 deletions

File tree

‎include/net/netlink.h‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1190,6 +1190,16 @@ static inline struct in6_addr nla_get_in6_addr(const struct nlattr *nla)
11901190
return tmp;
11911191
}
11921192

1193+
/**
1194+
* nla_memdup - duplicate attribute memory (kmemdup)
1195+
* @src: netlink attribute to duplicate from
1196+
* @gfp: GFP mask
1197+
*/
1198+
static inline void *nla_memdup(const struct nlattr *src, gfp_t gfp)
1199+
{
1200+
return kmemdup(nla_data(src), nla_len(src), gfp);
1201+
}
1202+
11931203
/**
11941204
* nla_nest_start - Start a new level of nested attributes
11951205
* @skb: socket buffer to add attributes to

‎net/sched/act_bpf.c‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,9 +226,7 @@ static int tcf_bpf_init_from_efd(struct nlattr **tb, struct tcf_bpf_cfg *cfg)
226226
return PTR_ERR(fp);
227227

228228
if (tb[TCA_ACT_BPF_NAME]) {
229-
name = kmemdup(nla_data(tb[TCA_ACT_BPF_NAME]),
230-
nla_len(tb[TCA_ACT_BPF_NAME]),
231-
GFP_KERNEL);
229+
name = nla_memdup(tb[TCA_ACT_BPF_NAME], GFP_KERNEL);
232230
if (!name) {
233231
bpf_prog_put(fp);
234232
return -ENOMEM;

‎net/sched/cls_bpf.c‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -369,9 +369,7 @@ static int cls_bpf_prog_from_efd(struct nlattr **tb, struct cls_bpf_prog *prog,
369369
return PTR_ERR(fp);
370370

371371
if (tb[TCA_BPF_NAME]) {
372-
name = kmemdup(nla_data(tb[TCA_BPF_NAME]),
373-
nla_len(tb[TCA_BPF_NAME]),
374-
GFP_KERNEL);
372+
name = nla_memdup(tb[TCA_BPF_NAME], GFP_KERNEL);
375373
if (!name) {
376374
bpf_prog_put(fp);
377375
return -ENOMEM;

‎net/wireless/nl80211.c‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10625,8 +10625,7 @@ static int handle_nan_filter(struct nlattr *attr_filter,
1062510625

1062610626
i = 0;
1062710627
nla_for_each_nested(attr, attr_filter, rem) {
10628-
filter[i].filter = kmemdup(nla_data(attr), nla_len(attr),
10629-
GFP_KERNEL);
10628+
filter[i].filter = nla_memdup(attr, GFP_KERNEL);
1063010629
filter[i].len = nla_len(attr);
1063110630
i++;
1063210631
}

0 commit comments

Comments
 (0)