]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - queue-4.14/net-rose-fix-a-possible-stack-overflow.patch
Linux 4.9.167
[thirdparty/kernel/stable-queue.git] / queue-4.14 / net-rose-fix-a-possible-stack-overflow.patch
1 From foo@baz Thu Mar 28 21:57:57 CET 2019
2 From: Eric Dumazet <edumazet@google.com>
3 Date: Fri, 15 Mar 2019 10:41:14 -0700
4 Subject: net: rose: fix a possible stack overflow
5
6 From: Eric Dumazet <edumazet@google.com>
7
8 [ Upstream commit e5dcc0c3223c45c94100f05f28d8ef814db3d82c ]
9
10 rose_write_internal() uses a temp buffer of 100 bytes, but a manual
11 inspection showed that given arbitrary input, rose_create_facilities()
12 can fill up to 110 bytes.
13
14 Lets use a tailroom of 256 bytes for peace of mind, and remove
15 the bounce buffer : we can simply allocate a big enough skb
16 and adjust its length as needed.
17
18 syzbot report :
19
20 BUG: KASAN: stack-out-of-bounds in memcpy include/linux/string.h:352 [inline]
21 BUG: KASAN: stack-out-of-bounds in rose_create_facilities net/rose/rose_subr.c:521 [inline]
22 BUG: KASAN: stack-out-of-bounds in rose_write_internal+0x597/0x15d0 net/rose/rose_subr.c:116
23 Write of size 7 at addr ffff88808b1ffbef by task syz-executor.0/24854
24
25 CPU: 0 PID: 24854 Comm: syz-executor.0 Not tainted 5.0.0+ #97
26 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
27 Call Trace:
28 __dump_stack lib/dump_stack.c:77 [inline]
29 dump_stack+0x172/0x1f0 lib/dump_stack.c:113
30 print_address_description.cold+0x7c/0x20d mm/kasan/report.c:187
31 kasan_report.cold+0x1b/0x40 mm/kasan/report.c:317
32 check_memory_region_inline mm/kasan/generic.c:185 [inline]
33 check_memory_region+0x123/0x190 mm/kasan/generic.c:191
34 memcpy+0x38/0x50 mm/kasan/common.c:131
35 memcpy include/linux/string.h:352 [inline]
36 rose_create_facilities net/rose/rose_subr.c:521 [inline]
37 rose_write_internal+0x597/0x15d0 net/rose/rose_subr.c:116
38 rose_connect+0x7cb/0x1510 net/rose/af_rose.c:826
39 __sys_connect+0x266/0x330 net/socket.c:1685
40 __do_sys_connect net/socket.c:1696 [inline]
41 __se_sys_connect net/socket.c:1693 [inline]
42 __x64_sys_connect+0x73/0xb0 net/socket.c:1693
43 do_syscall_64+0x103/0x610 arch/x86/entry/common.c:290
44 entry_SYSCALL_64_after_hwframe+0x49/0xbe
45 RIP: 0033:0x458079
46 Code: ad b8 fb ff c3 66 2e 0f 1f 84 00 00 00 00 00 66 90 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 0f 83 7b b8 fb ff c3 66 2e 0f 1f 84 00 00 00 00
47 RSP: 002b:00007f47b8d9dc78 EFLAGS: 00000246 ORIG_RAX: 000000000000002a
48 RAX: ffffffffffffffda RBX: 0000000000000003 RCX: 0000000000458079
49 RDX: 000000000000001c RSI: 0000000020000040 RDI: 0000000000000004
50 RBP: 000000000073bf00 R08: 0000000000000000 R09: 0000000000000000
51 R10: 0000000000000000 R11: 0000000000000246 R12: 00007f47b8d9e6d4
52 R13: 00000000004be4a4 R14: 00000000004ceca8 R15: 00000000ffffffff
53
54 The buggy address belongs to the page:
55 page:ffffea00022c7fc0 count:0 mapcount:0 mapping:0000000000000000 index:0x0
56 flags: 0x1fffc0000000000()
57 raw: 01fffc0000000000 0000000000000000 ffffffff022c0101 0000000000000000
58 raw: 0000000000000000 0000000000000000 00000000ffffffff 0000000000000000
59 page dumped because: kasan: bad access detected
60
61 Memory state around the buggy address:
62 ffff88808b1ffa80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
63 ffff88808b1ffb00: 00 00 00 00 00 00 00 00 f1 f1 f1 f1 00 00 00 03
64 >ffff88808b1ffb80: f2 f2 00 00 00 00 00 00 00 00 00 00 00 00 04 f3
65 ^
66 ffff88808b1ffc00: f3 f3 f3 f3 00 00 00 00 00 00 00 00 00 00 00 00
67 ffff88808b1ffc80: 00 00 00 00 00 00 00 f1 f1 f1 f1 f1 f1 01 f2 01
68
69 Signed-off-by: Eric Dumazet <edumazet@google.com>
70 Reported-by: syzbot <syzkaller@googlegroups.com>
71 Signed-off-by: David S. Miller <davem@davemloft.net>
72 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
73 ---
74 net/rose/rose_subr.c | 21 ++++++++++++---------
75 1 file changed, 12 insertions(+), 9 deletions(-)
76
77 --- a/net/rose/rose_subr.c
78 +++ b/net/rose/rose_subr.c
79 @@ -105,16 +105,17 @@ void rose_write_internal(struct sock *sk
80 struct sk_buff *skb;
81 unsigned char *dptr;
82 unsigned char lci1, lci2;
83 - char buffer[100];
84 - int len, faclen = 0;
85 + int maxfaclen = 0;
86 + int len, faclen;
87 + int reserve;
88
89 - len = AX25_BPQ_HEADER_LEN + AX25_MAX_HEADER_LEN + ROSE_MIN_LEN + 1;
90 + reserve = AX25_BPQ_HEADER_LEN + AX25_MAX_HEADER_LEN + 1;
91 + len = ROSE_MIN_LEN;
92
93 switch (frametype) {
94 case ROSE_CALL_REQUEST:
95 len += 1 + ROSE_ADDR_LEN + ROSE_ADDR_LEN;
96 - faclen = rose_create_facilities(buffer, rose);
97 - len += faclen;
98 + maxfaclen = 256;
99 break;
100 case ROSE_CALL_ACCEPTED:
101 case ROSE_CLEAR_REQUEST:
102 @@ -123,15 +124,16 @@ void rose_write_internal(struct sock *sk
103 break;
104 }
105
106 - if ((skb = alloc_skb(len, GFP_ATOMIC)) == NULL)
107 + skb = alloc_skb(reserve + len + maxfaclen, GFP_ATOMIC);
108 + if (!skb)
109 return;
110
111 /*
112 * Space for AX.25 header and PID.
113 */
114 - skb_reserve(skb, AX25_BPQ_HEADER_LEN + AX25_MAX_HEADER_LEN + 1);
115 + skb_reserve(skb, reserve);
116
117 - dptr = skb_put(skb, skb_tailroom(skb));
118 + dptr = skb_put(skb, len);
119
120 lci1 = (rose->lci >> 8) & 0x0F;
121 lci2 = (rose->lci >> 0) & 0xFF;
122 @@ -146,7 +148,8 @@ void rose_write_internal(struct sock *sk
123 dptr += ROSE_ADDR_LEN;
124 memcpy(dptr, &rose->source_addr, ROSE_ADDR_LEN);
125 dptr += ROSE_ADDR_LEN;
126 - memcpy(dptr, buffer, faclen);
127 + faclen = rose_create_facilities(dptr, rose);
128 + skb_put(skb, faclen);
129 dptr += faclen;
130 break;
131