Alexander Potapenko
62fe0521fb
net: don't call strlen() on the user buffer in packet_bind_spkt()
...
[ Upstream commit 540e2894f7905538740aaf122bd8e0548e1c34a4 ]
KMSAN (KernelMemorySanitizer, a new error detection tool) reports use of
uninitialized memory in packet_bind_spkt():
Acked-by: Eric Dumazet <edumazet@google.com>
==================================================================
BUG: KMSAN: use of unitialized memory
CPU: 0 PID: 1074 Comm: packet Not tainted 4.8.0-rc6+ #1891
Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS Bochs
01/01/2011
0000000000000000 ffff88006b6dfc08 ffffffff82559ae8 ffff88006b6dfb48
ffffffff818a7c91 ffffffff85b9c870 0000000000000092 ffffffff85b9c550
0000000000000000 0000000000000092 00000000ec400911 0000000000000002
Call Trace:
[< inline >] __dump_stack lib/dump_stack.c:15
[<ffffffff82559ae8>] dump_stack+0x238/0x290 lib/dump_stack.c:51
[<ffffffff818a6626>] kmsan_report+0x276/0x2e0 mm/kmsan/kmsan.c:1003
[<ffffffff818a783b>] __msan_warning+0x5b/0xb0
mm/kmsan/kmsan_instr.c:424
[< inline >] strlen lib/string.c:484
[<ffffffff8259b58d>] strlcpy+0x9d/0x200 lib/string.c:144
[<ffffffff84b2eca4>] packet_bind_spkt+0x144/0x230
net/packet/af_packet.c:3132
[<ffffffff84242e4d>] SYSC_bind+0x40d/0x5f0 net/socket.c:1370
[<ffffffff84242a22>] SyS_bind+0x82/0xa0 net/socket.c:1356
[<ffffffff8515991b>] entry_SYSCALL_64_fastpath+0x13/0x8f
arch/x86/entry/entry_64.o:?
chained origin: 00000000eba00911
[<ffffffff810bb787>] save_stack_trace+0x27/0x50
arch/x86/kernel/stacktrace.c:67
[< inline >] kmsan_save_stack_with_flags mm/kmsan/kmsan.c:322
[< inline >] kmsan_save_stack mm/kmsan/kmsan.c:334
[<ffffffff818a59f8>] kmsan_internal_chain_origin+0x118/0x1e0
mm/kmsan/kmsan.c:527
[<ffffffff818a7773>] __msan_set_alloca_origin4+0xc3/0x130
mm/kmsan/kmsan_instr.c:380
[<ffffffff84242b69>] SYSC_bind+0x129/0x5f0 net/socket.c:1356
[<ffffffff84242a22>] SyS_bind+0x82/0xa0 net/socket.c:1356
[<ffffffff8515991b>] entry_SYSCALL_64_fastpath+0x13/0x8f
arch/x86/entry/entry_64.o:?
origin description: ----address@SYSC_bind (origin=00000000eb400911)
==================================================================
(the line numbers are relative to 4.8-rc6, but the bug persists
upstream)
, when I run the following program as root:
=====================================
#include <string.h>
#include <sys/socket.h>
#include <netpacket/packet.h>
#include <net/ethernet.h>
int main() {
struct sockaddr addr;
memset(&addr, 0xff, sizeof(addr));
addr.sa_family = AF_PACKET;
int fd = socket(PF_PACKET, SOCK_PACKET, htons(ETH_P_ALL));
bind(fd, &addr, sizeof(addr));
return 0;
}
=====================================
This happens because addr.sa_data copied from the userspace is not
zero-terminated, and copying it with strlcpy() in packet_bind_spkt()
results in calling strlen() on the kernel copy of that non-terminated
buffer.
Signed-off-by: Alexander Potapenko <glider@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-03-22 12:43:32 +01:00
..
2016-09-19 20:19:34 +02:00
2016-09-23 13:47:44 -04:00
2016-10-20 14:32:22 -04:00
2016-09-10 21:19:10 -07:00
2016-09-10 21:19:10 -07:00
2017-02-04 09:47:09 +01:00
2016-12-02 10:46:59 +01:00
2016-11-22 22:50:46 +01:00
2017-03-22 12:43:32 +01:00
2016-12-05 14:48:48 -05:00
2017-02-18 15:11:40 +01:00
2017-03-12 06:41:53 +01:00
2017-02-26 11:10:50 +01:00
2016-12-03 23:54:25 -05:00
2017-03-22 12:43:32 +01:00
2016-07-05 14:08:47 -07:00
2017-02-18 15:11:43 +01:00
2017-02-18 15:11:43 +01:00
2016-10-18 10:28:18 -04:00
2016-07-08 13:23:12 +02:00
2017-03-22 12:43:32 +01:00
2017-03-22 12:43:31 +01:00
2017-02-26 11:10:51 +01:00
2017-01-19 20:18:04 +01:00
2017-02-26 11:10:50 +01:00
2017-03-22 12:43:32 +01:00
2016-09-10 23:12:53 -07:00
2016-05-29 22:33:25 -07:00
2017-02-26 11:10:50 +01:00
2017-03-15 10:02:48 +08:00
2016-09-19 20:19:34 +02:00
2017-02-04 09:47:11 +01:00
2016-10-20 11:23:08 -04:00
2017-03-12 06:41:53 +01:00
2016-06-27 15:06:18 -04:00
2016-12-05 19:43:42 -05:00
2016-07-11 02:02:03 +02:00
2017-02-04 09:47:09 +01:00
2017-03-22 12:43:32 +01:00
2016-05-17 14:11:19 -04:00
2016-12-02 13:29:26 -05:00
2016-07-13 11:53:40 -07:00
2016-10-13 08:43:17 +01:00
2017-03-22 12:43:32 +01:00
2017-02-18 15:11:44 +01:00
2016-10-12 01:51:49 -04:00
2017-03-12 06:41:52 +01:00
2016-10-19 10:58:04 -04:00
2016-12-02 14:03:20 -05:00
2017-02-04 09:47:10 +01:00
2017-01-09 08:32:23 +01:00
2017-02-14 15:25:37 -08:00
2016-09-09 18:13:30 -07:00
2016-11-30 10:58:53 +01:00
2016-06-09 23:41:03 -07:00
2016-08-17 19:36:23 -04:00
2016-08-17 19:36:23 -04:00
2017-02-26 11:10:51 +01:00
2016-10-06 09:52:23 -07:00