netfilter: guard option walkers against 1-byte tail reads
Subsystems (2)
PATCH 1/1 netfilter: guard option walkers against 1-byte tail reads
When the last byte of options is a non-single-byte option kind, walkers that advance with i += op[i + 1] ? : 1 can read op[i + 1] past the end of the option area.
Add an explicit i == optlen - 1 check before dereferencing op[i + 1] in xt_tcpudp and xt_dccp option walkers.
--- net/netfilter/xt_dccp.c | 4 ++-- net/netfilter/xt_tcpudp.c | 6 ++++-- 2 files changed, 5 insertions(+), 4 deletions(-)
net/netfilter/xt_dccp.c +2 -2
@@ -62,10 +62,10 @@ dccp_find_option(u_int8_t option,return true; } -if (op[i] <2 ) +if (op[i] <2 || i == optlen -1 ) i++;else - i += op[i+1 ]?:1 ; + i += op[i +1 ] ? :1 ; }spin_unlock_bh (&dccp_buflock);
net/netfilter/xt_tcpudp.c +4 -2
@@ -59,8 +59,10 @@ tcp_find_option(u_int8_t option,for (i =0 ; i < optlen; ) {if (op[i] == option)return !invert; -if (op[i] <2 ) i++; -else i += op[i+1 ]?:1 ; +if (op[i] <2 || i == optlen -1 ) + i++; +else + i += op[i +1 ] ? :1 ; }return invert;
Signature · 1 line
2.43.0
Florian Westphal
maintainerQuoted 6 lines · David Dull
When the last byte of options is a non-single-byte option kind, walkers that advance with i += op[i + 1] ? : 1 can read op[i + 1] past the end of the option area.
Add an explicit i == optlen - 1 check before dereferencing op[i + 1] in
xt_tcpudpandxt_dccpoption walkers.
PATCH v2 1/1 netfilter: guard option walkers against 1-byte tail reads
In reply to David DullWhen the last byte of options is a non-single-byte option kind, walkers that advance with i += op[i + 1] ? : 1 can read op[i + 1] past the end of the option area.
Add an explicit i == optlen - 1 check before dereferencing op[i + 1] in xt_tcpudp and xt_dccp option walkers.
--- net/netfilter/xt_dccp.c | 4 ++-- net/netfilter/xt_tcpudp.c | 6 ++++-- 2 files changed, 5 insertions(+), 4 deletions(-)
net/netfilter/xt_dccp.c +2 -2
@@ -62,10 +62,10 @@ dccp_find_option(u_int8_t option,return true; } -if (op[i] <2 ) +if (op[i] <2 || i == optlen -1 ) i++;else - i += op[i+1 ]?:1 ; + i += op[i +1 ] ? :1 ; }spin_unlock_bh (&dccp_buflock);
net/netfilter/xt_tcpudp.c +4 -2
@@ -59,8 +59,10 @@ tcp_find_option(u_int8_t option,for (i =0 ; i < optlen; ) {if (op[i] == option)return !invert; -if (op[i] <2 ) i++; -else i += op[i+1 ]?:1 ; +if (op[i] <2 || i == optlen -1 ) + i++; +else + i += op[i +1 ] ? :1 ; }return invert;
Signature · 1 line
2.43.0
Pablo Neira Ayuso
maintainerQuoted 21 lines · David Dull
When the last byte of options is a non-single-byte option kind, walkers that advance with i += op[i + 1] ? : 1 can read op[i + 1] past the end of the option area.
Add an explicit i == optlen - 1 check before dereferencing op[i + 1] in
xt_tcpudpandxt_dccpoption walkers.Fixes 2e4e6a17af35 ("[NETFILTER] x_tables: Abstraction layer for {ip,ip6,arp}_tables")Signed-off-by David Dull <[email protected]>--- net/netfilter/xt_dccp.c | 4 ++-- net/netfilter/xt_tcpudp.c | 6 ++++-- 2 files changed, 5 insertions(+), 4 deletions(-)net/netfilter/xt_dccp.c +0
-0
net/netfilter/xt_dccp.c dccp_find_option(u_int8_t option, · line 69
Quoted 10 lines
net/netfilter/xt_dccp.c +2
-2@@ -62,10 +62,10 @@ dccp_find_option(u_int8_t option,return true; } -if (op[i] <2 ) +if (op[i] <2 || i == optlen -1 ) i++;else - i += op[i+1 ]?:1 ; + i += op[i +1 ] ? :1 ; }
To improve this area, I'd suggest:
if (op[i] < 2) {
i++;
continue;
}
if (i + 1 >= optlen)
break;
i += op[i + 1] ? : 1;}
PATCH v3 1/1 netfilter: guard option walkers against 1-byte tail reads
In reply to David DullWhen the last byte of options is a non-single-byte option kind, walkers that advance with i += op[i + 1] ? : 1 can read op[i + 1] past the end of the option area.
Handle single-byte options first, then check that a length byte is still available before reading op[i + 1] in xt_tcpudp and xt_dccp option walkers.
--- net/netfilter/xt_dccp.c | 8 ++++++-- net/netfilter/xt_tcpudp.c | 8 ++++++-- 2 files changed, 12 insertions(+), 4 deletions(-)
net/netfilter/xt_dccp.c +7 -2
@@ -62,10 +62,14 @@ dccp_find_option(u_int8_t option,return true; } -if (op[i] <2 || i == optlen -1 ) +if (op[i] <2 ) { i++; -else +continue ; + } + +if (i +1 >= optlen) +break ; + i += op[i +1 ] ? :1 ; }
spin_unlock_bh(&dccp_buflock);
net/netfilter/xt_tcpudp.c +7 -2
@@ -59,10 +59,14 @@ tcp_find_option(u_int8_t option,for (i =0 ; i < optlen; ) {if (op[i] == option)return !invert; -if (op[i] <2 || i == optlen -1 ) +if (op[i] <2 ) { i++; -else +continue ; + } + +if (i +1 >= optlen) +break ; + i += op[i +1 ] ? :1 ; }
return invert;
Signature · 1 line
2.43.0
Pablo Neira Ayuso
maintainerQuoted 25 lines · David Dull
When the last byte of options is a non-single-byte option kind, walkers that advance with i += op[i + 1] ? : 1 can read op[i + 1] past the end of the option area.
Handle single-byte options first, then check that a length byte is still available before reading op[i + 1] in
xt_tcpudpandxt_dccpoption walkers.Fixes 2e4e6a17af35 ("[NETFILTER] x_tables: Abstraction layer for {ip,ip6,arp}_tables")Signed-off-by David Dull <[email protected]>--- net/netfilter/xt_dccp.c | 8 ++++++-- net/netfilter/xt_tcpudp.c | 8 ++++++-- 2 files changed, 12 insertions(+), 4 deletions(-)net/netfilter/xt_dccp.c +0
-1@@ -62,10 +62,14 @@ dccp_find_option(u_int8_t option,return true; } -if (op[i] <2 || i == optlen -1 )
net/netfilter/xt_dccp.c dccp_find_option(u_int8_t option, · line 73
Quoted 10 lines
net/netfilter/xt_dccp.c +7
-1+if (op[i] <2 ) { i++; - else +continue ; + } + +if (i +1 >= optlen) +break ; + i += op[i +1 ] ? :1 ;
This indent is wrong, I posted this patch:
https://patchwork.ozlabs.org/project/netfilter-devel/patch/[email protected]/