Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1673337 > unrolled thread

[UBSAN] iwlmvm's iwl_mvm_enable_txq accesses IEEE80211_INVAL_HW_QUEUE

Started byJiri Slaby <jslaby@suse.cz>
First post2017-06-23 09:50 +0200
Last post2017-06-23 10:00 +0200
Articles 2 — 2 participants

Back to article view | Back to linux.kernel


Contents

  [UBSAN] iwlmvm's iwl_mvm_enable_txq accesses IEEE80211_INVAL_HW_QUEUE Jiri Slaby <jslaby@suse.cz> - 2017-06-23 09:50 +0200
    Re: [UBSAN] iwlmvm's iwl_mvm_enable_txq accesses  IEEE80211_INVAL_HW_QUEUE Johannes Berg <johannes@sipsolutions.net> - 2017-06-23 10:00 +0200

#1673337 — [UBSAN] iwlmvm's iwl_mvm_enable_txq accesses IEEE80211_INVAL_HW_QUEUE

FromJiri Slaby <jslaby@suse.cz>
Date2017-06-23 09:50 +0200
Subject[UBSAN] iwlmvm's iwl_mvm_enable_txq accesses IEEE80211_INVAL_HW_QUEUE
Message-ID<tVrvQ-7Kn-5@gated-at.bofh.it>
Hi,

we have got an UBSAN report from opensuse's user who booten
UBSAN-enabled kernel by mistake:
UBSAN: Undefined behaviour in
drivers/net/wireless/intel/iwlwifi/mvm/utils.c:667:49
shift exponent 255 is too large for 64-bit type 'long unsigned int'
CPU: 2 PID: 1590 Comm: wpa_supplicant Not tainted 4.11.2-1-syzkaller #1
Hardware name: Dell Inc. Precision 5510/0N8J4R, BIOS 01.02.00 04/07/2016
Call Trace:
...
 iwl_mvm_enable_txq+0xc6d/0x1080 [iwlmvm]
 iwl_mvm_send_add_bcast_sta+0x275/0x850 [iwlmvm]
 iwl_mvm_add_bcast_sta+0x11b/0x280 [iwlmvm]
 iwl_mvm_mac_add_interface+0x51f/0x8b0 [iwlmvm]
 drv_add_interface+0x1a7/0x8c0 [mac80211]
 ieee80211_do_open+0xdff/0x2790 [mac80211]
 ieee80211_start_p2p_device+0xac/0xf0 [mac80211]
 nl80211_start_p2p_device+0x25d/0xab0 [cfg80211]
 genl_family_rcv_msg+0x835/0xf10
 genl_rcv_msg+0xd0/0x1c0
 netlink_rcv_skb+0x226/0x310
 genl_rcv+0x2d/0x40
 netlink_unicast+0x631/0x9d0
 netlink_sendmsg+0xa2e/0xf60
 sock_sendmsg+0xf7/0x180
 ___sys_sendmsg+0x777/0xa60
 __sys_sendmsg+0xd6/0x170
 SyS_sendmsg+0x32/0x50
 entry_SYSCALL_64_fastpath+0x23/0xc6



mac80211_queue is 255 which is IEEE80211_INVAL_HW_QUEUE, so it should
not be worked with at all.


The invalid queue is hopefully handled in ieee80211_check_queues after
drv_add_interface in ieee80211_do_open:

res = drv_add_interface(local, sdata);
if (res)
        goto err_stop;
res = ieee80211_check_queues(sdata,
        ieee80211_vif_type_p2p(&sdata->vif));


But the mvm driver still should not blindly shift 1 by 255 in
iwl_mvm_enable_txq. Should the check for the invalid queue be before
adding the interface in mac80211? Or should drivers check it in their
add_interface?

thanks,
-- 
js
suse labs

[toc] | [next] | [standalone]


#1673339 — Re: [UBSAN] iwlmvm's iwl_mvm_enable_txq accesses IEEE80211_INVAL_HW_QUEUE

FromJohannes Berg <johannes@sipsolutions.net>
Date2017-06-23 10:00 +0200
SubjectRe: [UBSAN] iwlmvm's iwl_mvm_enable_txq accesses IEEE80211_INVAL_HW_QUEUE
Message-ID<tVrFv-7Pz-5@gated-at.bofh.it>
In reply to#1673337
On Fri, 2017-06-23 at 09:48 +0200, Jiri Slaby wrote:
> 
> mac80211_queue is 255 which is IEEE80211_INVAL_HW_QUEUE, so it should
> not be worked with at all.

Funny you should find this today :-)

> The invalid queue is hopefully handled in ieee80211_check_queues
> after
> drv_add_interface in ieee80211_do_open:
> 
> res = drv_add_interface(local, sdata);
> if (res)
>         goto err_stop;
> res = ieee80211_check_queues(sdata,
>         ieee80211_vif_type_p2p(&sdata->vif));
> 
> 
> But the mvm driver still should not blindly shift 1 by 255 in
> iwl_mvm_enable_txq. Should the check for the invalid queue be before
> adding the interface in mac80211? Or should drivers check it in their
> add_interface?

Everything is actually handled well afaict, because the bug won't
matter - this is a queue we'll never really stop, so we won't be
looking at the (invalid) result of the calculation. I had actually been
under the impression that it wasn't undefined but would just result in
0; that's clearly not true but also doesn't matter. AFAICT it even
results in 0x80000000 (which makes some sense, since 255 % 32 == 31),
and that's a queue number (31) that's too big for mac80211 anyway, so
it would warn if we were to ever try to stop it.

In later versions of the code, however, there *was* indeed a bug - we
were using a u8 instead of a u32 in the code we have internally. While
fixing *that* bug, I also made this catch the case of
IEEE80211_INVAL_HW_QUEUE so we'll not modify the bitmap at all, which
is the correct thing to do.

IOW - yes, it's not nice, but it also shouldn't matter, and even if for
some strange reason we tried to stop the queue we'd just get a warning
from mac80211.

johannes

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web