All of lore.kernel.org
 help / color / mirror / Atom feed
* nftables stateless NAT in raw table mangles fragmented UDP packets
@ 2021-12-31 12:02 Steffen Weinreich
  2021-12-31 13:37 ` Pablo Neira Ayuso
  0 siblings, 1 reply; 9+ messages in thread
From: Steffen Weinreich @ 2021-12-31 12:02 UTC (permalink / raw)
  To: netfilter; +Cc: steve

Hi

We have using kernel 5.10 and nftables(0.9.8-3.1) from debian for a
stateless NAT GW. We are using the nftables "raw" tables to replace
statically source and destination addresses for pakets traversing the
host with two nftables map, without any connection tracking. The bug is
also reproducible in a Debian 5.16 kernel from experimental.

If fragmented UDP packets are traversing the gateway the second fragment
gets modified at the location where in a non fragmented packet the UDP
checksum would be located.

On the Sample below the packet content at 0x1a-0x1b was changes from
0x61 0x61 to 0xba 0x9e 


This is a minimized version of the ruleset which expedites the bug:

nft list ruleset

table ip raw {
    map M_publicip_in {
        type ipv4_addr : ipv4_addr
        elements = { 100.64.1.1 : 10.1.2.3 }

    }

    map M_publicip_out {
        type ipv4_addr : ipv4_addr
        elements = { 10.1.2.3 : 100.64.1.1 }
    }

    chain PREROUTING {
        type filter hook prerouting priority -300; policy accept;

        jump publicip_out
        jump publicip_in
    }

    chain publicip_out {
        ip saddr set ip saddr map @M_publicip_out accept
    }

    chain publicip_in {
        ip daddr set ip daddr map @M_publicip_in accept
    }
}


This is a fragmented udp packet before NAT:

root@debian:~# tcpdump -l  -i eth0 -nvvvx
tcpdump: listening on eth0, link-type EN10MB (Ethernet), snapshot length
262144 bytes
21:50:15.314671 IP (tos 0x0, ttl 64, id 3756, offset 0, flags [+], proto
UDP (17), length 1500)
    10.2.1.1.45866 > 100.64.1.1.9999: UDP, length 2013
    0x0000:  4500 05dc 0eac 2000 4011 d621 0a02 0101
    0x0010:  6440 0101 b32a 270f 07e5 0016 4865 6c6c
    0x0020:  6f2c 2057 6f72 6c64 2161 6161 6161 6161
    0x0030:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0040:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0050:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0060:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0070:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0080:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0090:  6161 6161 6161 6161 6161 6161 6161 6161
    0x00a0:  6161 6161 6161 6161 6161 6161 6161 6161
    0x00b0:  6161 6161 6161 6161 6161 6161 6161 6161
    0x00c0:  6161 6161 6161 6161 6161 6161 6161 6161
    0x00d0:  6161 6161 6161 6161 6161 6161 6161 6161
    0x00e0:  6161 6161 6161 6161 6161 6161 6161 6161
    0x00f0:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0100:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0110:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0120:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0130:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0140:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0150:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0160:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0170:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0180:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0190:  6161 6161 6161 6161 6161 6161 6161 6161
    0x01a0:  6161 6161 6161 6161 6161 6161 6161 6161
    0x01b0:  6161 6161 6161 6161 6161 6161 6161 6161
    0x01c0:  6161 6161 6161 6161 6161 6161 6161 6161
    0x01d0:  6161 6161 6161 6161 6161 6161 6161 6161
    0x01e0:  6161 6161 6161 6161 6161 6161 6161 6161
    0x01f0:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0200:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0210:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0220:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0230:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0240:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0250:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0260:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0270:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0280:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0290:  6161 6161 6161 6161 6161 6161 6161 6161
    0x02a0:  6161 6161 6161 6161 6161 6161 6161 6161
    0x02b0:  6161 6161 6161 6161 6161 6161 6161 6161
    0x02c0:  6161 6161 6161 6161 6161 6161 6161 6161
    0x02d0:  6161 6161 6161 6161 6161 6161 6161 6161
    0x02e0:  6161 6161 6161 6161 6161 6161 6161 6161
    0x02f0:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0300:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0310:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0320:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0330:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0340:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0350:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0360:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0370:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0380:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0390:  6161 6161 6161 6161 6161 6161 6161 6161
    0x03a0:  6161 6161 6161 6161 6161 6161 6161 6161
    0x03b0:  6161 6161 6161 6161 6161 6161 6161 6161
    0x03c0:  6161 6161 6161 6161 6161 6161 6161 6161
    0x03d0:  6161 6161 6161 6161 6161 6161 6161 6161
    0x03e0:  6161 6161 6161 6161 6161 6161 6161 6161
    0x03f0:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0400:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0410:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0420:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0430:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0440:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0450:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0460:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0470:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0480:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0490:  6161 6161 6161 6161 6161 6161 6161 6161
    0x04a0:  6161 6161 6161 6161 6161 6161 6161 6161
    0x04b0:  6161 6161 6161 6161 6161 6161 6161 6161
    0x04c0:  6161 6161 6161 6161 6161 6161 6161 6161
    0x04d0:  6161 6161 6161 6161 6161 6161 6161 6161
    0x04e0:  6161 6161 6161 6161 6161 6161 6161 6161
    0x04f0:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0500:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0510:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0520:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0530:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0540:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0550:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0560:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0570:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0580:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0590:  6161 6161 6161 6161 6161 6161 6161 6161
    0x05a0:  6161 6161 6161 6161 6161 6161 6161 6161
    0x05b0:  6161 6161 6161 6161 6161 6161 6161 6161
    0x05c0:  6161 6161 6161 6161 6161 6161 6161 6161
    0x05d0:  6161 6161 6161 6161 6161 6161
21:50:15.314687 IP (tos 0x0, ttl 64, id 3756, offset 1480, flags [none],
proto UDP (17), length 561)
    10.2.1.1 > 100.64.1.1: ip-proto-17
    0x0000:  4500 0231 0eac 00b9 4011 f913 0a02 0101
    0x0010:  6440 0101 6161 6161 6161 6161 6161 6161
    0x0020:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0030:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0040:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0050:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0060:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0070:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0080:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0090:  6161 6161 6161 6161 6161 6161 6161 6161
    0x00a0:  6161 6161 6161 6161 6161 6161 6161 6161
    0x00b0:  6161 6161 6161 6161 6161 6161 6161 6161
    0x00c0:  6161 6161 6161 6161 6161 6161 6161 6161
    0x00d0:  6161 6161 6161 6161 6161 6161 6161 6161
    0x00e0:  6161 6161 6161 6161 6161 6161 6161 6161
    0x00f0:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0100:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0110:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0120:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0130:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0140:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0150:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0160:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0170:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0180:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0190:  6161 6161 6161 6161 6161 6161 6161 6161
    0x01a0:  6161 6161 6161 6161 6161 6161 6161 6161
    0x01b0:  6161 6161 6161 6161 6161 6161 6161 6161
    0x01c0:  6161 6161 6161 6161 6161 6161 6161 6161
    0x01d0:  6161 6161 6161 6161 6161 6161 6161 6161
    0x01e0:  6161 6161 6161 6161 6161 6161 6161 6161
    0x01f0:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0200:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0210:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0220:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0230:  61


This is a fragmented udp packet after NAT. See the second fragment at
offset 0x1a and compare it with the previous example

21:49:32.999088 IP (tos 0x0, ttl 63, id 87, offset 0, flags [+], proto
UDP (17), length 1500)
    10.2.1.1.46549 > 10.1.2.3.9999: UDP, length 2013
    0x0000:  4500 05dc 0057 2000 3f11 3eb4 0a02 0101
    0x0010:  0a01 0203 b5d5 270f 07e5 56a8 4865 6c6c
    0x0020:  6f2c 2057 6f72 6c64 2161 6161 6161 6161
    0x0030:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0040:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0050:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0060:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0070:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0080:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0090:  6161 6161 6161 6161 6161 6161 6161 6161
    0x00a0:  6161 6161 6161 6161 6161 6161 6161 6161
    0x00b0:  6161 6161 6161 6161 6161 6161 6161 6161
    0x00c0:  6161 6161 6161 6161 6161 6161 6161 6161
    0x00d0:  6161 6161 6161 6161 6161 6161 6161 6161
    0x00e0:  6161 6161 6161 6161 6161 6161 6161 6161
    0x00f0:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0100:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0110:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0120:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0130:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0140:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0150:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0160:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0170:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0180:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0190:  6161 6161 6161 6161 6161 6161 6161 6161
    0x01a0:  6161 6161 6161 6161 6161 6161 6161 6161
    0x01b0:  6161 6161 6161 6161 6161 6161 6161 6161
    0x01c0:  6161 6161 6161 6161 6161 6161 6161 6161
    0x01d0:  6161 6161 6161 6161 6161 6161 6161 6161
    0x01e0:  6161 6161 6161 6161 6161 6161 6161 6161
    0x01f0:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0200:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0210:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0220:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0230:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0240:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0250:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0260:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0270:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0280:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0290:  6161 6161 6161 6161 6161 6161 6161 6161
    0x02a0:  6161 6161 6161 6161 6161 6161 6161 6161
    0x02b0:  6161 6161 6161 6161 6161 6161 6161 6161
    0x02c0:  6161 6161 6161 6161 6161 6161 6161 6161
    0x02d0:  6161 6161 6161 6161 6161 6161 6161 6161
    0x02e0:  6161 6161 6161 6161 6161 6161 6161 6161
    0x02f0:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0300:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0310:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0320:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0330:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0340:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0350:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0360:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0370:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0380:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0390:  6161 6161 6161 6161 6161 6161 6161 6161
    0x03a0:  6161 6161 6161 6161 6161 6161 6161 6161
    0x03b0:  6161 6161 6161 6161 6161 6161 6161 6161
    0x03c0:  6161 6161 6161 6161 6161 6161 6161 6161
    0x03d0:  6161 6161 6161 6161 6161 6161 6161 6161
    0x03e0:  6161 6161 6161 6161 6161 6161 6161 6161
    0x03f0:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0400:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0410:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0420:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0430:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0440:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0450:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0460:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0470:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0480:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0490:  6161 6161 6161 6161 6161 6161 6161 6161
    0x04a0:  6161 6161 6161 6161 6161 6161 6161 6161
    0x04b0:  6161 6161 6161 6161 6161 6161 6161 6161
    0x04c0:  6161 6161 6161 6161 6161 6161 6161 6161
    0x04d0:  6161 6161 6161 6161 6161 6161 6161 6161
    0x04e0:  6161 6161 6161 6161 6161 6161 6161 6161
    0x04f0:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0500:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0510:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0520:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0530:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0540:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0550:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0560:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0570:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0580:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0590:  6161 6161 6161 6161 6161 6161 6161 6161
    0x05a0:  6161 6161 6161 6161 6161 6161 6161 6161
    0x05b0:  6161 6161 6161 6161 6161 6161 6161 6161
    0x05c0:  6161 6161 6161 6161 6161 6161 6161 6161
    0x05d0:  6161 6161 6161 6161 6161 6161
21:49:32.999096 IP (tos 0x0, ttl 63, id 87, offset 1480, flags [none],
proto UDP (17), length 561)
    10.2.1.1 > 10.1.2.3: ip-proto-17
    0x0000:  4500 0231 0057 00b9 3f11 61a6 0a02 0101
    0x0010:  0a01 0203 6161 6161 6161 ba9e 6161 6161
    0x0020:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0030:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0040:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0050:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0060:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0070:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0080:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0090:  6161 6161 6161 6161 6161 6161 6161 6161
    0x00a0:  6161 6161 6161 6161 6161 6161 6161 6161
    0x00b0:  6161 6161 6161 6161 6161 6161 6161 6161
    0x00c0:  6161 6161 6161 6161 6161 6161 6161 6161
    0x00d0:  6161 6161 6161 6161 6161 6161 6161 6161
    0x00e0:  6161 6161 6161 6161 6161 6161 6161 6161
    0x00f0:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0100:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0110:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0120:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0130:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0140:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0150:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0160:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0170:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0180:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0190:  6161 6161 6161 6161 6161 6161 6161 6161
    0x01a0:  6161 6161 6161 6161 6161 6161 6161 6161
    0x01b0:  6161 6161 6161 6161 6161 6161 6161 6161
    0x01c0:  6161 6161 6161 6161 6161 6161 6161 6161
    0x01d0:  6161 6161 6161 6161 6161 6161 6161 6161
    0x01e0:  6161 6161 6161 6161 6161 6161 6161 6161
    0x01f0:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0200:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0210:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0220:  6161 6161 6161 6161 6161 6161 6161 6161
    0x0230:  61


The behaviour could be reproduced using the VM with a freshly installed
debian bullseye and the following script. The script setups two
different  Network namespaces which are used for reproducing the bug.
(On our prodcution Setup no NNS are used)


#!/bin/bash

# ============================================================
# setup nns test
# here traffic for ip 100.64.1.1 will be rewritten to 10.1.2.3
ip netns add test
ip link add eth1 type veth
ip link set dev veth0 netns test name eth0

ip link set dev eth1 up
ip address add 10.2.1.1/30 dev eth1

ip netns exec test ip link set dev eth0 up
ip netns exec test ip address add 10.2.1.2/30 dev eth0

ip route add 100.64.1.1/32 via 10.2.1.2

# Load nftables rules for stateless nat
ip netns exec test /usr/sbin/nft -f test.nft


# ============================================================
# setup nns test2
# here the ip adress 10.1.2.3 is bound
ip netns add test2
ip netns exec test2 ip link add eth0 type veth
ip netns exec test2 ip link set dev veth0 netns test name eth1
ip netns exec test2 ip link set dev eth0 up
ip netns exec test2 ip address add 10.1.2.3/28 dev eth0

ip netns exec test ip link set dev eth1 up
ip netns exec test ip address add 10.1.2.1/28 dev eth1


# =================
# Enable forwarding
# =================
/sbin/sysctl net.ipv4.conf.all.forwarding=1
ip netns exec test /sbin/sysctl net.ipv4.conf.all.forwarding=1
ip netns exec test2 /sbin/sysctl net.ipv4.conf.all.forwarding=1


The following python script is used to send  fragmented UDP frames from
the root NNS to the test NNS


#!env python3
import socket

byte_message = bytes("Hello, World!" + "a"*2000, "utf-8")

opened_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
opened_socket.sendto(byte_message, ("100.64.1.1", 9999))






^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: nftables stateless NAT in raw table mangles fragmented UDP packets
  2021-12-31 12:02 nftables stateless NAT in raw table mangles fragmented UDP packets Steffen Weinreich
@ 2021-12-31 13:37 ` Pablo Neira Ayuso
  2021-12-31 13:39   ` Pablo Neira Ayuso
  0 siblings, 1 reply; 9+ messages in thread
From: Pablo Neira Ayuso @ 2021-12-31 13:37 UTC (permalink / raw)
  To: Steffen Weinreich; +Cc: netfilter

[-- Attachment #1: Type: text/plain, Size: 19677 bytes --]

Hi,

On Fri, Dec 31, 2021 at 01:02:13PM +0100, Steffen Weinreich wrote:
> Hi
> 
> We have using kernel 5.10 and nftables(0.9.8-3.1) from debian for a
> stateless NAT GW. We are using the nftables "raw" tables to replace
> statically source and destination addresses for pakets traversing the
> host with two nftables map, without any connection tracking. The bug is
> also reproducible in a Debian 5.16 kernel from experimental.
> 
> If fragmented UDP packets are traversing the gateway the second fragment
> gets modified at the location where in a non fragmented packet the UDP
> checksum would be located.
> 
> On the Sample below the packet content at 0x1a-0x1b was changes from
> 0x61 0x61 to 0xba 0x9e 

Could you give a try to this kernel patch?

Thanks for reporting.

> This is a minimized version of the ruleset which expedites the bug:
> 
> nft list ruleset
> 
> table ip raw {
>     map M_publicip_in {
>         type ipv4_addr : ipv4_addr
>         elements = { 100.64.1.1 : 10.1.2.3 }
> 
>     }
> 
>     map M_publicip_out {
>         type ipv4_addr : ipv4_addr
>         elements = { 10.1.2.3 : 100.64.1.1 }
>     }
> 
>     chain PREROUTING {
>         type filter hook prerouting priority -300; policy accept;
> 
>         jump publicip_out
>         jump publicip_in
>     }
> 
>     chain publicip_out {
>         ip saddr set ip saddr map @M_publicip_out accept
>     }
> 
>     chain publicip_in {
>         ip daddr set ip daddr map @M_publicip_in accept
>     }
> }
> 
> 
> This is a fragmented udp packet before NAT:
> 
> root@debian:~# tcpdump -l  -i eth0 -nvvvx
> tcpdump: listening on eth0, link-type EN10MB (Ethernet), snapshot length
> 262144 bytes
> 21:50:15.314671 IP (tos 0x0, ttl 64, id 3756, offset 0, flags [+], proto
> UDP (17), length 1500)
>     10.2.1.1.45866 > 100.64.1.1.9999: UDP, length 2013
>     0x0000:  4500 05dc 0eac 2000 4011 d621 0a02 0101
>     0x0010:  6440 0101 b32a 270f 07e5 0016 4865 6c6c
>     0x0020:  6f2c 2057 6f72 6c64 2161 6161 6161 6161
>     0x0030:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0040:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0050:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0060:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0070:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0080:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0090:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x00a0:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x00b0:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x00c0:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x00d0:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x00e0:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x00f0:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0100:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0110:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0120:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0130:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0140:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0150:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0160:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0170:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0180:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0190:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x01a0:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x01b0:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x01c0:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x01d0:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x01e0:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x01f0:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0200:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0210:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0220:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0230:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0240:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0250:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0260:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0270:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0280:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0290:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x02a0:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x02b0:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x02c0:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x02d0:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x02e0:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x02f0:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0300:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0310:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0320:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0330:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0340:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0350:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0360:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0370:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0380:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0390:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x03a0:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x03b0:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x03c0:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x03d0:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x03e0:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x03f0:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0400:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0410:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0420:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0430:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0440:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0450:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0460:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0470:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0480:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0490:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x04a0:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x04b0:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x04c0:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x04d0:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x04e0:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x04f0:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0500:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0510:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0520:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0530:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0540:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0550:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0560:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0570:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0580:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0590:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x05a0:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x05b0:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x05c0:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x05d0:  6161 6161 6161 6161 6161 6161
> 21:50:15.314687 IP (tos 0x0, ttl 64, id 3756, offset 1480, flags [none],
> proto UDP (17), length 561)
>     10.2.1.1 > 100.64.1.1: ip-proto-17
>     0x0000:  4500 0231 0eac 00b9 4011 f913 0a02 0101
>     0x0010:  6440 0101 6161 6161 6161 6161 6161 6161
>     0x0020:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0030:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0040:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0050:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0060:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0070:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0080:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0090:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x00a0:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x00b0:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x00c0:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x00d0:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x00e0:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x00f0:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0100:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0110:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0120:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0130:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0140:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0150:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0160:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0170:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0180:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0190:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x01a0:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x01b0:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x01c0:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x01d0:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x01e0:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x01f0:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0200:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0210:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0220:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0230:  61
> 
> 
> This is a fragmented udp packet after NAT. See the second fragment at
> offset 0x1a and compare it with the previous example
> 
> 21:49:32.999088 IP (tos 0x0, ttl 63, id 87, offset 0, flags [+], proto
> UDP (17), length 1500)
>     10.2.1.1.46549 > 10.1.2.3.9999: UDP, length 2013
>     0x0000:  4500 05dc 0057 2000 3f11 3eb4 0a02 0101
>     0x0010:  0a01 0203 b5d5 270f 07e5 56a8 4865 6c6c
>     0x0020:  6f2c 2057 6f72 6c64 2161 6161 6161 6161
>     0x0030:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0040:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0050:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0060:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0070:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0080:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0090:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x00a0:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x00b0:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x00c0:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x00d0:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x00e0:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x00f0:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0100:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0110:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0120:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0130:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0140:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0150:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0160:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0170:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0180:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0190:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x01a0:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x01b0:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x01c0:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x01d0:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x01e0:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x01f0:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0200:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0210:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0220:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0230:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0240:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0250:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0260:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0270:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0280:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0290:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x02a0:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x02b0:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x02c0:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x02d0:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x02e0:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x02f0:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0300:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0310:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0320:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0330:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0340:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0350:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0360:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0370:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0380:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0390:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x03a0:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x03b0:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x03c0:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x03d0:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x03e0:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x03f0:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0400:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0410:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0420:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0430:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0440:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0450:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0460:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0470:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0480:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0490:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x04a0:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x04b0:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x04c0:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x04d0:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x04e0:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x04f0:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0500:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0510:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0520:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0530:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0540:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0550:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0560:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0570:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0580:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0590:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x05a0:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x05b0:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x05c0:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x05d0:  6161 6161 6161 6161 6161 6161
> 21:49:32.999096 IP (tos 0x0, ttl 63, id 87, offset 1480, flags [none],
> proto UDP (17), length 561)
>     10.2.1.1 > 10.1.2.3: ip-proto-17
>     0x0000:  4500 0231 0057 00b9 3f11 61a6 0a02 0101
>     0x0010:  0a01 0203 6161 6161 6161 ba9e 6161 6161
>     0x0020:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0030:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0040:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0050:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0060:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0070:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0080:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0090:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x00a0:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x00b0:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x00c0:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x00d0:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x00e0:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x00f0:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0100:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0110:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0120:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0130:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0140:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0150:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0160:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0170:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0180:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0190:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x01a0:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x01b0:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x01c0:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x01d0:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x01e0:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x01f0:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0200:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0210:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0220:  6161 6161 6161 6161 6161 6161 6161 6161
>     0x0230:  61
> 
> 
> The behaviour could be reproduced using the VM with a freshly installed
> debian bullseye and the following script. The script setups two
> different  Network namespaces which are used for reproducing the bug.
> (On our prodcution Setup no NNS are used)
> 
> 
> #!/bin/bash
> 
> # ============================================================
> # setup nns test
> # here traffic for ip 100.64.1.1 will be rewritten to 10.1.2.3
> ip netns add test
> ip link add eth1 type veth
> ip link set dev veth0 netns test name eth0
> 
> ip link set dev eth1 up
> ip address add 10.2.1.1/30 dev eth1
> 
> ip netns exec test ip link set dev eth0 up
> ip netns exec test ip address add 10.2.1.2/30 dev eth0
> 
> ip route add 100.64.1.1/32 via 10.2.1.2
> 
> # Load nftables rules for stateless nat
> ip netns exec test /usr/sbin/nft -f test.nft
> 
> 
> # ============================================================
> # setup nns test2
> # here the ip adress 10.1.2.3 is bound
> ip netns add test2
> ip netns exec test2 ip link add eth0 type veth
> ip netns exec test2 ip link set dev veth0 netns test name eth1
> ip netns exec test2 ip link set dev eth0 up
> ip netns exec test2 ip address add 10.1.2.3/28 dev eth0
> 
> ip netns exec test ip link set dev eth1 up
> ip netns exec test ip address add 10.1.2.1/28 dev eth1
> 
> 
> # =================
> # Enable forwarding
> # =================
> /sbin/sysctl net.ipv4.conf.all.forwarding=1
> ip netns exec test /sbin/sysctl net.ipv4.conf.all.forwarding=1
> ip netns exec test2 /sbin/sysctl net.ipv4.conf.all.forwarding=1
> 
> 
> The following python script is used to send  fragmented UDP frames from
> the root NNS to the test NNS
> 
> 
> #!env python3
> import socket
> 
> byte_message = bytes("Hello, World!" + "a"*2000, "utf-8")
> 
> opened_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
> opened_socket.sendto(byte_message, ("100.64.1.1", 9999))
> 
> 
> 
> 
> 

[-- Attachment #2: x.patch --]
[-- Type: text/x-diff, Size: 484 bytes --]

diff --git a/net/netfilter/nft_payload.c b/net/netfilter/nft_payload.c
index bd689938a2e0..77deb312d3ad 100644
--- a/net/netfilter/nft_payload.c
+++ b/net/netfilter/nft_payload.c
@@ -588,6 +588,9 @@ static int nft_payload_l4csum_update(const struct nft_pktinfo *pkt,
 	int l4csum_offset;
 	__sum16 sum;
 
+	if (pkt->fragoff)
+		return 0;
+
 	/* If we cannot determine layer 4 checksum offset or this packet doesn't
 	 * require layer 4 checksum recalculation, skip this packet.
 	 */

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: nftables stateless NAT in raw table mangles fragmented UDP packets
  2021-12-31 13:37 ` Pablo Neira Ayuso
