Skip to content

Commit

Permalink
netfilter: nf_tables: reduce nft_pktinfo by 8 bytes
Browse files Browse the repository at this point in the history
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 <fw@strlen.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
  • Loading branch information
Florian Westphal authored and Pablo Neira Ayuso committed Oct 25, 2022
1 parent ac1f8c0 commit e7a1caa
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
4 changes: 2 additions & 2 deletions include/net/netfilter/nf_tables.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ struct nft_pktinfo {
u8 flags;
u8 tprot;
u16 fragoff;
unsigned int thoff;
unsigned int inneroff;
u16 thoff;
u16 inneroff;
};

static inline struct sock *nft_sk(const struct nft_pktinfo *pkt)
Expand Down
4 changes: 4 additions & 0 deletions include/net/netfilter/nf_tables_ipv4.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ static inline int __nft_set_pktinfo_ipv4_validate(struct nft_pktinfo *pkt)
return -1;
else if (len < thoff)
return -1;
else if (thoff < sizeof(*iph))
return -1;

pkt->flags = NFT_PKTINFO_L4PROTO;
pkt->tprot = iph->protocol;
Expand Down Expand Up @@ -69,6 +71,8 @@ static inline int nft_set_pktinfo_ipv4_ingress(struct nft_pktinfo *pkt)
return -1;
} else if (len < thoff) {
goto inhdr_error;
} else if (thoff < sizeof(*iph)) {
return -1;
}

pkt->flags = NFT_PKTINFO_L4PROTO;
Expand Down
6 changes: 3 additions & 3 deletions include/net/netfilter/nf_tables_ipv6.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ static inline void nft_set_pktinfo_ipv6(struct nft_pktinfo *pkt)
unsigned short frag_off;

protohdr = ipv6_find_hdr(pkt->skb, &thoff, -1, &frag_off, &flags);
if (protohdr < 0) {
if (protohdr < 0 || thoff > U16_MAX) {
nft_set_pktinfo_unspec(pkt);
return;
}
Expand Down Expand Up @@ -47,7 +47,7 @@ static inline int __nft_set_pktinfo_ipv6_validate(struct nft_pktinfo *pkt)
return -1;

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

pkt->flags = NFT_PKTINFO_L4PROTO;
Expand Down Expand Up @@ -93,7 +93,7 @@ static inline int nft_set_pktinfo_ipv6_ingress(struct nft_pktinfo *pkt)
}

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

pkt->flags = NFT_PKTINFO_L4PROTO;
Expand Down

0 comments on commit e7a1caa

Please sign in to comment.