Skip to content

Commit e7a1caa

Browse files
Florian Westphalummakynes
authored andcommitted
netfilter: nf_tables: reduce nft_pktinfo by 8 bytes
structure is reduced from 32 to 24 bytes. While at it, also check that iphdrlen is sane, this is guaranteed for NFPROTO_IPV4 but not for ingress or bridge, so add checks for this. Signed-off-by: Florian Westphal <[email protected]> Signed-off-by: Pablo Neira Ayuso <[email protected]>
1 parent ac1f8c0 commit e7a1caa

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

include/net/netfilter/nf_tables.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ struct nft_pktinfo {
3232
u8 flags;
3333
u8 tprot;
3434
u16 fragoff;
35-
unsigned int thoff;
36-
unsigned int inneroff;
35+
u16 thoff;
36+
u16 inneroff;
3737
};
3838

3939
static inline struct sock *nft_sk(const struct nft_pktinfo *pkt)

include/net/netfilter/nf_tables_ipv4.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ static inline int __nft_set_pktinfo_ipv4_validate(struct nft_pktinfo *pkt)
3535
return -1;
3636
else if (len < thoff)
3737
return -1;
38+
else if (thoff < sizeof(*iph))
39+
return -1;
3840

3941
pkt->flags = NFT_PKTINFO_L4PROTO;
4042
pkt->tprot = iph->protocol;
@@ -69,6 +71,8 @@ static inline int nft_set_pktinfo_ipv4_ingress(struct nft_pktinfo *pkt)
6971
return -1;
7072
} else if (len < thoff) {
7173
goto inhdr_error;
74+
} else if (thoff < sizeof(*iph)) {
75+
return -1;
7276
}
7377

7478
pkt->flags = NFT_PKTINFO_L4PROTO;

include/net/netfilter/nf_tables_ipv6.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ static inline void nft_set_pktinfo_ipv6(struct nft_pktinfo *pkt)
1313
unsigned short frag_off;
1414

1515
protohdr = ipv6_find_hdr(pkt->skb, &thoff, -1, &frag_off, &flags);
16-
if (protohdr < 0) {
16+
if (protohdr < 0 || thoff > U16_MAX) {
1717
nft_set_pktinfo_unspec(pkt);
1818
return;
1919
}
@@ -47,7 +47,7 @@ static inline int __nft_set_pktinfo_ipv6_validate(struct nft_pktinfo *pkt)
4747
return -1;
4848

4949
protohdr = ipv6_find_hdr(pkt->skb, &thoff, -1, &frag_off, &flags);
50-
if (protohdr < 0)
50+
if (protohdr < 0 || thoff > U16_MAX)
5151
return -1;
5252

5353
pkt->flags = NFT_PKTINFO_L4PROTO;
@@ -93,7 +93,7 @@ static inline int nft_set_pktinfo_ipv6_ingress(struct nft_pktinfo *pkt)
9393
}
9494

9595
protohdr = ipv6_find_hdr(pkt->skb, &thoff, -1, &frag_off, &flags);
96-
if (protohdr < 0)
96+
if (protohdr < 0 || thoff > U16_MAX)
9797
goto inhdr_error;
9898

9999
pkt->flags = NFT_PKTINFO_L4PROTO;

0 commit comments

Comments
 (0)