Skip to contentSkip to conversation

ipvs: ip_vs_sh: ip_vs_sh_get_port: check skb_header_pointer for NULL

PATCH In review Daniel Borkmann 3 participants 4 messages Aug 6, 2013 1 message not in the archive

Subsystems (3)
lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

PATCH 1/1 ipvs: ip_vs_sh: ip_vs_sh_get_port: check skb_header_pointer for NULL

skb_header_pointer could return NULL, so check for it as we do it everywhere else in ipvs code. This fixes a coverity warning.

---
I'd consider the case of NULL quite unlikely, therefore ipvs-next should be sufficient.

 net/netfilter/ipvs/ip_vs_sh.c | 6 ++++++
 1 file changed, 6 insertions(+)
net/netfilter/ipvs/ip_vs_sh.c +6 -0
index f16c027..3588fae 100644
@@ -269,14 +269,20 @@ ip_vs_sh_get_port(const struct sk_buff *skb, struct ip_vs_iphdr *iph)
 	switch (iph->protocol) {
 	case IPPROTO_TCP:
 		th = skb_header_pointer(skb, iph->len, sizeof(_tcph), &_tcph);
+		if (unlikely(th == NULL))
+			return 0;
 		port = th->source;
 		break;
 	case IPPROTO_UDP:
 		uh = skb_header_pointer(skb, iph->len, sizeof(_udph), &_udph);
+		if (unlikely(uh == NULL))
+			return 0;
 		port = uh->source;
 		break;
 	case IPPROTO_SCTP:
 		sh = skb_header_pointer(skb, iph->len, sizeof(_sctph), &_sctph);
+		if (unlikely(sh == NULL))
+			return 0;
 		port = sh->source;
 		break;
 	default:
Signature · 1 line
1.7.11.7
maintainer
#2 lore raw
Quoted 7 lines · Daniel Borkmann

skb_header_pointer could return NULL, so check for it as we do it everywhere else in ipvs code. This fixes a coverity warning.

---
I'd consider the case of NULL quite unlikely, therefore ipvs-next should be sufficient.

Thanks, I have queued-this patch up in ipvs-next as you suggested.

Quoted 32 lines
 net/netfilter/ipvs/ip_vs_sh.c | 6 ++++++
 1 file changed, 6 insertions(+)
net/netfilter/ipvs/ip_vs_sh.c +6 -0
index f16c027..3588fae 100644
@@ -269,14 +269,20 @@ ip_vs_sh_get_port(const struct sk_buff *skb, struct ip_vs_iphdr *iph)
 	switch (iph->protocol) {
 	case IPPROTO_TCP:
 		th = skb_header_pointer(skb, iph->len, sizeof(_tcph), &_tcph);
+		if (unlikely(th == NULL))
+			return 0;
 		port = th->source;
 		break;
 	case IPPROTO_UDP:
 		uh = skb_header_pointer(skb, iph->len, sizeof(_udph), &_udph);
+		if (unlikely(uh == NULL))
+			return 0;
 		port = uh->source;
 		break;
 	case IPPROTO_SCTP:
 		sh = skb_header_pointer(skb, iph->len, sizeof(_sctph), &_sctph);
+		if (unlikely(sh == NULL))
+			return 0;
 		port = sh->source;
 		break;
 	default:
Signature · 1 line
1.7.11.7
maintainer Acked-by on v1 1/1
#3 lore raw
In reply to Daniel Borkmann

Hello,

Quoted 7 lines · Daniel Borkmann

skb_header_pointer could return NULL, so check for it as we do it everywhere else in ipvs code. This fixes a coverity warning.

---
I'd consider the case of NULL quite unlikely, therefore ipvs-next should be sufficient.

Agreed, to avoid confusion...

At the time when SH patch was submitted I ignored
it as problem because this code is part of the scheduling lookup and we already passed such skb_header_pointer() checks at top of tcp_conn_schedule().

Quoted 30 lines
 net/netfilter/ipvs/ip_vs_sh.c | 6 ++++++
 1 file changed, 6 insertions(+)
net/netfilter/ipvs/ip_vs_sh.c +6 -0
index f16c027..3588fae 100644
@@ -269,14 +269,20 @@ ip_vs_sh_get_port(const struct sk_buff *skb, struct ip_vs_iphdr *iph)
 	switch (iph->protocol) {
 	case IPPROTO_TCP:
 		th = skb_header_pointer(skb, iph->len, sizeof(_tcph), &_tcph);
+		if (unlikely(th == NULL))
+			return 0;
 		port = th->source;
 		break;
 	case IPPROTO_UDP:
 		uh = skb_header_pointer(skb, iph->len, sizeof(_udph), &_udph);
+		if (unlikely(uh == NULL))
+			return 0;
 		port = uh->source;
 		break;
 	case IPPROTO_SCTP:
 		sh = skb_header_pointer(skb, iph->len, sizeof(_sctph), &_sctph);
+		if (unlikely(sh == NULL))
+			return 0;
 		port = sh->source;
 		break;
 	default:
Signature · 1 line
1.7.11.7

Regards

--
Julian Anastasov <[email protected]>

maintainer
#4 lore raw
Quoted 8 lines · Julian Anastasov

Hello,

Quoted 3 lines · Daniel Borkmann

skb_header_pointer could return NULL, so check for it as we do it everywhere else in ipvs code. This fixes a coverity warning.

Quoted 8 lines
Quoted 4 lines

---
I'd consider the case of NULL quite unlikely, therefore ipvs-next should be sufficient.

Agreed, to avoid confusion...

Thanks, I have added your ack and forcibly re-pushed the change into ipvs-next.

Quoted 41 lines

At the time when SH patch was submitted I ignored
it as problem because this code is part of the scheduling lookup and we already passed such skb_header_pointer() checks at top of tcp_conn_schedule().

Quoted 30 lines
 net/netfilter/ipvs/ip_vs_sh.c | 6 ++++++
 1 file changed, 6 insertions(+)
net/netfilter/ipvs/ip_vs_sh.c +6 -0
index f16c027..3588fae 100644
@@ -269,14 +269,20 @@ ip_vs_sh_get_port(const struct sk_buff *skb, struct ip_vs_iphdr *iph)
 	switch (iph->protocol) {
 	case IPPROTO_TCP:
 		th = skb_header_pointer(skb, iph->len, sizeof(_tcph), &_tcph);
+		if (unlikely(th == NULL))
+			return 0;
 		port = th->source;
 		break;
 	case IPPROTO_UDP:
 		uh = skb_header_pointer(skb, iph->len, sizeof(_udph), &_udph);
+		if (unlikely(uh == NULL))
+			return 0;
 		port = uh->source;
 		break;
 	case IPPROTO_SCTP:
 		sh = skb_header_pointer(skb, iph->len, sizeof(_sctph), &_sctph);
+		if (unlikely(sh == NULL))
+			return 0;
 		port = sh->source;
 		break;
 	default:
Signature · 1 line
1.7.11.7

Regards

--
Julian Anastasov <[email protected]>