net: better validate user provided tunnel names
Subsystems (5)
cover net: better validate user provided tunnel names
This series changes dev_valid_name() to not attempt reading a possibly too long user-provided device name, then use this helper in five different tunnel providers.
Eric Dumazet (6):
net: fool proof dev_valid_name()
ip_tunnel: better validate user provided tunnel names
ipv6: sit: better validate user provided tunnel names
ip6_gre: better validate user provided tunnel names
ip6_tunnel: better validate user provided tunnel names
vti6: better validate user provided tunnel names
net/core/dev.c | 2 +- net/ipv4/ip_tunnel.c | 11 ++++++----- net/ipv6/ip6_gre.c | 8 +++++--- net/ipv6/ip6_tunnel.c | 11 +++++++---- net/ipv6/ip6_vti.c | 7 +++++-- net/ipv6/sit.c | 8 +++++--- 6 files changed, 29 insertions(+), 18 deletions(-)
Signature · 1 line
2.17.0.484.g0c8726318c-goog
PATCH 1/6 net: fool proof dev_valid_name()
We want to use dev_valid_name() to validate tunnel names, so better use strnlen(name, IFNAMSIZ) than strlen(name) to make sure to not upset KASAN.
--- net/core/dev.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/core/dev.c +1 -1
@@ -1027,7 +1027,7 @@ bool dev_valid_name(const char *name) {if (*name =='\0' )return false; -if (strlen (name) >=IFNAMSIZ ) +if (strnlen (name,IFNAMSIZ ) ==IFNAMSIZ )return false;if (!strcmp (name,"." ) || !strcmp (name,".." ))return false;
Signature · 1 line
2.17.0.484.g0c8726318c-goog
PATCH 2/6 ip_tunnel: better validate user provided tunnel names
In reply to Eric DumazetUse dev_valid_name() to make sure user does not provide illegal device name.
syzbot caught the following bug :
BUG: KASAN: stack-out-of-bounds in strlcpy include/linux/string.h:300 [inline] BUG: KASAN: stack-out-of-bounds in __ip_tunnel_create+0xca/0x6b0 net/ipv4/ip_tunnel.c:257 Write of size 20 at addr ffff8801ac79f810 by task syzkaller268107/4482 CPU: 0 PID: 4482 Comm: syzkaller268107 Not tainted 4.16.0+ #1 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+0x1b9/0x29f lib/dump_stack.c:53 print_address_description+0x6c/0x20b mm/kasan/report.c:256 kasan_report_error mm/kasan/report.c:354 [inline] kasan_report.cold.7+0xac/0x2f5 mm/kasan/report.c:412 check_memory_region_inline mm/kasan/kasan.c:260 [inline] check_memory_region+0x13e/0x1b0 mm/kasan/kasan.c:267 memcpy+0x37/0x50 mm/kasan/kasan.c:303 strlcpy include/linux/string.h:300 [inline] __ip_tunnel_create+0xca/0x6b0 net/ipv4/ip_tunnel.c:257 ip_tunnel_create net/ipv4/ip_tunnel.c:352 [inline] ip_tunnel_ioctl+0x818/0xd40 net/ipv4/ip_tunnel.c:861 ipip_tunnel_ioctl+0x1c5/0x420 net/ipv4/ipip.c:350 dev_ifsioc+0x43e/0xb90 net/core/dev_ioctl.c:334 dev_ioctl+0x69a/0xcc0 net/core/dev_ioctl.c:525 sock_ioctl+0x47e/0x680 net/socket.c:1015 vfs_ioctl fs/ioctl.c:46 [inline] file_ioctl fs/ioctl.c:500 [inline] do_vfs_ioctl+0x1cf/0x1650 fs/ioctl.c:684 ksys_ioctl+0xa9/0xd0 fs/ioctl.c:701 SYSC_ioctl fs/ioctl.c:708 [inline] SyS_ioctl+0x24/0x30 fs/ioctl.c:706 do_syscall_64+0x29e/0x9d0 arch/x86/entry/common.c:287 entry_SYSCALL_64_after_hwframe+0x42/0xb7
--- net/ipv4/ip_tunnel.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
net/ipv4/ip_tunnel.c +6 -5
@@ -253,13 +253,14 @@ static struct net_device *__ip_tunnel_create(struct net *net,struct net_device *dev;char name[IFNAMSIZ ]; -if (parms->name[0 ]) + err = -E2BIG ; +if (parms->name[0 ]) { +if (!dev_valid_name (parms->name)) + goto failed;strlcpy (name, parms->name,IFNAMSIZ ); -else { -if (strlen (ops->kind) > (IFNAMSIZ -3 )) { - err = -E2BIG ; + }else { +if (strlen (ops->kind) > (IFNAMSIZ -3 )) goto failed; - }strlcpy (name, ops->kind,IFNAMSIZ );strncat (name,"%d" ,2 ); }
Signature · 1 line
2.17.0.484.g0c8726318c-goog
Re: [PATCH net 2/6] ip_tunnel: better validate user provided tunnel names
Hi,
[This is an automated email]
This commit has been processed because it contains a "Fixes:" tag, fixing commit: c54419321455 GRE: Refactor GRE tunneling code..
The bot has also determined it's probably a bug fixing patch. (score: 46.6256)
The bot has tested the following trees: v4.16, v4.15.15, v4.14.32, v4.9.92, v4.4.126.
v4.16: Build OK!
v4.15.15: Build OK!
v4.14.32: Build OK!
v4.9.92: Build OK!
v4.4.126: Build OK!
--
Thanks,
Sasha
PATCH 3/6 ipv6: sit: better validate user provided tunnel names
In reply to Eric DumazetUse dev_valid_name() to make sure user does not provide illegal device name.
syzbot caught the following bug :
BUG: KASAN: stack-out-of-bounds in strlcpy include/linux/string.h:300 [inline] BUG: KASAN: stack-out-of-bounds in ipip6_tunnel_locate+0x63b/0xaa0 net/ipv6/sit.c:254 Write of size 33 at addr ffff8801b64076d8 by task syzkaller932654/4453 CPU: 0 PID: 4453 Comm: syzkaller932654 Not tainted 4.16.0+ #1 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+0x1b9/0x29f lib/dump_stack.c:53 print_address_description+0x6c/0x20b mm/kasan/report.c:256 kasan_report_error mm/kasan/report.c:354 [inline] kasan_report.cold.7+0xac/0x2f5 mm/kasan/report.c:412 check_memory_region_inline mm/kasan/kasan.c:260 [inline] check_memory_region+0x13e/0x1b0 mm/kasan/kasan.c:267 memcpy+0x37/0x50 mm/kasan/kasan.c:303 strlcpy include/linux/string.h:300 [inline] ipip6_tunnel_locate+0x63b/0xaa0 net/ipv6/sit.c:254 ipip6_tunnel_ioctl+0xe71/0x241b net/ipv6/sit.c:1221 dev_ifsioc+0x43e/0xb90 net/core/dev_ioctl.c:334 dev_ioctl+0x69a/0xcc0 net/core/dev_ioctl.c:525 sock_ioctl+0x47e/0x680 net/socket.c:1015 vfs_ioctl fs/ioctl.c:46 [inline] file_ioctl fs/ioctl.c:500 [inline] do_vfs_ioctl+0x1cf/0x1650 fs/ioctl.c:684 ksys_ioctl+0xa9/0xd0 fs/ioctl.c:701 SYSC_ioctl fs/ioctl.c:708 [inline] SyS_ioctl+0x24/0x30 fs/ioctl.c:706 do_syscall_64+0x29e/0x9d0 arch/x86/entry/common.c:287 entry_SYSCALL_64_after_hwframe+0x42/0xb7
--- net/ipv6/sit.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
net/ipv6/sit.c +5 -3
@@ -250,11 +250,13 @@ static struct ip_tunnel *ipip6_tunnel_locate(struct net *net,if (!create) goto failed; -if (parms->name[0 ]) +if (parms->name[0 ]) { +if (!dev_valid_name (parms->name)) + goto failed;strlcpy (name, parms->name,IFNAMSIZ ); -else + }else {strcpy (name,"sit%d" ); - + } dev =alloc_netdev (sizeof (*t), name,NET_NAME_UNKNOWN , ipip6_tunnel_setup);if (!dev)
Signature · 1 line
2.17.0.484.g0c8726318c-goog
Re: [PATCH net 3/6] ipv6: sit: better validate user provided tunnel names
Hi,
[This is an automated email]
This commit has been processed because it contains a "Fixes:" tag, fixing commit: 1da177e4c3f4 Linux-2.6.12-rc2.
The bot has also determined it's probably a bug fixing patch. (score: 53.2877)
The bot has tested the following trees: v4.16, v4.15.15, v4.14.32, v4.9.92, v4.4.126.
v4.16: Build OK!
v4.15.15: Build OK!
v4.14.32: Build OK!
v4.9.92: Build OK!
v4.4.126: Build OK!
PATCH 4/6 ip6_gre: better validate user provided tunnel names
In reply to Eric DumazetUse dev_valid_name() to make sure user does not provide illegal device name.
syzbot caught the following bug :
BUG: KASAN: stack-out-of-bounds in strlcpy include/linux/string.h:300 [inline] BUG: KASAN: stack-out-of-bounds in ip6gre_tunnel_locate+0x334/0x860 net/ipv6/ip6_gre.c:339 Write of size 20 at addr ffff8801afb9f7b8 by task syzkaller851048/4466 CPU: 1 PID: 4466 Comm: syzkaller851048 Not tainted 4.16.0+ #1 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+0x1b9/0x29f lib/dump_stack.c:53 print_address_description+0x6c/0x20b mm/kasan/report.c:256 kasan_report_error mm/kasan/report.c:354 [inline] kasan_report.cold.7+0xac/0x2f5 mm/kasan/report.c:412 check_memory_region_inline mm/kasan/kasan.c:260 [inline] check_memory_region+0x13e/0x1b0 mm/kasan/kasan.c:267 memcpy+0x37/0x50 mm/kasan/kasan.c:303 strlcpy include/linux/string.h:300 [inline] ip6gre_tunnel_locate+0x334/0x860 net/ipv6/ip6_gre.c:339 ip6gre_tunnel_ioctl+0x69d/0x12e0 net/ipv6/ip6_gre.c:1195 dev_ifsioc+0x43e/0xb90 net/core/dev_ioctl.c:334 dev_ioctl+0x69a/0xcc0 net/core/dev_ioctl.c:525 sock_ioctl+0x47e/0x680 net/socket.c:1015 vfs_ioctl fs/ioctl.c:46 [inline] file_ioctl fs/ioctl.c:500 [inline] do_vfs_ioctl+0x1cf/0x1650 fs/ioctl.c:684 ksys_ioctl+0xa9/0xd0 fs/ioctl.c:701 SYSC_ioctl fs/ioctl.c:708 [inline] SyS_ioctl+0x24/0x30 fs/ioctl.c:706 do_syscall_64+0x29e/0x9d0 arch/x86/entry/common.c:287 entry_SYSCALL_64_after_hwframe+0x42/0xb7
--- net/ipv6/ip6_gre.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
net/ipv6/ip6_gre.c +5 -3
@@ -335,11 +335,13 @@ static struct ip6_tnl *ip6gre_tunnel_locate(struct net *net,if (t || !create)return t; -if (parms->name[0 ]) +if (parms->name[0 ]) { +if (!dev_valid_name (parms->name)) +return NULL ;strlcpy (name, parms->name,IFNAMSIZ ); -else + }else {strcpy (name,"ip6gre%d" ); - + } dev =alloc_netdev (sizeof (*t), name,NET_NAME_UNKNOWN , ip6gre_tunnel_setup);if (!dev)
Signature · 1 line
2.17.0.484.g0c8726318c-goog
Re: [PATCH net 4/6] ip6_gre: better validate user provided tunnel names
Hi,
[This is an automated email]
This commit has been processed because it contains a "Fixes:" tag, fixing commit: c12b395a4664 gre: Support GRE over IPv6.
The bot has also determined it's probably a bug fixing patch. (score: 52.9896)
The bot has tested the following trees: v4.16, v4.15.15, v4.14.32, v4.9.92, v4.4.126.
v4.16: Build OK!
v4.15.15: Build OK!
v4.14.32: Build OK!
v4.9.92: Build OK!
v4.4.126: Build OK!
PATCH 5/6 ip6_tunnel: better validate user provided tunnel names
In reply to Eric DumazetUse valid_name() to make sure user does not provide illegal device name.
--- net/ipv6/ip6_tunnel.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
net/ipv6/ip6_tunnel.c +7 -4
@@ -297,13 +297,16 @@ static struct ip6_tnl *ip6_tnl_create(struct net *net, struct __ip6_tnl_parm *p)struct net_device *dev;struct ip6_tnl *t;char name[IFNAMSIZ ]; -int err = -ENOMEM ; +int err = -E2BIG ; -if (p->name[0 ]) +if (p->name[0 ]) { +if (!dev_valid_name (p->name)) + goto failed;strlcpy (name, p->name,IFNAMSIZ ); -else + }else {sprintf (name,"ip6tnl%%d" ); - + } + err = -ENOMEM ; dev =alloc_netdev (sizeof (*t), name,NET_NAME_UNKNOWN , ip6_tnl_dev_setup);if (!dev)
Signature · 1 line
2.17.0.484.g0c8726318c-goog
Re: [PATCH net 5/6] ip6_tunnel: better validate user provided tunnel names
Hi,
[This is an automated email]
This commit has been processed because it contains a "Fixes:" tag, fixing commit: 1da177e4c3f4 Linux-2.6.12-rc2.
The bot has also determined it's probably a bug fixing patch. (score: 24.0820)
The bot has tested the following trees: v4.16, v4.15.15, v4.14.32, v4.9.92, v4.4.126.
v4.16: Build OK!
v4.15.15: Build OK!
v4.14.32: Build OK!
v4.9.92: Build OK!
v4.4.126: Build OK!
PATCH 6/6 vti6: better validate user provided tunnel names
In reply to Eric DumazetUse valid_name() to make sure user does not provide illegal device name.
--- net/ipv6/ip6_vti.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
net/ipv6/ip6_vti.c +5 -2
@@ -212,10 +212,13 @@ static struct ip6_tnl *vti6_tnl_create(struct net *net, struct __ip6_tnl_parm *pchar name[IFNAMSIZ ];int err; -if (p->name[0 ]) +if (p->name[0 ]) { +if (!dev_valid_name (p->name)) + goto failed;strlcpy (name, p->name,IFNAMSIZ ); -else + }else {sprintf (name,"ip6_vti%%d" ); + } dev =alloc_netdev (sizeof (*t), name,NET_NAME_UNKNOWN , vti6_dev_setup);if (!dev)
Signature · 1 line
2.17.0.484.g0c8726318c-goog
Re: [PATCH net 6/6] vti6: better validate user provided tunnel names
Hi,
[This is an automated email]
This commit has been processed because it contains a "Fixes:" tag, fixing commit: ed1efb2aefbb ipv6: Add support for IPsec virtual tunnel interfaces.
The bot has also determined it's probably a bug fixing patch. (score: 65.4654)
The bot has tested the following trees: v4.16, v4.15.15, v4.14.32, v4.9.92, v4.4.126.
v4.16: Build OK!
v4.15.15: Build OK!
v4.14.32: Build OK!
v4.9.92: Build OK!
v4.4.126: Build OK!
David Miller
maintainerFrom: Eric Dumazet <[email protected]>
Date: Thu, 5 Apr 2018 06:39:25 -0700
Quoted 3 lines
This series changes
dev_valid_name()to not attempt reading a possibly too long user-provided device name, then use this helper in five different tunnel providers.
Series applied and queued up for -stable, thanks Eric.
Reading over this series makes me wonder if we generally have an off-by-one bug for device names which are exactly IFNAMSIZ.
We validate the size using the test:
if (strlen(name) >= IFNAMSIZ) return ERROR;
and thusly after Eric's changes:
if (strnlen(name, IFNAMSIZ) == IFNAMSIZ) return ERROR;
This value computed by str{,n}len() doesn't include the trailing null byte.
So we will accept a name that has exactly IFNAMSIZ bytes long not including the trailing null.
Then we will copy IFNAMSIZ bytes, minus 1, into the device name and then tack on the trailling null byte.
So essentially we will set the final non-null byte in the string to a null byte.
Am I misreading things?
Quoted 19 lines · David Miller
From: Eric Dumazet <[email protected]>
Date: Thu, 5 Apr 2018 06:39:25 -0700Quoted 3 lines
This series changes
dev_valid_name()to not attempt reading a possibly too long user-provided device name, then use this helper in five different tunnel providers.Series applied and queued up for -stable, thanks Eric.
Reading over this series makes me wonder if we generally have an off-by-one bug for device names which are exactly IFNAMSIZ.
We validate the size using the test:
if (strlen(name) >= IFNAMSIZ) return ERROR;and thusly after Eric's changes:
Quoted 8 lines
if (strnlen(name, IFNAMSIZ) == IFNAMSIZ) return ERROR;This value computed by str{,n}len() doesn't include the trailing null byte.
So we will accept a name that has exactly IFNAMSIZ bytes long not including the trailing null.
In this case strnlen(name, IFNAMSIZ) returns IFNAMSIZ.
So (strnlen(name, IFNAMSIZ) == IFNAMSIZ) would definitely be true.
The only effect of the change is that strlen() would read 1000 bytes of a malicious string before we reached the test on the length to reject such name.
While strnlen() is guaranteed to not read more than IFNAMSIZ bytes.
Hi,
[This is an automated email]
This commit has been processed because it contains a "Fixes:" tag, fixing commit: ed1efb2aefbb ipv6: Add support for IPsec virtual tunnel interfaces.
The bot has also determined it's probably a bug fixing patch. (score: 53.6463)
The bot has tested the following trees: v4.16, v4.15.15, v4.14.32, v4.9.92, v4.4.126.
v4.16: Build OK!
v4.15.15: Build OK!
v4.14.32: Build OK!
v4.9.92: Build OK!
v4.4.126: Build OK!