Skip to contentSkip to conversation

libxt_sctp: fix array out of range in print_chunk

PATCH Superseded Nicolas Dichtel 2 participants 4 messages Nov 10, 2017 – Nov 13, 2017 netfilter

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libxt_sctp: fix array out of range in print_chunk

From: huaibin Wang <[email protected]>

For chunk type ASCONF, ASCONF_ACK and FORWARD_TSN, sctp_chunk_names[].chunk_type is not equal to the corresponding index in sctp_chunk_names[]. Using this field leads to a segmentation fault (index out of range).

Example

$ iptables -A INPUT -p sctp --chunk-type all ASCONF,ASCONF_ACK,FORWARD_TSN -j ACCEPT
$ iptables -L
Chain INPUT (policy ACCEPT)
target     prot opt source               destination
Segmentation fault
---
 extensions/libxt_sctp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
extensions/libxt_sctp.c +1 -1
index df1936be8b83..140de2653b1e 100644
@@ -370,7 +370,7 @@ print_chunk(uint32_t chunknum, int numeric)
 
 		for (i = 0; i < ARRAY_SIZE(sctp_chunk_names); ++i)
 			if (sctp_chunk_names[i].chunk_type == chunknum)
-				printf("%s", sctp_chunk_names[chunknum].name);
+				printf("%s", sctp_chunk_names[i].name);
 	}
 }
 
Signature · 1 line
2.13.2
#1 lore raw

Hi Nicolas,

Quoted 24 lines · Nicolas Dichtel

From: huaibin Wang <[email protected]>

For chunk type ASCONF, ASCONF_ACK and FORWARD_TSN, sctp_chunk_names[].chunk_type is not equal to the corresponding index in sctp_chunk_names[]. Using this field leads to a segmentation fault (index out of range).

Example

$ iptables -A INPUT -p sctp --chunk-type all ASCONF,ASCONF_ACK,FORWARD_TSN -j ACCEPT
$ iptables -L
Chain INPUT (policy ACCEPT)
target     prot opt source               destination
Segmentation fault
---
 extensions/libxt_sctp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
extensions/libxt_sctp.c +0 -0
index df1936be8b83..140de2653b1e 100644

extensions/libxt_sctp.c print_chunk(uint32_t chunknum, int numeric) · line 373

Quoted 5 lines
extensions/libxt_sctp.c +1 -1
@@ -370,7 +370,7 @@ print_chunk(uint32_t chunknum, int numeric)
 
 		for (i = 0; i < ARRAY_SIZE(sctp_chunk_names); ++i)
 			if (sctp_chunk_names[i].chunk_type == chunknum)
-				printf("%s", sctp_chunk_names[chunknum].name);
+				printf("%s", sctp_chunk_names[i].name);

Can we get a test for iptables/extensions/libxt_sctp.t ?

Thanks!

#2 lore raw

PATCH v2 1/1 libxt_sctp: fix array out of range in print_chunk

From: huaibin Wang <[email protected]>

For chunk type ASCONF, ASCONF_ACK and FORWARD_TSN, sctp_chunk_names[].chunk_type is not equal to the corresponding index in sctp_chunk_names[]. Using this field leads to a segmentation fault (index out of range).

Example

$ iptables -A INPUT -p sctp --chunk-type all ASCONF,ASCONF_ACK,FORWARD_TSN -j ACCEPT
$ iptables -L
Chain INPUT (policy ACCEPT)
target     prot opt source               destination
Segmentation fault

---

v1 -> v2:
uncomment corresponding tests

 extensions/libxt_sctp.c | 2 +-
 extensions/libxt_sctp.t | 9 +++------
 2 files changed, 4 insertions(+), 7 deletions(-)
extensions/libxt_sctp.c +1 -1
index df1936be8b83..140de2653b1e 100644
@@ -370,7 +370,7 @@ print_chunk(uint32_t chunknum, int numeric)
 
 		for (i = 0; i < ARRAY_SIZE(sctp_chunk_names); ++i)
 			if (sctp_chunk_names[i].chunk_type == chunknum)
-				printf("%s", sctp_chunk_names[chunknum].name);
+				printf("%s", sctp_chunk_names[i].name);
 	}
 }
 
extensions/libxt_sctp.t +3 -6
index 2f75e2a68e8e..4016e4fb1880 100644
@@ -23,10 +23,7 @@
 -p sctp -m sctp --chunk-types all COOKIE_ACK;=;OK
 -p sctp -m sctp --chunk-types all ECN_ECNE;=;OK
 -p sctp -m sctp --chunk-types all ECN_CWR;=;OK
-# ERROR: iptables-save segfaults: iptables -A INPUT -p sctp -m sctp --chunk-types all ASCONF
-# -p sctp -m sctp --chunk-types all ASCONF;=;OK
-# ERROR: iptables-save segfaults: iptables -A INPUT -p sctp -m sctp --chunk-types all ASCONF_ACK
-# -p sctp -m sctp --chunk-types all ASCONF_ACK;=;OK
-# ERROR: iptables-save segfaults: iptables -A INPUT -p sctp -m sctp --chunk-types all FORWARD_TSN
-# -p sctp -m sctp --chunk-types all FORWARD_TSN;=;OK
+-p sctp -m sctp --chunk-types all ASCONF;=;OK
+-p sctp -m sctp --chunk-types all ASCONF_ACK;=;OK
+-p sctp -m sctp --chunk-types all FORWARD_TSN;=;OK
 -p sctp -m sctp --chunk-types all SHUTDOWN_COMPLETE;=;OK
Signature · 1 line
2.13.2
maintainer Applied
#3 lore raw
Quoted 6 lines · Nicolas Dichtel

From: huaibin Wang <[email protected]>

For chunk type ASCONF, ASCONF_ACK and FORWARD_TSN, sctp_chunk_names[].chunk_type is not equal to the corresponding index in sctp_chunk_names[]. Using this field leads to a segmentation fault (index out of range).

Quoted 6 lines

Example

$ iptables -A INPUT -p sctp --chunk-type all ASCONF,ASCONF_ACK,FORWARD_TSN -j ACCEPT
$ iptables -L
Chain INPUT (policy ACCEPT)
target     prot opt source               destination
Segmentation fault

Applied, thanks a lot Nicolas.