All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] netfilter: xt_socket: Restore mark from full sockets only
@ 2017-09-21 22:08 Subash Abhinov Kasiviswanathan
  2017-09-22  0:01 ` Eric Dumazet
  0 siblings, 1 reply; 3+ messages in thread
From: Subash Abhinov Kasiviswanathan @ 2017-09-21 22:08 UTC (permalink / raw)
  To: netfilter-devel, eric.dumazet; +Cc: Subash Abhinov Kasiviswanathan

An out of bounds error was detected on an ARM64 target with
Android based kernel 4.9. This occurs while trying to
restore mark on a skb from an inet request socket.

BUG: KASAN: slab-out-of-bounds in socket_match.isra.2+0xc8/0x1f0 net/netfilter/xt_socket.c:248
Read of size 4 at addr ffffffc06a8d824c by task syz-fuzzer/1532
CPU: 7 PID: 1532 Comm: syz-fuzzer Tainted: G        W  O    4.9.41+ #1
Call trace:
[<ffffff900808d2f8>] dump_backtrace+0x0/0x440 arch/arm64/kernel/traps.c:76
[<ffffff900808d760>] show_stack+0x28/0x38 arch/arm64/kernel/traps.c:226
[<ffffff90085f7dc8>] __dump_stack lib/dump_stack.c:15 [inline]
[<ffffff90085f7dc8>] dump_stack+0xe4/0x134 lib/dump_stack.c:51
[<ffffff900830f358>] print_address_description+0x68/0x258 mm/kasan/report.c:248
[<ffffff900830f770>] kasan_report_error mm/kasan/report.c:347 [inline]
[<ffffff900830f770>] kasan_report.part.2+0x228/0x2f0 mm/kasan/report.c:371
[<ffffff900830fdec>] kasan_report+0x5c/0x70 mm/kasan/report.c:372
[<ffffff900830de98>] check_memory_region_inline mm/kasan/kasan.c:308 [inline]
[<ffffff900830de98>] __asan_load4+0x88/0xa0 mm/kasan/kasan.c:740
[<ffffff90097498f8>] socket_match.isra.2+0xc8/0x1f0 net/netfilter/xt_socket.c:248
[<ffffff9009749a5c>] socket_mt4_v1_v2_v3+0x3c/0x48 net/netfilter/xt_socket.c:272
[<ffffff90097f7e4c>] ipt_do_table+0x54c/0xad8 net/ipv4/netfilter/ip_tables.c:311
[<ffffff90097fcf14>] iptable_mangle_hook+0x6c/0x220 net/ipv4/netfilter/iptable_mangle.c:90
...
Allocated by task 1532:
 save_stack_trace_tsk+0x0/0x2a0 arch/arm64/kernel/stacktrace.c:131
 save_stack_trace+0x28/0x38 arch/arm64/kernel/stacktrace.c:215
 save_stack mm/kasan/kasan.c:495 [inline]
 set_track mm/kasan/kasan.c:507 [inline]
 kasan_kmalloc+0xd8/0x188 mm/kasan/kasan.c:599
 kasan_slab_alloc+0x14/0x20 mm/kasan/kasan.c:537
 slab_post_alloc_hook mm/slab.h:417 [inline]
 slab_alloc_node mm/slub.c:2728 [inline]
 slab_alloc mm/slub.c:2736 [inline]
 kmem_cache_alloc+0x14c/0x2e8 mm/slub.c:2741
 reqsk_alloc include/net/request_sock.h:87 [inline]
 inet_reqsk_alloc+0x4c/0x238 net/ipv4/tcp_input.c:6236
 tcp_conn_request+0x2b0/0xea8 net/ipv4/tcp_input.c:6341
 tcp_v4_conn_request+0xe0/0x100 net/ipv4/tcp_ipv4.c:1256
 tcp_rcv_state_process+0x384/0x18a8 net/ipv4/tcp_input.c:5926
 tcp_v4_do_rcv+0x2f0/0x3e0 net/ipv4/tcp_ipv4.c:1430
 tcp_v4_rcv+0x1278/0x1350 net/ipv4/tcp_ipv4.c:1709
 ip_local_deliver_finish+0x174/0x3e0 net/ipv4/ip_input.c:216

v1->v2: Change socket_mt6_v1_v2_v3() as well as mentioned by Eric

Fixes: a94070000388 ("netfilter: xt_socket: prepare for TCP_NEW_SYN_RECV support")
Signed-off-by: Subash Abhinov Kasiviswanathan <subashab@codeaurora.org>
---
 net/netfilter/xt_socket.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/net/netfilter/xt_socket.c b/net/netfilter/xt_socket.c
index e75ef39..575d215 100644
--- a/net/netfilter/xt_socket.c
+++ b/net/netfilter/xt_socket.c
@@ -76,7 +76,7 @@
 			transparent = nf_sk_is_transparent(sk);
 
 		if (info->flags & XT_SOCKET_RESTORESKMARK && !wildcard &&
-		    transparent)
+		    transparent && sk_fullsock(sk))
 			pskb->mark = sk->sk_mark;
 
 		if (sk != skb->sk)
@@ -133,7 +133,7 @@
 			transparent = nf_sk_is_transparent(sk);
 
 		if (info->flags & XT_SOCKET_RESTORESKMARK && !wildcard &&
-		    transparent)
+		    transparent && sk_fullsock(sk))
 			pskb->mark = sk->sk_mark;
 
 		if (sk != skb->sk)
-- 
1.9.1


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

* Re: [PATCH v2] netfilter: xt_socket: Restore mark from full sockets only
  2017-09-21 22:08 [PATCH v2] netfilter: xt_socket: Restore mark from full sockets only Subash Abhinov Kasiviswanathan
@ 2017-09-22  0:01 ` Eric Dumazet
  2017-09-22  0:09   ` Subash Abhinov Kasiviswanathan
  0 siblings, 1 reply; 3+ messages in thread
From: Eric Dumazet @ 2017-09-22  0:01 UTC (permalink / raw)
  To: Subash Abhinov Kasiviswanathan; +Cc: netfilter-devel

On Thu, 2017-09-21 at 16:08 -0600, Subash Abhinov Kasiviswanathan wrote:
> An out of bounds error was detected on an ARM64 target with
> Android based kernel 4.9. This occurs while trying to
> restore mark on a skb from an inet request socket.
> 
> BUG: KASAN: slab-out-of-bounds in socket_match.isra.2+0xc8/0x1f0 net/netfilter/xt_socket.c:248
> Read of size 4 at addr ffffffc06a8d824c by task syz-fuzzer/1532
> CPU: 7 PID: 1532 Comm: syz-fuzzer Tainted: G        W  O    4.9.41+ #1
> Call trace:

> 
> v1->v2: Change socket_mt6_v1_v2_v3() as well as mentioned by Eric
> 
> Fixes: a94070000388 ("netfilter: xt_socket: prepare for TCP_NEW_SYN_RECV support")

When my commit was written (Mon Mar 16 21:06:17 2015 -0700), this
XT_SOCKET_RESTORESKMARK code was not there yet.


The bug was added in commit 01555e74bde5 ("netfilter: xt_socket: add
XT_SOCKET_RESTORESKMARK flag")  which came later (Mon Jun 15 18:40:43
2015 -0600)

Please put a correct Fixes: tag, thanks.


> Signed-off-by: Subash Abhinov Kasiviswanathan <subashab@codeaurora.org>
> ---
>  net/netfilter/xt_socket.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/net/netfilter/xt_socket.c b/net/netfilter/xt_socket.c
> index e75ef39..575d215 100644
> --- a/net/netfilter/xt_socket.c
> +++ b/net/netfilter/xt_socket.c
> @@ -76,7 +76,7 @@
>  			transparent = nf_sk_is_transparent(sk);
>  
>  		if (info->flags & XT_SOCKET_RESTORESKMARK && !wildcard &&
> -		    transparent)
> +		    transparent && sk_fullsock(sk))
>  			pskb->mark = sk->sk_mark;
>  
>  		if (sk != skb->sk)
> @@ -133,7 +133,7 @@
>  			transparent = nf_sk_is_transparent(sk);
>  
>  		if (info->flags & XT_SOCKET_RESTORESKMARK && !wildcard &&
> -		    transparent)
> +		    transparent && sk_fullsock(sk))
>  			pskb->mark = sk->sk_mark;
>  
>  		if (sk != skb->sk)



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

* Re: [PATCH v2] netfilter: xt_socket: Restore mark from full sockets only
  2017-09-22  0:01 ` Eric Dumazet
