Skip to content

Commit a13fbf5

Browse files
lxinkuba-moo
authored andcommitted
netfilter: use skb_ip_totlen and iph_totlen
There are also quite some places in netfilter that may process IPv4 TCP GSO packets, we need to replace them too. In length_mt(), we have to use u_int32_t/int to accept skb_ip_totlen() return value, otherwise it may overflow and mismatch. This change will also help us add selftest for IPv4 BIG TCP in the following patch. Note that we don't need to replace the one in tcpmss_tg4(), as it will return if there is data after tcphdr in tcpmss_mangle_packet(). The same in mangle_contents() in nf_nat_helper.c, it returns false when skb->len + extra > 65535 in enlarge_skb(). Signed-off-by: Xin Long <[email protected]> Reviewed-by: Eric Dumazet <[email protected]> Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 043e397 commit a13fbf5

File tree

4 files changed

+5
-5
lines changed

4 files changed

+5
-5
lines changed

include/net/netfilter/nf_tables_ipv4.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ static inline int __nft_set_pktinfo_ipv4_validate(struct nft_pktinfo *pkt)
2929
if (iph->ihl < 5 || iph->version != 4)
3030
return -1;
3131

32-
len = ntohs(iph->tot_len);
32+
len = iph_totlen(pkt->skb, iph);
3333
thoff = iph->ihl * 4;
3434
if (pkt->skb->len < len)
3535
return -1;
@@ -64,7 +64,7 @@ static inline int nft_set_pktinfo_ipv4_ingress(struct nft_pktinfo *pkt)
6464
if (iph->ihl < 5 || iph->version != 4)
6565
goto inhdr_error;
6666

67-
len = ntohs(iph->tot_len);
67+
len = iph_totlen(pkt->skb, iph);
6868
thoff = iph->ihl * 4;
6969
if (pkt->skb->len < len) {
7070
__IP_INC_STATS(nft_net(pkt), IPSTATS_MIB_INTRUNCATEDPKTS);

net/netfilter/ipvs/ip_vs_xmit.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -994,7 +994,7 @@ ip_vs_prepare_tunneled_skb(struct sk_buff *skb, int skb_af,
994994
old_dsfield = ipv4_get_dsfield(old_iph);
995995
*ttl = old_iph->ttl;
996996
if (payload_len)
997-
*payload_len = ntohs(old_iph->tot_len);
997+
*payload_len = skb_ip_totlen(skb);
998998
}
999999

10001000
/* Implement full-functionality option for ECN encapsulation */

net/netfilter/nf_log_syslog.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ dump_ipv4_packet(struct net *net, struct nf_log_buf *m,
322322

323323
/* Max length: 46 "LEN=65535 TOS=0xFF PREC=0xFF TTL=255 ID=65535 " */
324324
nf_log_buf_add(m, "LEN=%u TOS=0x%02X PREC=0x%02X TTL=%u ID=%u ",
325-
ntohs(ih->tot_len), ih->tos & IPTOS_TOS_MASK,
325+
iph_totlen(skb, ih), ih->tos & IPTOS_TOS_MASK,
326326
ih->tos & IPTOS_PREC_MASK, ih->ttl, ntohs(ih->id));
327327

328328
/* Max length: 6 "CE DF MF " */

net/netfilter/xt_length.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ static bool
2121
length_mt(const struct sk_buff *skb, struct xt_action_param *par)
2222
{
2323
const struct xt_length_info *info = par->matchinfo;
24-
u_int16_t pktlen = ntohs(ip_hdr(skb)->tot_len);
24+
u32 pktlen = skb_ip_totlen(skb);
2525

2626
return (pktlen >= info->min && pktlen <= info->max) ^ info->invert;
2727
}

0 commit comments

Comments
 (0)