Skip to content

Commit be2ab5b

Browse files
Florian Westphalummakynes
authored andcommitted
netfilter: nf_tables: take module reference when starting a batch
Signed-off-by: Florian Westphal <[email protected]> Signed-off-by: Pablo Neira Ayuso <[email protected]>
1 parent ca2f18b commit be2ab5b

File tree

3 files changed

+11
-0
lines changed

3 files changed

+11
-0
lines changed

include/linux/netfilter/nfnetlink.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ struct nfnetlink_subsystem {
2929
__u8 subsys_id; /* nfnetlink subsystem ID */
3030
__u8 cb_count; /* number of callbacks */
3131
const struct nfnl_callback *cb; /* callback for individual types */
32+
struct module *owner;
3233
int (*commit)(struct net *net, struct sk_buff *skb);
3334
int (*abort)(struct net *net, struct sk_buff *skb);
3435
void (*cleanup)(struct net *net);

net/netfilter/nf_tables_api.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6603,6 +6603,7 @@ static const struct nfnetlink_subsystem nf_tables_subsys = {
66036603
.abort = nf_tables_abort,
66046604
.cleanup = nf_tables_cleanup,
66056605
.valid_genid = nf_tables_valid_genid,
6606+
.owner = THIS_MODULE,
66066607
};
66076608

66086609
int nft_chain_validate_dependency(const struct nft_chain *chain,

net/netfilter/nfnetlink.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,14 @@ static void nfnetlink_rcv_batch(struct sk_buff *skb, struct nlmsghdr *nlh,
337337
return kfree_skb(skb);
338338
}
339339

340+
if (!try_module_get(ss->owner)) {
341+
nfnl_unlock(subsys_id);
342+
netlink_ack(oskb, nlh, -EOPNOTSUPP, NULL);
343+
return kfree_skb(skb);
344+
}
345+
340346
if (!ss->valid_genid(net, genid)) {
347+
module_put(ss->owner);
341348
nfnl_unlock(subsys_id);
342349
netlink_ack(oskb, nlh, -ERESTART, NULL);
343350
return kfree_skb(skb);
@@ -472,6 +479,7 @@ static void nfnetlink_rcv_batch(struct sk_buff *skb, struct nlmsghdr *nlh,
472479
nfnl_err_reset(&err_list);
473480
nfnl_unlock(subsys_id);
474481
kfree_skb(skb);
482+
module_put(ss->owner);
475483
goto replay;
476484
} else if (status == NFNL_BATCH_DONE) {
477485
err = ss->commit(net, oskb);
@@ -491,6 +499,7 @@ static void nfnetlink_rcv_batch(struct sk_buff *skb, struct nlmsghdr *nlh,
491499
nfnl_err_deliver(&err_list, oskb);
492500
nfnl_unlock(subsys_id);
493501
kfree_skb(skb);
502+
module_put(ss->owner);
494503
}
495504

496505
static const struct nla_policy nfnl_batch_policy[NFNL_BATCH_MAX + 1] = {

0 commit comments

Comments
 (0)