@ 2017-09-22  0:09   ` Subash Abhinov Kasiviswanathan
  0 siblings, 0 replies; 3+ messages in thread
From: Subash Abhinov Kasiviswanathan @ 2017-09-22  0:09 UTC (permalink / raw)
  To: Eric Dumazet; +Cc: netfilter-devel

On 2017-09-21 18:01, Eric Dumazet wrote:
> On Thu, 2017-09-21 at 16:08 -0600, Subash Abhinov Kasiviswanathan 
> wrote:
>> An out of bounds error was detected on an ARM64 target with
>> Android based kernel 4.9. This occurs while trying to
>> restore mark on a skb from an inet request socket.
>> 
>> BUG: KASAN: slab-out-of-bounds in socket_match.isra.2+0xc8/0x1f0 
>> net/netfilter/xt_socket.c:248
>> Read of size 4 at addr ffffffc06a8d824c by task syz-fuzzer/1532
>> CPU: 7 PID: 1532 Comm: syz-fuzzer Tainted: G        W  O    4.9.41+ #1
>> Call trace:
> 
>> 
>> v1->v2: Change socket_mt6_v1_v2_v3() as well as mentioned by Eric
>> 
>> Fixes: a94070000388 ("netfilter: xt_socket: prepare for 
>> TCP_NEW_SYN_RECV support")
> 
> When my commit was written (Mon Mar 16 21:06:17 2015 -0700), this
> XT_SOCKET_RESTORESKMARK code was not there yet.
> 
> 
> The bug was added in commit 01555e74bde5 ("netfilter: xt_socket: add
> XT_SOCKET_RESTORESKMARK flag")  which came later (Mon Jun 15 18:40:43
> 2015 -0600)
> 
> Please put a correct Fixes: tag, thanks.
> 

Sure, I'll update that in v3.

-- 
Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a 
Linux Foundation Collaborative Project

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

end of thread, other threads:[~2017-09-22  0:09 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-09-21 22:08 [PATCH v2] netfilter: xt_socket: Restore mark from full sockets only Subash Abhinov Kasiviswanathan
2017-09-22  0:01 ` Eric Dumazet
2017-09-22  0:09   ` Subash Abhinov Kasiviswanathan

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.