mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-09-12 13:55:32 +00:00
![Hawkins Jiawei](/assets/img/avatar_default.png)
commit e3e6e1d16a
upstream.
Syzkaller reports buffer overflow false positive as follows:
------------[ cut here ]------------
memcpy: detected field-spanning write (size 8) of single field
"&compat_event->pointer" at net/wireless/wext-core.c:623 (size 4)
WARNING: CPU: 0 PID: 3607 at net/wireless/wext-core.c:623
wireless_send_event+0xab5/0xca0 net/wireless/wext-core.c:623
Modules linked in:
CPU: 1 PID: 3607 Comm: syz-executor659 Not tainted
6.0.0-rc6-next-20220921-syzkaller #0
[...]
Call Trace:
<TASK>
ioctl_standard_call+0x155/0x1f0 net/wireless/wext-core.c:1022
wireless_process_ioctl+0xc8/0x4c0 net/wireless/wext-core.c:955
wext_ioctl_dispatch net/wireless/wext-core.c:988 [inline]
wext_ioctl_dispatch net/wireless/wext-core.c:976 [inline]
wext_handle_ioctl+0x26b/0x280 net/wireless/wext-core.c:1049
sock_ioctl+0x285/0x640 net/socket.c:1220
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+0x193/0x200 fs/ioctl.c:856
do_syscall_x64 arch/x86/entry/common.c:50 [inline]
do_syscall_64+0x35/0xb0 arch/x86/entry/common.c:80
entry_SYSCALL_64_after_hwframe+0x63/0xcd
[...]
</TASK>
Wireless events will be sent on the appropriate channels in
wireless_send_event(). Different wireless events may have different
payload structure and size, so kernel uses **len** and **cmd** field
in struct __compat_iw_event as wireless event common LCP part, uses
**pointer** as a label to mark the position of remaining different part.
Yet the problem is that, **pointer** is a compat_caddr_t type, which may
be smaller than the relative structure at the same position. So during
wireless_send_event() tries to parse the wireless events payload, it may
trigger the memcpy() run-time destination buffer bounds checking when the
relative structure's data is copied to the position marked by **pointer**.
This patch solves it by introducing flexible-array field **ptr_bytes**,
to mark the position of the wireless events remaining part next to
LCP part. What's more, this patch also adds **ptr_len** variable in
wireless_send_event() to improve its maintainability.
Reported-and-tested-by: syzbot+473754e5af963cf014cf@syzkaller.appspotmail.com
Link: https://lore.kernel.org/all/00000000000070db2005e95a5984@google.com/
Suggested-by: Kees Cook <keescook@chromium.org>
Reviewed-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Hawkins Jiawei <yin31149@gmail.com>
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
53 lines
1.6 KiB
C
53 lines
1.6 KiB
C
/* SPDX-License-Identifier: GPL-2.0 */
|
|
/*
|
|
* This file define a set of standard wireless extensions
|
|
*
|
|
* Version : 22 16.3.07
|
|
*
|
|
* Authors : Jean Tourrilhes - HPL - <jt@hpl.hp.com>
|
|
* Copyright (c) 1997-2007 Jean Tourrilhes, All Rights Reserved.
|
|
*/
|
|
#ifndef _LINUX_WIRELESS_H
|
|
#define _LINUX_WIRELESS_H
|
|
|
|
#include <uapi/linux/wireless.h>
|
|
|
|
#ifdef CONFIG_COMPAT
|
|
|
|
#include <linux/compat.h>
|
|
|
|
struct compat_iw_point {
|
|
compat_caddr_t pointer;
|
|
__u16 length;
|
|
__u16 flags;
|
|
};
|
|
#endif
|
|
#ifdef CONFIG_COMPAT
|
|
struct __compat_iw_event {
|
|
__u16 len; /* Real length of this stuff */
|
|
__u16 cmd; /* Wireless IOCTL */
|
|
|
|
union {
|
|
compat_caddr_t pointer;
|
|
|
|
/* we need ptr_bytes to make memcpy() run-time destination
|
|
* buffer bounds checking happy, nothing special
|
|
*/
|
|
DECLARE_FLEX_ARRAY(__u8, ptr_bytes);
|
|
};
|
|
};
|
|
#define IW_EV_COMPAT_LCP_LEN offsetof(struct __compat_iw_event, pointer)
|
|
#define IW_EV_COMPAT_POINT_OFF offsetof(struct compat_iw_point, length)
|
|
|
|
/* Size of the various events for compat */
|
|
#define IW_EV_COMPAT_CHAR_LEN (IW_EV_COMPAT_LCP_LEN + IFNAMSIZ)
|
|
#define IW_EV_COMPAT_UINT_LEN (IW_EV_COMPAT_LCP_LEN + sizeof(__u32))
|
|
#define IW_EV_COMPAT_FREQ_LEN (IW_EV_COMPAT_LCP_LEN + sizeof(struct iw_freq))
|
|
#define IW_EV_COMPAT_PARAM_LEN (IW_EV_COMPAT_LCP_LEN + sizeof(struct iw_param))
|
|
#define IW_EV_COMPAT_ADDR_LEN (IW_EV_COMPAT_LCP_LEN + sizeof(struct sockaddr))
|
|
#define IW_EV_COMPAT_QUAL_LEN (IW_EV_COMPAT_LCP_LEN + sizeof(struct iw_quality))
|
|
#define IW_EV_COMPAT_POINT_LEN \
|
|
(IW_EV_COMPAT_LCP_LEN + sizeof(struct compat_iw_point) - \
|
|
IW_EV_COMPAT_POINT_OFF)
|
|
#endif
|
|
#endif /* _LINUX_WIRELESS_H */
|