Skip to content

Commit 53664d5

Browse files
committed
Merge git://git.kernel.org/pub/scm/linux/kernel/git/netfilter/nf
Pablo Neira Ayuso says: ==================== Netfilter fixes for net 1) Use get_random_u32() instead of prandom_u32_state() in nft_meta and nft_numgen, from Florian Westphal. 2) Incorrect list head in nfnetlink_cttimeout in recent update coming from previous development cycle. Also from Florian. 3) Incorrect path to pktgen scripts for nft_concat_range.sh selftest. From Jie2x Zhou. 4) Two fixes for the for nft_fwd and nft_dup egress support, from Florian. * git://git.kernel.org/pub/scm/linux/kernel/git/netfilter/nf: netfilter: nf_dup_netdev: add and use recursion counter netfilter: nf_dup_netdev: do not push mac header a second time selftests: netfilter: correct PKTGEN_SCRIPT_PATHS in nft_concat_range.sh netfilter: cttimeout: fix slab-out-of-bounds read typo in cttimeout_net_exit netfilter: use get_random_u32 instead of prandom ==================== Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
2 parents 2642cc6 + fcd53c5 commit 53664d5

File tree

5 files changed

+28
-26
lines changed

5 files changed

+28
-26
lines changed

net/netfilter/nf_dup_netdev.c

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,31 @@
1313
#include <net/netfilter/nf_tables_offload.h>
1414
#include <net/netfilter/nf_dup_netdev.h>
1515

16-
static void nf_do_netdev_egress(struct sk_buff *skb, struct net_device *dev)
16+
#define NF_RECURSION_LIMIT 2
17+
18+
static DEFINE_PER_CPU(u8, nf_dup_skb_recursion);
19+
20+
static void nf_do_netdev_egress(struct sk_buff *skb, struct net_device *dev,
21+
enum nf_dev_hooks hook)
1722
{
18-
if (skb_mac_header_was_set(skb))
23+
if (__this_cpu_read(nf_dup_skb_recursion) > NF_RECURSION_LIMIT)
24+
goto err;
25+
26+
if (hook == NF_NETDEV_INGRESS && skb_mac_header_was_set(skb)) {
27+
if (skb_cow_head(skb, skb->mac_len))
28+
goto err;
29+
1930
skb_push(skb, skb->mac_len);
31+
}
2032

2133
skb->dev = dev;
2234
skb_clear_tstamp(skb);
35+
__this_cpu_inc(nf_dup_skb_recursion);
2336
dev_queue_xmit(skb);
37+
__this_cpu_dec(nf_dup_skb_recursion);
38+
return;
39+
err:
40+
kfree_skb(skb);
2441
}
2542

2643
void nf_fwd_netdev_egress(const struct nft_pktinfo *pkt, int oif)
@@ -33,7 +50,7 @@ void nf_fwd_netdev_egress(const struct nft_pktinfo *pkt, int oif)
3350
return;
3451
}
3552

36-
nf_do_netdev_egress(pkt->skb, dev);
53+
nf_do_netdev_egress(pkt->skb, dev, nft_hook(pkt));
3754
}
3855
EXPORT_SYMBOL_GPL(nf_fwd_netdev_egress);
3956

@@ -48,7 +65,7 @@ void nf_dup_netdev_egress(const struct nft_pktinfo *pkt, int oif)
4865

4966
skb = skb_clone(pkt->skb, GFP_ATOMIC);
5067
if (skb)
51-
nf_do_netdev_egress(skb, dev);
68+
nf_do_netdev_egress(skb, dev, nft_hook(pkt));
5269
}
5370
EXPORT_SYMBOL_GPL(nf_dup_netdev_egress);
5471

net/netfilter/nfnetlink_cttimeout.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,7 @@ static void __net_exit cttimeout_net_exit(struct net *net)
614614

615615
nf_ct_untimeout(net, NULL);
616616