@ 2021-12-31 13:39   ` Pablo Neira Ayuso
  2022-01-04 11:27     ` Steffen Weinreich
  2022-01-24 16:49     ` Steffen Weinreich
  0 siblings, 2 replies; 9+ messages in thread
From: Pablo Neira Ayuso @ 2021-12-31 13:39 UTC (permalink / raw)
  To: Steffen Weinreich; +Cc: netfilter

[-- Attachment #1: Type: text/plain, Size: 21093 bytes --]

On Fri, Dec 31, 2021 at 02:37:47PM +0100, Pablo Neira Ayuso wrote:
> Hi,
> 
> On Fri, Dec 31, 2021 at 01:02:13PM +0100, Steffen Weinreich wrote:
> > Hi
> > 
> > We have using kernel 5.10 and nftables(0.9.8-3.1) from debian for a
> > stateless NAT GW. We are using the nftables "raw" tables to replace
> > statically source and destination addresses for pakets traversing the
> > host with two nftables map, without any connection tracking. The bug is
> > also reproducible in a Debian 5.16 kernel from experimental.
> > 
> > If fragmented UDP packets are traversing the gateway the second fragment
> > gets modified at the location where in a non fragmented packet the UDP
> > checksum would be located.
> > 
> > On the Sample below the packet content at 0x1a-0x1b was changes from
> > 0x61 0x61 to 0xba 0x9e 
> 
> Could you give a try to this kernel patch?

Wrong patch, attaching again.

> Thanks for reporting.
> 
> > This is a minimized version of the ruleset which expedites the bug:
> > 
> > nft list ruleset
> > 
> > table ip raw {
> >     map M_publicip_in {
> >         type ipv4_addr : ipv4_addr
> >         elements = { 100.64.1.1 : 10.1.2.3 }
> > 
> >     }
> > 
> >     map M_publicip_out {
> >         type ipv4_addr : ipv4_addr
> >         elements = { 10.1.2.3 : 100.64.1.1 }
> >     }
> > 
> >     chain PREROUTING {
> >         type filter hook prerouting priority -300; policy accept;
> > 
> >         jump publicip_out
> >         jump publicip_in
> >     }
> > 
> >     chain publicip_out {
> >         ip saddr set ip saddr map @M_publicip_out accept
> >     }
> > 
> >     chain publicip_in {
> >         ip daddr set ip daddr map @M_publicip_in accept
> >     }
> > }
> > 
> > 
> > This is a fragmented udp packet before NAT:
> > 
> > root@debian:~# tcpdump -l  -i eth0 -nvvvx
> > tcpdump: listening on eth0, link-type EN10MB (Ethernet), snapshot length
> > 262144 bytes
> > 21:50:15.314671 IP (tos 0x0, ttl 64, id 3756, offset 0, flags [+], proto
> > UDP (17), length 1500)
> >     10.2.1.1.45866 > 100.64.1.1.9999: UDP, length 2013
> >     0x0000:  4500 05dc 0eac 2000 4011 d621 0a02 0101
> >     0x0010:  6440 0101 b32a 270f 07e5 0016 4865 6c6c
> >     0x0020:  6f2c 2057 6f72 6c64 2161 6161 6161 6161
> >     0x0030:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0040:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0050:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0060:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0070:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0080:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0090:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x00a0:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x00b0:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x00c0:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x00d0:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x00e0:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x00f0:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0100:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0110:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0120:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0130:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0140:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0150:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0160:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0170:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0180:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0190:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x01a0:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x01b0:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x01c0:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x01d0:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x01e0:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x01f0:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0200:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0210:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0220:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0230:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0240:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0250:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0260:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0270:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0280:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0290:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x02a0:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x02b0:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x02c0:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x02d0:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x02e0:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x02f0:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0300:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0310:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0320:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0330:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0340:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0350:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0360:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0370:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0380:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0390:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x03a0:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x03b0:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x03c0:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x03d0:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x03e0:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x03f0:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0400:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0410:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0420:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0430:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0440:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0450:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0460:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0470:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0480:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0490:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x04a0:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x04b0:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x04c0:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x04d0:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x04e0:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x04f0:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0500:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0510:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0520:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0530:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0540:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0550:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0560:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0570:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0580:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0590:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x05a0:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x05b0:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x05c0:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x05d0:  6161 6161 6161 6161 6161 6161
> > 21:50:15.314687 IP (tos 0x0, ttl 64, id 3756, offset 1480, flags [none],
> > proto UDP (17), length 561)
> >     10.2.1.1 > 100.64.1.1: ip-proto-17
> >     0x0000:  4500 0231 0eac 00b9 4011 f913 0a02 0101
> >     0x0010:  6440 0101 6161 6161 6161 6161 6161 6161
> >     0x0020:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0030:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0040:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0050:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0060:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0070:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0080:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0090:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x00a0:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x00b0:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x00c0:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x00d0:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x00e0:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x00f0:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0100:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0110:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0120:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0130:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0140:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0150:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0160:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0170:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0180:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0190:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x01a0:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x01b0:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x01c0:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x01d0:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x01e0:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x01f0:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0200:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0210:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0220:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0230:  61
> > 
> > 
> > This is a fragmented udp packet after NAT. See the second fragment at
> > offset 0x1a and compare it with the previous example
> > 
> > 21:49:32.999088 IP (tos 0x0, ttl 63, id 87, offset 0, flags [+], proto
> > UDP (17), length 1500)
> >     10.2.1.1.46549 > 10.1.2.3.9999: UDP, length 2013
> >     0x0000:  4500 05dc 0057 2000 3f11 3eb4 0a02 0101
> >     0x0010:  0a01 0203 b5d5 270f 07e5 56a8 4865 6c6c
> >     0x0020:  6f2c 2057 6f72 6c64 2161 6161 6161 6161
> >     0x0030:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0040:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0050:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0060:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0070:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0080:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0090:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x00a0:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x00b0:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x00c0:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x00d0:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x00e0:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x00f0:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0100:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0110:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0120:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0130:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0140:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0150:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0160:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0170:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0180:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0190:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x01a0:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x01b0:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x01c0:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x01d0:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x01e0:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x01f0:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0200:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0210:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0220:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0230:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0240:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0250:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0260:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0270:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0280:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0290:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x02a0:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x02b0:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x02c0:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x02d0:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x02e0:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x02f0:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0300:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0310:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0320:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0330:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0340:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0350:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0360:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0370:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0380:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0390:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x03a0:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x03b0:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x03c0:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x03d0:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x03e0:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x03f0:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0400:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0410:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0420:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0430:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0440:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0450:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0460:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0470:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0480:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0490:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x04a0:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x04b0:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x04c0:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x04d0:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x04e0:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x04f0:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0500:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0510:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0520:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0530:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0540:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0550:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0560:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0570:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0580:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0590:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x05a0:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x05b0:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x05c0:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x05d0:  6161 6161 6161 6161 6161 6161
> > 21:49:32.999096 IP (tos 0x0, ttl 63, id 87, offset 1480, flags [none],
> > proto UDP (17), length 561)
> >     10.2.1.1 > 10.1.2.3: ip-proto-17
> >     0x0000:  4500 0231 0057 00b9 3f11 61a6 0a02 0101
> >     0x0010:  0a01 0203 6161 6161 6161 ba9e 6161 6161
> >     0x0020:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0030:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0040:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0050:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0060:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0070:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0080:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0090:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x00a0:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x00b0:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x00c0:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x00d0:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x00e0:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x00f0:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0100:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0110:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0120:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0130:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0140:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0150:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0160:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0170:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0180:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0190:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x01a0:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x01b0:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x01c0:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x01d0:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x01e0:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x01f0:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0200:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0210:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0220:  6161 6161 6161 6161 6161 6161 6161 6161
> >     0x0230:  61
> > 
> > 
> > The behaviour could be reproduced using the VM with a freshly installed
> > debian bullseye and the following script. The script setups two
> > different  Network namespaces which are used for reproducing the bug.
> > (On our prodcution Setup no NNS are used)
> > 
> > 
> > #!/bin/bash
> > 
> > # ============================================================
> > # setup nns test
> > # here traffic for ip 100.64.1.1 will be rewritten to 10.1.2.3
> > ip netns add test
> > ip link add eth1 type veth
> > ip link set dev veth0 netns test name eth0
> > 
> > ip link set dev eth1 up
> > ip address add 10.2.1.1/30 dev eth1
> > 
> > ip netns exec test ip link set dev eth0 up
> > ip netns exec test ip address add 10.2.1.2/30 dev eth0
> > 
> > ip route add 100.64.1.1/32 via 10.2.1.2
> > 
> > # Load nftables rules for stateless nat
> > ip netns exec test /usr/sbin/nft -f test.nft
> > 
> > 
> > # ============================================================
> > # setup nns test2
> > # here the ip adress 10.1.2.3 is bound
> > ip netns add test2
> > ip netns exec test2 ip link add eth0 type veth
> > ip netns exec test2 ip link set dev veth0 netns test name eth1
> > ip netns exec test2 ip link set dev eth0 up
> > ip netns exec test2 ip address add 10.1.2.3/28 dev eth0
> > 
> > ip netns exec test ip link set dev eth1 up
> > ip netns exec test ip address add 10.1.2.1/28 dev eth1
> > 
> > 
> > # =================
> > # Enable forwarding
> > # =================
> > /sbin/sysctl net.ipv4.conf.all.forwarding=1
> > ip netns exec test /sbin/sysctl net.ipv4.conf.all.forwarding=1
> > ip netns exec test2 /sbin/sysctl net.ipv4.conf.all.forwarding=1
> > 
> > 
> > The following python script is used to send  fragmented UDP frames from
> > the root NNS to the test NNS
> > 
> > 
> > #!env python3
> > import socket
> > 
> > byte_message = bytes("Hello, World!" + "a"*2000, "utf-8")
> > 
> > opened_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
> > opened_socket.sendto(byte_message, ("100.64.1.1", 9999))
> > 
> > 
> > 
> > 
> > 

> diff --git a/net/netfilter/nft_payload.c b/net/netfilter/nft_payload.c
> index bd689938a2e0..77deb312d3ad 100644
> --- a/net/netfilter/nft_payload.c
> +++ b/net/netfilter/nft_payload.c
> @@ -588,6 +588,9 @@ static int nft_payload_l4csum_update(const struct nft_pktinfo *pkt,
>  	int l4csum_offset;
>  	__sum16 sum;
>  
> +	if (pkt->fragoff)
> +		return 0;
> +
>  	/* If we cannot determine layer 4 checksum offset or this packet doesn't
>  	 * require layer 4 checksum recalculation, skip this packet.
>  	 */


[-- Attachment #2: x.patch --]
[-- Type: text/x-diff, Size: 472 bytes --]

diff --git a/net/netfilter/nft_payload.c b/net/netfilter/nft_payload.c
index bd689938a2e0..58e96a0fe0b4 100644
--- a/net/netfilter/nft_payload.c
+++ b/net/netfilter/nft_payload.c
@@ -546,6 +546,9 @@ static int nft_payload_l4csum_offset(const struct nft_pktinfo *pkt,
 				     struct sk_buff *skb,
 				     unsigned int *l4csum_offset)
 {
+	if (pkt->fragoff)
+		return -1;
+
 	switch (pkt->tprot) {
 	case IPPROTO_TCP:
 		*l4csum_offset = offsetof(struct tcphdr, check);

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: nftables stateless NAT in raw table mangles fragmented UDP packets
  2021-12-31 13:39   ` Pablo Neira Ayuso
