forked from mirrors/linux
		
	 3a4f0edbb7
			
		
	
	
		3a4f0edbb7
		
	
	
	
	
		
			
			SIOCGETSGCNT_IN6 uses a "struct sioc_sg_req6 buffer".
Unfortunately the blamed commit made hard to ensure type safety.
syzbot reported:
BUG: KASAN: stack-out-of-bounds in ip6mr_ioctl+0xba3/0xcb0 net/ipv6/ip6mr.c:1917
Read of size 16 at addr ffffc900039afb68 by task syz-executor937/5008
CPU: 1 PID: 5008 Comm: syz-executor937 Not tainted 6.4.0-rc6-syzkaller-01304-gc08afcdcf952 #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 05/27/2023
Call Trace:
<TASK>
__dump_stack lib/dump_stack.c:88 [inline]
dump_stack_lvl+0xd9/0x150 lib/dump_stack.c:106
print_address_description.constprop.0+0x2c/0x3c0 mm/kasan/report.c:351
print_report mm/kasan/report.c:462 [inline]
kasan_report+0x11c/0x130 mm/kasan/report.c:572
ip6mr_ioctl+0xba3/0xcb0 net/ipv6/ip6mr.c:1917
rawv6_ioctl+0x4e/0x1e0 net/ipv6/raw.c:1143
sock_ioctl_out net/core/sock.c:4186 [inline]
sk_ioctl+0x151/0x440 net/core/sock.c:4214
inet6_ioctl+0x1b8/0x290 net/ipv6/af_inet6.c:582
sock_do_ioctl+0xcc/0x230 net/socket.c:1189
sock_ioctl+0x1f8/0x680 net/socket.c:1306
vfs_ioctl fs/ioctl.c:51 [inline]
__do_sys_ioctl fs/ioctl.c:870 [inline]
__se_sys_ioctl fs/ioctl.c:856 [inline]
__x64_sys_ioctl+0x197/0x210 fs/ioctl.c:856
do_syscall_x64 arch/x86/entry/common.c:50 [inline]
do_syscall_64+0x39/0xb0 arch/x86/entry/common.c:80
entry_SYSCALL_64_after_hwframe+0x63/0xcd
RIP: 0033:0x7f255849bad9
Code: 28 c3 e8 2a 14 00 00 66 2e 0f 1f 84 00 00 00 00 00 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 73 01 c3 48 c7 c1 c0 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007ffd06792778 EFLAGS: 00000246 ORIG_RAX: 0000000000000010
RAX: ffffffffffffffda RBX: 0000000000000000 RCX: 00007f255849bad9
RDX: 0000000000000000 RSI: 00000000000089e1 RDI: 0000000000000003
RBP: 00007f255845fc80 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 00007f255845fd10
R13: 0000000000000000 R14: 0000000000000000 R15: 0000000000000000
</TASK>
The buggy address belongs to stack of task syz-executor937/5008
and is located at offset 40 in frame:
sk_ioctl+0x0/0x440 net/core/sock.c:4172
This frame has 2 objects:
[32, 36) 'karg'
[48, 88) 'buffer'
Fixes: e1d001fa5b ("net: ioctl: Use kernel memory on protocol ioctl callbacks")
Reported-by: syzbot <syzkaller@googlegroups.com>
Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Willem de Bruijn <willemb@google.com>
Cc: David Ahern <dsahern@kernel.org>
Cc: Kuniyuki Iwashima <kuniyu@amazon.com>
Reviewed-by: Breno Leitao <leitao@debian.org>
Link: https://lore.kernel.org/r/20230619072740.464528-1-edumazet@google.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
		
	
			
		
			
				
	
	
		
			140 lines
		
	
	
	
		
			2.9 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			140 lines
		
	
	
	
		
			2.9 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
| /* SPDX-License-Identifier: GPL-2.0 */
 | |
| #ifndef __LINUX_MROUTE6_H
 | |
| #define __LINUX_MROUTE6_H
 | |
| 
 | |
| 
 | |
| #include <linux/pim.h>
 | |
| #include <linux/skbuff.h>	/* for struct sk_buff_head */
 | |
| #include <net/net_namespace.h>
 | |
| #include <uapi/linux/mroute6.h>
 | |
| #include <linux/mroute_base.h>
 | |
| #include <linux/sockptr.h>
 | |
| #include <net/fib_rules.h>
 | |
| 
 | |
| #ifdef CONFIG_IPV6_MROUTE
 | |
| static inline int ip6_mroute_opt(int opt)
 | |
| {
 | |
| 	return (opt >= MRT6_BASE) && (opt <= MRT6_MAX);
 | |
| }
 | |
| #else
 | |
| static inline int ip6_mroute_opt(int opt)
 | |
| {
 | |
| 	return 0;
 | |
| }
 | |
| #endif
 | |
| 
 | |
| struct sock;
 | |
| 
 | |
| #ifdef CONFIG_IPV6_MROUTE
 | |
