From: Kees Cook <keescook@chromium.org>
To: Hawkins Jiawei <yin31149@gmail.com>
Cc: syzbot+473754e5af963cf014cf@syzkaller.appspotmail.com,
Johannes Berg <johannes@sipsolutions.net>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
linux-kernel@vger.kernel.org, linux-wireless@vger.kernel.org,
netdev@vger.kernel.org, syzkaller-bugs@googlegroups.com,
18801353760@163.com
Subject: Re: [PATCH] wext: use flex array destination for memcpy()
Date: Mon, 26 Sep 2022 10:43:31 -0700 [thread overview]
Message-ID: <202209261042.9B401F8D6@keescook> (raw)
In-Reply-To: <20220926150907.8551-1-yin31149@gmail.com>
On Mon, Sep 26, 2022 at 11:09:06PM +0800, Hawkins Jiawei wrote:
> Syzkaller reports refcount bug as follows:
"buffer overflow false positive" instead of "refcount bug"
> ------------[ 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>
> Signed-off-by: Hawkins Jiawei <yin31149@gmail.com>
Thanks for spinning this and getting it tested!
Reviewed-by: Kees Cook <keescook@chromium.org>
--
Kees Cook
next prev parent reply other threads:[~2022-09-26 18:03 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-23 16:05 [syzbot] WARNING in wireless_send_event syzbot
2022-09-24 7:10 ` [PATCH] Add linux-next specific files for 20220923 Hawkins Jiawei
2022-09-24 7:26 ` Kees Cook
2022-09-24 11:44 ` Hawkins Jiawei
2022-09-24 15:55 ` Hawkins Jiawei
2022-09-24 15:55 ` syzbot
2022-09-24 16:13 ` Hawkins Jiawei
2022-09-24 16:33 ` [syzbot] WARNING in wireless_send_event syzbot
2022-09-24 16:26 ` [PATCH] Add linux-next specific files for 20220923 Kees Cook
2022-09-25 6:25 ` Hawkins Jiawei
2022-09-24 7:32 ` [syzbot] WARNING in wireless_send_event syzbot
2022-09-26 11:59 ` Hawkins Jiawei
2022-09-26 12:24 ` syzbot
2022-09-26 15:09 ` [PATCH] wext: use flex array destination for memcpy() Hawkins Jiawei
2022-09-26 16:14 ` Eric Dumazet
2022-09-26 23:17 ` Hawkins Jiawei
2022-09-26 17:43 ` Kees Cook [this message]
2022-09-26 23:34 ` [PATCH wireless-next v2] " Hawkins Jiawei
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=202209261042.9B401F8D6@keescook \
--to=keescook@chromium.org \
--cc=18801353760@163.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=johannes@sipsolutions.net \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-wireless@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=syzbot+473754e5af963cf014cf@syzkaller.appspotmail.com \
--cc=syzkaller-bugs@googlegroups.com \
--cc=yin31149@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.