@ 2022-01-04 11:27     ` Steffen Weinreich
  2022-01-04 18:38       ` Steffen Weinreich
  2022-01-24 16:49     ` Steffen Weinreich
  1 sibling, 1 reply; 9+ messages in thread
From: Steffen Weinreich @ 2022-01-04 11:27 UTC (permalink / raw)
  To: Pablo Neira Ayuso; +Cc: netfilter

Hi Pablo,

Am 31.12.21 um 14:39 schrieb Pablo Neira Ayuso:
>> Could you give a try to this kernel patch?
> Wrong patch, attaching again.

Yes, that patch fixes the issue.


cheerio

Steve


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: nftables stateless NAT in raw table mangles fragmented UDP packets
  2022-01-04 11:27     ` Steffen Weinreich
@ 2022-01-04 18:38       ` Steffen Weinreich
  2022-01-04 18:41         ` Florian Westphal
  0 siblings, 1 reply; 9+ messages in thread
From: Steffen Weinreich @ 2022-01-04 18:38 UTC (permalink / raw)
  To: Pablo Neira Ayuso; +Cc: netfilter

Hi Pablo

Am 04.01.22 um 12:27 schrieb Steffen Weinreich:
> Hi Pablo,
>
> Am 31.12.21 um 14:39 schrieb Pablo Neira Ayuso:
>>> Could you give a try to this kernel patch?
>> Wrong patch, attaching again.
> Yes, that patch fixes the issue.

