Skip to content

Commit 90d2723

Browse files
committed
netfilter: nf_tables: do not hold reference on netdevice from preparation phase
The netfilter netdevice event handler hold the nfnl_lock mutex, this avoids races with a device going away while such device is being attached to hooks from the netlink control plane. Therefore, either control plane bails out with ENOENT or netdevice event path waits until the hook that is attached to net_device is registered. Signed-off-by: Pablo Neira Ayuso <[email protected]>
1 parent d92191a commit 90d2723

File tree

1 file changed

+4
-15
lines changed

1 file changed

+4
-15
lines changed

net/netfilter/nf_tables_api.c

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1288,8 +1288,6 @@ static void nf_tables_chain_destroy(struct nft_chain *chain)
12881288
free_percpu(basechain->stats);
12891289
if (basechain->stats)
12901290
static_branch_dec(&nft_counters_enabled);
1291-
if (basechain->ops.dev != NULL)
1292-
dev_put(basechain->ops.dev);
12931291
kfree(chain->name);
12941292
kfree(basechain);
12951293
} else {
@@ -1356,7 +1354,7 @@ static int nft_chain_parse_hook(struct net *net,
13561354
}
13571355

13581356
nla_strlcpy(ifname, ha[NFTA_HOOK_DEV], IFNAMSIZ);
1359-
dev = dev_get_by_name(net, ifname);
1357+
dev = __dev_get_by_name(net, ifname);
13601358
if (!dev) {
13611359
module_put(type->owner);
13621360
return -ENOENT;
@@ -1373,8 +1371,6 @@ static int nft_chain_parse_hook(struct net *net,
13731371
static void nft_chain_release_hook(struct nft_chain_hook *hook)
13741372
{
13751373
module_put(hook->type->owner);
1376-
if (hook->dev != NULL)
1377-
dev_put(hook->dev);
13781374
}
13791375

13801376
static int nf_tables_addchain(struct nft_ctx *ctx, u8 family, u8 genmask,
@@ -4948,7 +4944,7 @@ static int nf_tables_parse_devices(const struct nft_ctx *ctx,
49484944
}
49494945

49504946
nla_strlcpy(ifname, tmp, IFNAMSIZ);
4951-
dev = dev_get_by_name(ctx->net, ifname);
4947+
dev = __dev_get_by_name(ctx->net, ifname);
49524948
if (!dev) {
49534949
err = -ENOENT;
49544950
goto err1;
@@ -5007,10 +5003,8 @@ static int nf_tables_flowtable_parse_hook(const struct nft_ctx *ctx,
50075003
return err;
50085004

50095005
ops = kzalloc(sizeof(struct nf_hook_ops) * n, GFP_KERNEL);
5010-
if (!ops) {
5011-
err = -ENOMEM;
5012-
goto err1;
5013-
}
5006+
if (!ops)
5007+
return -ENOMEM;
50145008

50155009
flowtable->hooknum = hooknum;
50165010
flowtable->priority = priority;
@@ -5028,11 +5022,6 @@ static int nf_tables_flowtable_parse_hook(const struct nft_ctx *ctx,
50285022
GFP_KERNEL);
50295023
}
50305024

5031-
err = 0;
5032-
err1:
5033-
for (i = 0; i < n; i++)
5034-
dev_put(dev_array[i]);
5035-
50365025
return err;
50375026
}
50385027

0 commit comments

Comments
 (0)