net: check both type and procotol for tcp sockets
Subsystems (3)
PATCH 1/1 net: check both type and procotol for tcp sockets
Dmitry reported the following out-of-bound access:
Call Trace: [<ffffffff816cec2e>] __asan_report_load4_noabort+0x3e/0x40 mm/kasan/report.c:294 [<ffffffff84affb14>] sock_setsockopt+0x1284/0x13d0 net/core/sock.c:880 [< inline >] SYSC_setsockopt net/socket.c:1746 [<ffffffff84aed7ee>] SyS_setsockopt+0x1fe/0x240 net/socket.c:1729 [<ffffffff85c18c76>] entry_SYSCALL_64_fastpath+0x16/0x7a
arch/x86/entry/entry_64.S:185
This is because we mistake a raw socket as a tcp socket. We should check both sk->sk_type and sk->sk_protocol to ensure it is a tcp socket.
Willem points out __skb_complete_tx_timestamp() needs to fix as well.
--- net/core/skbuff.c | 3 ++- net/core/sock.c | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-)
net/core/skbuff.c +2 -1
@@ -3643,7 +3643,8 @@ static void __skb_complete_tx_timestamp(struct sk_buff *skb, serr->ee.ee_info = tstype;if (sk->sk_tsflags &SOF_TIMESTAMPING_OPT_ID ) { serr->ee.ee_data =skb_shinfo (skb)->tskey; -if (sk->sk_protocol ==IPPROTO_TCP ) +if (sk->sk_protocol ==IPPROTO_TCP && + sk->sk_type ==SOCK_STREAM ) serr->ee.ee_data -= sk->sk_tskey; }
net/core/sock.c +2 -1
@@ -872,7 +872,8 @@ int sock_setsockopt(struct socket *sock, int level, int optname,if (val &SOF_TIMESTAMPING_OPT_ID && !(sk->sk_tsflags &SOF_TIMESTAMPING_OPT_ID )) { -if (sk->sk_protocol ==IPPROTO_TCP ) { +if (sk->sk_protocol ==IPPROTO_TCP && + sk->sk_type ==SOCK_STREAM ) {if (sk->sk_state !=TCP_ESTABLISHED ) { ret = -EINVAL ;break ;
Signature · 1 line
1.8.3.1
Quoted 15 lines · Cong Wang
Dmitry reported the following out-of-bound access:
Call Trace: [<ffffffff816cec2e>] __asan_report_load4_noabort+0x3e/0x40 mm/kasan/report.c:294 [<ffffffff84affb14>] sock_setsockopt+0x1284/0x13d0 net/core/sock.c:880 [< inline >] SYSC_setsockopt net/socket.c:1746 [<ffffffff84aed7ee>] SyS_setsockopt+0x1fe/0x240 net/socket.c:1729 [<ffffffff85c18c76>] entry_SYSCALL_64_fastpath+0x16/0x7a
arch/x86/entry/entry_64.S:185This is because we mistake a raw socket as a tcp socket. We should check both
sk->sk_typeandsk->sk_protocolto ensure it is a tcp socket.
Quoted 6 lines
Willem points out
__skb_complete_tx_timestamp()needs to fix as well.Reported-by Dmitry Vyukov <[email protected]>Cc Willem de Bruijn <[email protected]>Cc Eric Dumazet <[email protected]>Signed-off-by Cong Wang <[email protected]>
Thanks for fixing both cases at once.
David Miller
maintainerFrom: Cong Wang <[email protected]>
Date: Wed, 16 Dec 2015 23:39:04 -0800
Quoted 15 lines
Dmitry reported the following out-of-bound access:
Call Trace: [<ffffffff816cec2e>] __asan_report_load4_noabort+0x3e/0x40 mm/kasan/report.c:294 [<ffffffff84affb14>] sock_setsockopt+0x1284/0x13d0 net/core/sock.c:880 [< inline >] SYSC_setsockopt net/socket.c:1746 [<ffffffff84aed7ee>] SyS_setsockopt+0x1fe/0x240 net/socket.c:1729 [<ffffffff85c18c76>] entry_SYSCALL_64_fastpath+0x16/0x7a
arch/x86/entry/entry_64.S:185This is because we mistake a raw socket as a tcp socket. We should check both
sk->sk_typeandsk->sk_protocolto ensure it is a tcp socket.
Quoted 6 lines
Willem points out
__skb_complete_tx_timestamp()needs to fix as well.Reported-by Dmitry Vyukov <[email protected]>Cc Willem de Bruijn <[email protected]>Cc Eric Dumazet <[email protected]>Signed-off-by Cong Wang <[email protected]>
Applied and queued up for -stable, thanks.