Meanwhile I tried that patch on a 4.19 Kernel. Since the struct
nft_pktinfo pkt does not have a member fragoff the patch does not work
on 4.19

Any chance to get a patch for a 4.19?  We are still using the debian
buster 4.19 kernel  series on out production systems and are currently
not able to move to a newer kernel due to issues with the userland nft
tools and our wrapper around them..

cheerio

Steve


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: nftables stateless NAT in raw table mangles fragmented UDP packets
  2022-01-04 18:38       ` Steffen Weinreich
@ 2022-01-04 18:41         ` Florian Westphal
  2022-01-04 19:41           ` Steffen Weinreich
  0 siblings, 1 reply; 9+ messages in thread
From: Florian Westphal @ 2022-01-04 18:41 UTC (permalink / raw)
  To: Steffen Weinreich; +Cc: Pablo Neira Ayuso, netfilter

Steffen Weinreich <steve@weinreich.org> wrote:
> Hi Pablo
> 
> Am 04.01.22 um 12:27 schrieb Steffen Weinreich:
> > Hi Pablo,
> >
> > Am 31.12.21 um 14:39 schrieb Pablo Neira Ayuso:
> >>> Could you give a try to this kernel patch?
> >> Wrong patch, attaching again.
> > Yes, that patch fixes the issue.
> 
> Meanwhile I tried that patch on a 4.19 Kernel. Since the struct
> nft_pktinfo pkt does not have a member fragoff the patch does not work
> on 4.19

You can substitute it with 'pkt->xt.fragoff'.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: nftables stateless NAT in raw table mangles fragmented UDP packets
  2022-01-04 18:41         ` Florian Westphal
