Re: [PATCH net] sctp: sctp_sockaddr_af must check minimal addr length for AF_INET6

2018-04-10 Thread Marcelo Ricardo Leitner
On Sun, Apr 08, 2018 at 07:52:08AM -0700, Eric Dumazet wrote:
> Check must happen before call to ipv6_addr_v4mapped()

Please don't forget to also Cc linux-s...@vger.kernel.org on sctp
patches.

Thanks!


Re: [PATCH net] sctp: sctp_sockaddr_af must check minimal addr length for AF_INET6

2018-04-08 Thread David Miller
From: Eric Dumazet 
Date: Sun,  8 Apr 2018 07:52:08 -0700

> Check must happen before call to ipv6_addr_v4mapped()
> 
> syzbot report was :
 ...
> Signed-off-by: Eric Dumazet 
> Cc: Vlad Yasevich 
> Cc: Neil Horman 
> Reported-by: syzbot 

Applied and queued up for -stable, thanks Eric.


[PATCH net] sctp: sctp_sockaddr_af must check minimal addr length for AF_INET6

2018-04-08 Thread Eric Dumazet
Check must happen before call to ipv6_addr_v4mapped()

syzbot report was :

BUG: KMSAN: uninit-value in sctp_sockaddr_af net/sctp/socket.c:359 [inline]
BUG: KMSAN: uninit-value in sctp_do_bind+0x60f/0xdc0 net/sctp/socket.c:384
CPU: 0 PID: 3576 Comm: syzkaller968804 Not tainted 4.16.0+ #82
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 
01/01/2011
Call Trace:
 __dump_stack lib/dump_stack.c:17 [inline]
 dump_stack+0x185/0x1d0 lib/dump_stack.c:53
 kmsan_report+0x142/0x240 mm/kmsan/kmsan.c:1067
 __msan_warning_32+0x6c/0xb0 mm/kmsan/kmsan_instr.c:676
 sctp_sockaddr_af net/sctp/socket.c:359 [inline]
 sctp_do_bind+0x60f/0xdc0 net/sctp/socket.c:384
 sctp_bind+0x149/0x190 net/sctp/socket.c:332
 inet6_bind+0x1fd/0x1820 net/ipv6/af_inet6.c:293
 SYSC_bind+0x3f2/0x4b0 net/socket.c:1474
 SyS_bind+0x54/0x80 net/socket.c:1460
 do_syscall_64+0x309/0x430 arch/x86/entry/common.c:287
 entry_SYSCALL_64_after_hwframe+0x3d/0xa2
RIP: 0033:0x43fd49
RSP: 002b:7ffe99df3d28 EFLAGS: 0213 ORIG_RAX: 0031
RAX: ffda RBX: 004002c8 RCX: 0043fd49
RDX: 0010 RSI: 2000 RDI: 0003
RBP: 006ca018 R08: 004002c8 R09: 004002c8
R10: 004002c8 R11: 0213 R12: 00401670
R13: 00401700 R14:  R15: 

Local variable description: address@SYSC_bind
Variable was created at:
 SYSC_bind+0x6f/0x4b0 net/socket.c:1461
 SyS_bind+0x54/0x80 net/socket.c:1460

Signed-off-by: Eric Dumazet 
Cc: Vlad Yasevich 
Cc: Neil Horman 
Reported-by: syzbot 
---
 net/sctp/socket.c | 13 -
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/net/sctp/socket.c b/net/sctp/socket.c
index 
7a10ae3c3d8293abecd955ff6a5a19e60dcc6f95..eb712df7156eda7124cd88b4034359b088c2c475
 100644
--- a/net/sctp/socket.c
+++ b/net/sctp/socket.c
@@ -357,11 +357,14 @@ static struct sctp_af *sctp_sockaddr_af(struct sctp_sock 
*opt,
if (!opt->pf->af_supported(addr->sa.sa_family, opt))
return NULL;
 
-   /* V4 mapped address are really of AF_INET family */
-   if (addr->sa.sa_family == AF_INET6 &&
-   ipv6_addr_v4mapped(&addr->v6.sin6_addr) &&
-   !opt->pf->af_supported(AF_INET, opt))
-   return NULL;
+   if (addr->sa.sa_family == AF_INET6) {
+   if (len < SIN6_LEN_RFC2133)
+   return NULL;
+   /* V4 mapped address are really of AF_INET family */
+   if (ipv6_addr_v4mapped(&addr->v6.sin6_addr) &&
+   !opt->pf->af_supported(AF_INET, opt))
+   return NULL;
+   }
 
/* If we get this far, af is valid. */
af = sctp_get_af_specific(addr->sa.sa_family);
-- 
2.17.0.484.g0c8726318c-goog