617-
list_for_each_entry_safe(cur, tmp, &pernet->nfct_timeout_freelist, head) {
617+
list_for_each_entry_safe(cur, tmp, &pernet->nfct_timeout_freelist, free_head) {
618618
list_del(&cur->free_head);
619619

620620
if (refcount_dec_and_test(&cur->refcnt))

net/netfilter/nft_meta.c

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <linux/in.h>
1515
#include <linux/ip.h>
1616
#include <linux/ipv6.h>
17+
#include <linux/random.h>
1718
#include <linux/smp.h>
1819
#include <linux/static_key.h>
1920
#include <net/dst.h>
@@ -32,8 +33,6 @@
3233
#define NFT_META_SECS_PER_DAY 86400
3334
#define NFT_META_DAYS_PER_WEEK 7
3435

35-
static DEFINE_PER_CPU(struct rnd_state, nft_prandom_state);
36-
3736
static u8 nft_meta_weekday(void)
3837
{
3938
time64_t secs = ktime_get_real_seconds();
@@ -271,13 +270,6 @@ static bool nft_meta_get_eval_ifname(enum nft_meta_keys key, u32 *dest,
271270
return true;
272271
}
273272

274-
static noinline u32 nft_prandom_u32(void)
275-
{
276-
struct rnd_state *state = this_cpu_ptr(&nft_prandom_state);
277-
278-
return prandom_u32_state(state);
279-
}
280-
281273
#ifdef CONFIG_IP_ROUTE_CLASSID
282274
static noinline bool
283275
nft_meta_get_eval_rtclassid(const struct sk_buff *skb, u32 *dest)
@@ -389,7 +381,7 @@ void nft_meta_get_eval(const struct nft_expr *expr,
389381
break;
390382
#endif
391383
case NFT_META_PRANDOM:
392-
*dest = nft_prandom_u32();
384+
*dest = get_random_u32();
393385
break;
394386
#ifdef CONFIG_XFRM
395387
case NFT_META_SECPATH:
@@ -518,7 +510,6 @@ int nft_meta_get_init(const struct nft_ctx *ctx,
518510
len = IFNAMSIZ;
519511
break;
520512
case NFT_META_PRANDOM:
521-
prandom_init_once(&nft_prandom_state);
522513
len = sizeof(u32);
523514
break;
524515
#ifdef CONFIG_XFRM

net/netfilter/nft_numgen.c

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,11 @@
99
#include <linux/netlink.h>
1010
#include <linux/netfilter.h>
1111
#include <linux/netfilter/nf_tables.h>
12+
#include <linux/random.h>
1213
#include <linux/static_key.h>
1314
#include <net/netfilter/nf_tables.h>
1415
#include <net/netfilter/nf_tables_core.h>
1516

16-
static DEFINE_PER_CPU(struct rnd_state, nft_numgen_prandom_state);
17-
1817
struct nft_ng_inc {
1918
u8 dreg;
2019
u32 modulus;
@@ -135,12 +134,9 @@ struct nft_ng_random {
135134
u32 offset;
136135
};
137136

138-
static u32 nft_ng_random_gen(struct nft_ng_random *priv)
137+
static u32 nft_ng_random_gen(const struct nft_ng_random *priv)
139138
{
140-
struct rnd_state *state = this_cpu_ptr(&nft_numgen_prandom_state);
141-
142-
return reciprocal_scale(prandom_u32_state(state), priv->modulus) +
143-
priv->offset;
139+
return reciprocal_scale(get_random_u32(), priv->modulus) + priv->offset;
144140
}
145141

146142
static void nft_ng_random_eval(const struct nft_expr *expr,
@@ -168,8 +164,6 @@ static int nft_ng_random_init(const struct nft_ctx *ctx,
168164
if (priv->offset + priv->modulus - 1 < priv->offset)
169165
return -EOVERFLOW;
170166

171-
prandom_init_once(&nft_numgen_prandom_state);
172-
173167
return nft_parse_register_store(ctx, tb[NFTA_NG_DREG], &priv->dreg,
174168
NULL, NFT_DATA_VALUE, sizeof(u32));
175169
}

tools/testing/selftests/netfilter/nft_concat_range.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ BUGS="flush_remove_add reload"
3131

3232
# List of possible paths to pktgen script from kernel tree for performance tests
3333
PKTGEN_SCRIPT_PATHS="
34-
../../../samples/pktgen/pktgen_bench_xmit_mode_netif_receive.sh
34+
../../../../samples/pktgen/pktgen_bench_xmit_mode_netif_receive.sh
3535
pktgen/pktgen_bench_xmit_mode_netif_receive.sh"
3636

3737
# Definition of set types:

0 commit comments

Comments
 (0)