@ 2022-01-04 19:41           ` Steffen Weinreich
  0 siblings, 0 replies; 9+ messages in thread
From: Steffen Weinreich @ 2022-01-04 19:41 UTC (permalink / raw)
  To: Florian Westphal; +Cc: Pablo Neira Ayuso, netfilter

Hi Florian,

> You can substitute it with 'pkt->xt.fragoff'.

Many thank for the prompt hint! Using this on 4.19 get the kernel
compiled and the issue is also gone!

cheerio

Steve


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: nftables stateless NAT in raw table mangles fragmented UDP packets
  2021-12-31 13:39   ` Pablo Neira Ayuso
  2022-01-04 11:27     ` Steffen Weinreich
@ 2022-01-24 16:49     ` Steffen Weinreich
  2022-01-25 13:00       ` Florian Westphal
  1 sibling, 1 reply; 9+ messages in thread
From: Steffen Weinreich @ 2022-01-24 16:49 UTC (permalink / raw)
  To: Pablo Neira Ayuso; +Cc: netfilter

Hi Pablo,


>> Could you give a try to this kernel patch?
>> Wrong patch, attaching again.
>> Thanks for reporting.

The  patch works in our Test Envirnoment for the last 3 Weeks without a
problem.

How do we get the patch into to the Mainline Kernel, so that we do not
need a separate kernel package for these maschines?


cheerio

Steve


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: nftables stateless NAT in raw table mangles fragmented UDP packets
  2022-01-24 16:49     ` Steffen Weinreich
@ 2022-01-25 13:00       ` Florian Westphal
  0 siblings, 0 replies; 9+ messages in thread
From: Florian Westphal @ 2022-01-25 13:00 UTC (permalink / raw)
  To: Steffen Weinreich; +Cc: Pablo Neira Ayuso, netfilter

Steffen Weinreich <steve@weinreich.org> wrote:
> How do we get the patch into to the Mainline Kernel, so that we do not
> need a separate kernel package for these maschines?

Its already in mainline so it should appear in the next -stable releases
as well.

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2022-01-25 13:00 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-31 12:02 nftables stateless NAT in raw table mangles fragmented UDP packets Steffen Weinreich
2021-12-31 13:37 ` Pablo Neira Ayuso
2021-12-31 13:39   ` Pablo Neira Ayuso
2022-01-04 11:27     ` Steffen Weinreich
2022-01-04 18:38       ` Steffen Weinreich
2022-01-04 18:41         ` Florian Westphal
2022-01-04 19:41           ` Steffen Weinreich
2022-01-24 16:49     ` Steffen Weinreich
2022-01-25 13:00       ` Florian Westphal

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.