| extern int ip6_mroute_setsockopt(struct sock *, int, sockptr_t, unsigned int);
 | |
| extern int ip6_mroute_getsockopt(struct sock *, int, sockptr_t, sockptr_t);
 | |
| extern int ip6_mr_input(struct sk_buff *skb);
 | |
| extern int ip6mr_compat_ioctl(struct sock *sk, unsigned int cmd, void __user *arg);
 | |
| extern int ip6_mr_init(void);
 | |
| extern void ip6_mr_cleanup(void);
 | |
| int ip6mr_ioctl(struct sock *sk, int cmd, void *arg);
 | |
| #else
 | |
| static inline int ip6_mroute_setsockopt(struct sock *sock, int optname,
 | |
| 		sockptr_t optval, unsigned int optlen)
 | |
| {
 | |
| 	return -ENOPROTOOPT;
 | |
| }
 | |
| 
 | |
| static inline
 | |
| int ip6_mroute_getsockopt(struct sock *sock,
 | |
| 			  int optname, sockptr_t optval, sockptr_t optlen)
 | |
| {
 | |
| 	return -ENOPROTOOPT;
 | |
| }
 | |
| 
 | |
| static inline
 | |
| int ip6mr_ioctl(struct sock *sk, int cmd, void *arg)
 | |
| {
 | |
| 	return -ENOIOCTLCMD;
 | |
| }
 | |
| 
 | |
| static inline int ip6_mr_init(void)
 | |
| {
 | |
| 	return 0;
 | |
| }
 | |
| 
 | |
| static inline void ip6_mr_cleanup(void)
 | |
| {
 | |
| 	return;
 | |
| }
 | |
| #endif
 | |
| 
 | |
| #ifdef CONFIG_IPV6_MROUTE_MULTIPLE_TABLES
 | |
| bool ip6mr_rule_default(const struct fib_rule *rule);
 | |
| #else
 | |
| static inline bool ip6mr_rule_default(const struct fib_rule *rule)
 | |
| {
 | |
| 	return true;
 | |
| }
 | |
| #endif
 | |
| 
 | |
| #define VIFF_STATIC 0x8000
 | |
| 
 | |
| struct mfc6_cache_cmp_arg {
 | |
| 	struct in6_addr mf6c_mcastgrp;
 | |
| 	struct in6_addr mf6c_origin;
 | |
| };
 | |
| 
 | |
| struct mfc6_cache {
 | |
| 	struct mr_mfc _c;
 | |
| 	union {
 | |
| 		struct {
 | |
| 			struct in6_addr mf6c_mcastgrp;
 | |
| 			struct in6_addr mf6c_origin;
 | |
| 		};
 | |
| 		struct mfc6_cache_cmp_arg cmparg;
 | |
| 	};
 | |
| };
 | |
| 
 | |
| #define MFC_ASSERT_THRESH (3*HZ)		/* Maximal freq. of asserts */
 | |
| 
 | |
| struct rtmsg;
 | |
| extern int ip6mr_get_route(struct net *net, struct sk_buff *skb,
 | |
| 			   struct rtmsg *rtm, u32 portid);
 | |
| 
 | |
| #ifdef CONFIG_IPV6_MROUTE
 | |
| bool mroute6_is_socket(struct net *net, struct sk_buff *skb);
 | |
| extern int ip6mr_sk_done(struct sock *sk);
 | |
| static inline int ip6mr_sk_ioctl(struct sock *sk, unsigned int cmd,
 | |
| 				 void __user *arg)
 | |
| {
 | |
| 	switch (cmd) {
 | |
| 	/* These userspace buffers will be consumed by ip6mr_ioctl() */
 | |
| 	case SIOCGETMIFCNT_IN6: {
 | |
| 		struct sioc_mif_req6 buffer;
 | |
| 
 | |
| 		return sock_ioctl_inout(sk, cmd, arg, &buffer,
 | |
| 					sizeof(buffer));
 | |
| 		}
 | |
| 	case SIOCGETSGCNT_IN6: {
 | |
| 		struct sioc_sg_req6 buffer;
 | |
| 
 | |
| 		return sock_ioctl_inout(sk, cmd, arg, &buffer,
 | |
| 					sizeof(buffer));
 | |
| 		}
 | |
| 	}
 | |
| 
 | |
| 	return 1;
 | |
| }
 | |
| #else
 | |
| static inline bool mroute6_is_socket(struct net *net, struct sk_buff *skb)
 | |
| {
 | |
| 	return false;
 | |
| }
 | |
| static inline int ip6mr_sk_done(struct sock *sk)
 | |
| {
 | |
| 	return 0;
 | |
| }
 | |
| 
 | |
| static inline int ip6mr_sk_ioctl(struct sock *sk, unsigned int cmd,
 | |
| 				 void __user *arg)
 | |
| {
 | |
| 	return 1;
 | |
| }
 | |
| #endif
 | |
| #endif
 |