Skip to contentSkip to conversation

netfilter: nf_nat: fix crash in nf_nat_csum

PATCH In review Julian Anastasov 2 participants 5 messages May 29, 2011 – Jun 8, 2011

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 netfilter: nf_nat: fix crash in nf_nat_csum

Fix crash in nf_nat_csum when mangling packets
in OUTPUT hook where skb->dev is not defined, it is set later before POSTROUTING. Problem happens for CHECKSUM_NONE. We can check device from rt but using CHECKSUM_PARTIAL should be safe (skb_checksum_help).

---

net/ipv4/netfilter/nf_nat_helper.c renamed from linux/net/ipv4/netfilter/nf_nat_helper.c +1 -1
diff -urp v2.6.39/linux/net/ipv4/netfilter/nf_nat_helper.c linux/net/ipv4/netfilter/nf_nat_helper.c
@@ -160,7 +160,7 @@ static void nf_nat_csum(struct sk_buff *
 
 	if (skb->ip_summed != CHECKSUM_PARTIAL) {
 		if (!(rt->rt_flags & RTCF_LOCAL) &&
-		    skb->dev->features & NETIF_F_V4_CSUM) {
+		    (!skb->dev || skb->dev->features & NETIF_F_V4_CSUM)) {
 			skb->ip_summed = CHECKSUM_PARTIAL;
 			skb->csum_start = skb_headroom(skb) +
 					  skb_network_offset(skb) +
#1 lore raw
Quoted 6 lines · Julian Anastasov

Fix crash in nf_nat_csum when mangling packets
in OUTPUT hook where skb->dev is not defined, it is set later before POSTROUTING. Problem happens for CHECKSUM_NONE. We can check device from rt but using CHECKSUM_PARTIAL should be safe (skb_checksum_help).

We don't call helpers in LOCAL_OUT, how can this happen?

Quoted 17 lines

---

diff -urp v2.6.39/linux/net/ipv4/netfilter/nf_nat_helper.c linux/net/ipv4/netfilter/nf_nat_helper.c

net/ipv4/netfilter/nf_nat_helper.c renamed from linux/net/ipv4/netfilter/nf_nat_helper.c +1 -1
@@ -160,7 +160,7 @@ static void nf_nat_csum(struct sk_buff *
 
 	if (skb->ip_summed != CHECKSUM_PARTIAL) {
 		if (!(rt->rt_flags & RTCF_LOCAL) &&
-		    skb->dev->features & NETIF_F_V4_CSUM) {
+		    (!skb->dev || skb->dev->features & NETIF_F_V4_CSUM)) {
 			skb->ip_summed = CHECKSUM_PARTIAL;
 			skb->csum_start = skb_headroom(skb) +
 					  skb_network_offset(skb) +
#2 lore raw

Hello,

Quoted 9 lines · Patrick McHardy
Quoted 6 lines · Julian Anastasov

Fix crash in nf_nat_csum when mangling packets
in OUTPUT hook where skb->dev is not defined, it is set later before POSTROUTING. Problem happens for CHECKSUM_NONE. We can check device from rt but using CHECKSUM_PARTIAL should be safe (skb_checksum_help).

We don't call helpers in LOCAL_OUT, how can this happen?

I think, this happened with IPVS only in OUTPUT hook:
tcp_snat_handler -> ip_vs_ftp_out -> nf_nat_mangle_tcp_packet -> nf_nat_csum. This is again PASV FTP via loopback.

Quoted 5 lines
Quoted 5 lines

diff -urp v2.6.39/linux/net/ipv4/netfilter/nf_nat_helper.c linux/net/ipv4/netfilter/nf_nat_helper.c

net/ipv4/netfilter/nf_nat_helper.c renamed from linux/net/ipv4/netfilter/nf_nat_helper.c +0 -0
@@ -160,7 +160,7 @@ static void nf_nat_csum(struct sk_buff *
 
Quoted 8 lines

net/ipv4/netfilter/nf_nat_helper.c static void nf_nat_csum(struct sk_buff * · line 166

Quoted 8 lines
net/ipv4/netfilter/nf_nat_helper.c renamed from linux/net/ipv4/netfilter/nf_nat_helper.c +1 -1
 	if (skb->ip_summed != CHECKSUM_PARTIAL) {
 		if (!(rt->rt_flags & RTCF_LOCAL) &&
-		    skb->dev->features & NETIF_F_V4_CSUM) {
+		    (!skb->dev || skb->dev->features & NETIF_F_V4_CSUM)) {
 			skb->ip_summed = CHECKSUM_PARTIAL;
 			skb->csum_start = skb_headroom(skb) +
 					  skb_network_offset(skb) +

Regards

--
Julian Anastasov <[email protected]>

#3 lore raw
Quoted 13 lines · Julian Anastasov

Hello,

Quoted 8 lines · Patrick McHardy
Quoted 6 lines · Julian Anastasov

Fix crash in nf_nat_csum when mangling packets
in OUTPUT hook where skb->dev is not defined, it is set later before POSTROUTING. Problem happens for CHECKSUM_NONE. We can check device from rt but using CHECKSUM_PARTIAL should be safe (skb_checksum_help).

Quoted 5 lines
Quoted 1 line

We don't call helpers in LOCAL_OUT, how can this happen?

I think, this happened with IPVS only in OUTPUT hook:
tcp_snat_handler -> ip_vs_ftp_out -> nf_nat_mangle_tcp_packet -> nf_nat_csum. This is again PASV FTP via loopback.

I see, thanks. I'll add a comment and will apply this tommorrow.

#4 lore raw
Quoted 14 lines · Patrick McHardy
Quoted 13 lines · Julian Anastasov

Hello,

Quoted 8 lines · Patrick McHardy
Quoted 6 lines · Julian Anastasov

Fix crash in nf_nat_csum when mangling packets
in OUTPUT hook where skb->dev is not defined, it is set later before POSTROUTING. Problem happens for CHECKSUM_NONE. We can check device from rt but using CHECKSUM_PARTIAL should be safe (skb_checksum_help).

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

We don't call helpers in LOCAL_OUT, how can this happen?

I think, this happened with IPVS only in OUTPUT hook:
tcp_snat_handler -> ip_vs_ftp_out -> nf_nat_mangle_tcp_packet -> nf_nat_csum. This is again PASV FTP via loopback.

I see, thanks. I'll add a comment and will apply this tommorrow.

I must have overlooked the message, just noticed that this patch is already applied,