Skip to content

Commit fab2ecd

Browse files
committed
Merge: [9.6 P1] netfilter: stable backport from upstream
MR: https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-9/-/merge_requests/5304 JIRA: https://issues.redhat.com/browse/RHEL-60554 Signed-off-by: Florian Westphal <fwestpha@redhat.com> Approved-by: Phil Sutter <psutter@redhat.com> Approved-by: Antoine Tenart <atenart@redhat.com> Approved-by: CKI KWF Bot <cki-ci-bot+kwf-gitlab-com@redhat.com> Merged-by: Rado Vrbovsky <rvrbovsk@redhat.com>
2 parents 9cab413 + 7bcff9f commit fab2ecd

24 files changed

+460
-153
lines changed

include/net/netfilter/nf_tables.h

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,26 @@ static inline void nft_reg_store16(u32 *dreg, u16 val)
145145
*(u16 *)dreg = val;
146146
}
147147

148+
static inline void nft_reg_store_be16(u32 *dreg, __be16 val)
149+
{
150+
nft_reg_store16(dreg, (__force __u16)val);
151+
}
152+
148153
static inline u16 nft_reg_load16(const u32 *sreg)
149154
{
150155
return *(u16 *)sreg;
151156
}
152157

158+
static inline __be16 nft_reg_load_be16(const u32 *sreg)
159+
{
160+
return (__force __be16)nft_reg_load16(sreg);
161+
}
162+
163+
static inline __be32 nft_reg_load_be32(const u32 *sreg)
164+
{
165+
return *(__force __be32 *)sreg;
166+
}
167+
153168
static inline void nft_reg_store64(u64 *dreg, u64 val)
154169
{
155170
put_unaligned(val, dreg);
@@ -791,7 +806,7 @@ static inline bool __nft_set_elem_expired(const struct nft_set_ext *ext,
791806
u64 tstamp)
792807
{
793808
return nft_set_ext_exists(ext, NFT_SET_EXT_EXPIRATION) &&
794-
time_after_eq64(tstamp, *nft_set_ext_expiration(ext));
809+
time_after_eq64(tstamp, READ_ONCE(*nft_set_ext_expiration(ext)));
795810
}
796811

797812
static inline bool nft_set_elem_expired(const struct nft_set_ext *ext)
@@ -1562,6 +1577,7 @@ struct nft_trans_rule {
15621577
(((struct nft_trans_rule *)trans->data)->bound)
15631578

15641579
struct nft_trans_set {
1580+
struct list_head list_trans_newset;
15651581
struct nft_set *set;
15661582
u32 set_id;
15671583
u32 gc_int;
@@ -1710,6 +1726,7 @@ static inline int nft_request_module(struct net *net, const char *fmt, ...) { re
17101726
struct nftables_pernet {
17111727
struct list_head tables;
17121728
struct list_head commit_list;
1729+
struct list_head commit_set_list;
17131730
struct list_head binding_list;
17141731
struct list_head module_list;
17151732
struct list_head notify_list;

include/net/netfilter/nf_tables_core.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,16 +66,6 @@ struct nft_payload {
6666
u8 dreg;
6767
};
6868

69-
struct nft_payload_set {
70-
enum nft_payload_bases base:8;
71-
u8 offset;
72-
u8 len;
73-
u8 sreg;
74-
u8 csum_type;
75-
u8 csum_offset;
76-
u8 csum_flags;
77-
};
78-
7969
extern const struct nft_expr_ops nft_payload_fast_ops;
8070

8171
extern const struct nft_expr_ops nft_bitwise_fast_ops;

include/net/netfilter/nf_tables_ipv4.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ static inline void nft_set_pktinfo_ipv4(struct nft_pktinfo *pkt)
1919
static inline int __nft_set_pktinfo_ipv4_validate(struct nft_pktinfo *pkt)
2020
{
2121
struct iphdr *iph, _iph;
22-
u32 len, thoff;
22+
u32 len, thoff, skb_len;
2323

2424
iph = skb_header_pointer(pkt->skb, skb_network_offset(pkt->skb),
2525
sizeof(*iph), &_iph);
@@ -30,15 +30,17 @@ static inline int __nft_set_pktinfo_ipv4_validate(struct nft_pktinfo *pkt)
3030
return -1;
3131

3232
len = iph_totlen(pkt->skb, iph);
33-
thoff = skb_network_offset(pkt->skb) + (iph->ihl * 4);
34-
if (pkt->skb->len < len)
33+
thoff = iph->ihl * 4;
34+
skb_len = pkt->skb->len - skb_network_offset(pkt->skb);
35+
36+
if (skb_len < len)
3537
return -1;
3638
else if (len < thoff)
3739
return -1;
3840

3941
pkt->flags = NFT_PKTINFO_L4PROTO;
4042
pkt->tprot = iph->protocol;
41-
pkt->thoff = thoff;
43+
pkt->thoff = skb_network_offset(pkt->skb) + thoff;
4244
pkt->fragoff = ntohs(iph->frag_off) & IP_OFFSET;
4345

4446
return 0;

include/net/netfilter/nf_tables_ipv6.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ static inline int __nft_set_pktinfo_ipv6_validate(struct nft_pktinfo *pkt)
3131
struct ipv6hdr *ip6h, _ip6h;
3232
unsigned int thoff = 0;
3333
unsigned short frag_off;
34+
u32 pkt_len, skb_len;
3435
int protohdr;
35-
u32 pkt_len;
3636

3737
ip6h = skb_header_pointer(pkt->skb, skb_network_offset(pkt->skb),
3838
sizeof(*ip6h), &_ip6h);
@@ -43,7 +43,8 @@ static inline int __nft_set_pktinfo_ipv6_validate(struct nft_pktinfo *pkt)
4343
return -1;
4444

4545
pkt_len = ntohs(ip6h->payload_len);
46-
if (pkt_len + sizeof(*ip6h) > pkt->skb->len)
46+
skb_len = pkt->skb->len - skb_network_offset(pkt->skb);
47+
if (pkt_len + sizeof(*ip6h) > skb_len)
4748
return -1;
4849

4950
protohdr = ipv6_find_hdr(pkt->skb, &thoff, -1, &frag_off, &flags);

include/uapi/linux/netfilter/nf_tables.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1372,7 +1372,7 @@ enum nft_secmark_attributes {
13721372
#define NFTA_SECMARK_MAX (__NFTA_SECMARK_MAX - 1)
13731373

13741374
/* Max security context length */
1375-
#define NFT_SECMARK_CTX_MAXLEN 256
1375+
#define NFT_SECMARK_CTX_MAXLEN 4096
13761376

13771377
/**
13781378
* enum nft_reject_types - nf_tables reject expression reject types

net/bridge/br_netfilter_hooks.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,11 @@ static unsigned int br_nf_local_in(void *priv,
619619
if (likely(nf_ct_is_confirmed(ct)))
620620
return NF_ACCEPT;
621621

622+
if (WARN_ON_ONCE(refcount_read(&nfct->use) != 1)) {
623+
nf_reset_ct(skb);
624+
return NF_ACCEPT;
625+
}
626+
622627
/* We can't call nf_confirm here, it would create a dependency
623628
* on nf_conntrack module.
624629
*/

net/bridge/netfilter/nft_meta_bridge.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ static void nft_meta_bridge_get_eval(const struct nft_expr *expr,
5353
goto err;
5454

5555
br_vlan_get_proto(br_dev, &p_proto);
56-
nft_reg_store16(dest, htons(p_proto));
56+
nft_reg_store_be16(dest, htons(p_proto));
5757
return;
5858
}
5959
default:

net/ipv4/netfilter/nf_dup_ipv4.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,17 @@ void nf_dup_ipv4(struct net *net, struct sk_buff *skb, unsigned int hooknum,
5252
{
5353
struct iphdr *iph;
5454

55+
local_bh_disable();
5556
if (this_cpu_read(nf_skb_duplicated))
56-
return;
57+
goto out;
5758
/*
5859
* Copy the skb, and route the copy. Will later return %XT_CONTINUE for
5960
* the original skb, which should continue on its way as if nothing has
6061
* happened. The copy should be independently delivered to the gateway.
6162
*/
6263
skb = pskb_copy(skb, GFP_ATOMIC);
6364
if (skb == NULL)
64-
return;
65+
goto out;
6566

6667
#if IS_ENABLED(CONFIG_NF_CONNTRACK)
6768
/* Avoid counting cloned packets towards the original connection. */
@@ -90,6 +91,8 @@ void nf_dup_ipv4(struct net *net, struct sk_buff *skb, unsigned int hooknum,
9091
} else {
9192
kfree_skb(skb);
9293
}
94+
out:
95+
local_bh_enable();
9396
}
9497
EXPORT_SYMBOL_GPL(nf_dup_ipv4);
9598

net/ipv6/netfilter/nf_dup_ipv6.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,12 @@ static bool nf_dup_ipv6_route(struct net *net, struct sk_buff *skb,
4747
void nf_dup_ipv6(struct net *net, struct sk_buff *skb, unsigned int hooknum,
4848
const struct in6_addr *gw, int oif)
4949
{
50+
local_bh_disable();
5051
if (this_cpu_read(nf_skb_duplicated))
51-
return;
52+
goto out;
5253
skb = pskb_copy(skb, GFP_ATOMIC);
5354
if (skb == NULL)
54-
return;
55+
goto out;
5556

5657
#if IS_ENABLED(CONFIG_NF_CONNTRACK)
5758
nf_reset_ct(skb);
@@ -69,6 +70,8 @@ void nf_dup_ipv6(struct net *net, struct sk_buff *skb, unsigned int hooknum,
6970
} else {
7071
kfree_skb(skb);
7172
}
73+
out:
74+
local_bh_enable();
7275
}
7376
EXPORT_SYMBOL_GPL(nf_dup_ipv6);
7477

net/netfilter/nf_conntrack_netlink.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3426,7 +3426,8 @@ static int ctnetlink_del_expect(struct sk_buff *skb,
34263426

34273427
if (cda[CTA_EXPECT_ID]) {
34283428
__be32 id = nla_get_be32(cda[CTA_EXPECT_ID]);
3429-
if (ntohl(id) != (u32)(unsigned long)exp) {
3429+
3430+
if (id != nf_expect_get_id(exp)) {
34303431
nf_ct_expect_put(exp);
34313432
return -ENOENT;
34323433
}

0 commit comments

Comments
 (0)