Linux wireless drivers development
 help / color / mirror / Atom feed
From: Kees Cook <kees@kernel.org>
To: Dmitry Antipov <dmantipov@yandex.ru>
Cc: Johannes Berg <johannes.berg@intel.com>,
	Kalle Valo <kvalo@kernel.org>,
	linux-wireless@vger.kernel.org, linux-hardening@vger.kernel.org,
	lvc-project@linuxtesting.org
Subject: Re: [PATCH] wifi: cfg80211: fix UBSAN noise in cfg80211_wext_siwscan()
Date: Thu, 5 Sep 2024 09:58:25 -0700	[thread overview]
Message-ID: <202409050957.7DD6B23EA@keescook> (raw)
In-Reply-To: <20240905150400.126386-1-dmantipov@yandex.ru>

On Thu, Sep 05, 2024 at 06:04:00PM +0300, Dmitry Antipov wrote:
> Looking at https://syzkaller.appspot.com/bug?extid=1a3986bbd3169c307819
> and running reproducer with CONFIG_UBSAN_BOUNDS, I've noticed the
> following:
> 
> [ T4985] UBSAN: array-index-out-of-bounds in net/wireless/scan.c:3479:25
> [ T4985] index 164 is out of range for type 'struct ieee80211_channel *[]'
> <...skipped...>
> [ T4985] Call Trace:
> [ T4985]  <TASK>
> [ T4985]  dump_stack_lvl+0x1c2/0x2a0
> [ T4985]  ? __pfx_dump_stack_lvl+0x10/0x10
> [ T4985]  ? __pfx__printk+0x10/0x10
> [ T4985]  __ubsan_handle_out_of_bounds+0x127/0x150
> [ T4985]  cfg80211_wext_siwscan+0x11a4/0x1260
> <...the rest is not too useful...>
> 
> Even if we do 'creq->n_channels = n_channels' before 'creq->ssids =
> (void *)&creq->channels[n_channels]', UBSAN treats the latter as
> off-by-one error. Fix this by using pointer arithmetic rather than
> an expression with explicit array indexing and use convenient
> 'struct_size()' to simplify the math here and in 'kzalloc()' above.
> 
> Fixes: 5ba63533bbf6 ("cfg80211: fix alignment problem in scan request")
> Signed-off-by: Dmitry Antipov <dmantipov@yandex.ru>

This looks correct -- the offset is based on the allocation base, not
the array within the struct, so no array-out-of-bounds warning will
happen.

Reviewed-by: Kees Cook <kees@kernel.org>

-- 
Kees Cook

      reply	other threads:[~2024-09-05 16:58 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-05 15:04 [PATCH] wifi: cfg80211: fix UBSAN noise in cfg80211_wext_siwscan() Dmitry Antipov
2024-09-05 16:58 ` Kees Cook [this message]

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=202409050957.7DD6B23EA@keescook \
    --to=kees@kernel.org \
    --cc=dmantipov@yandex.ru \
    --cc=johannes.berg@intel.com \
    --cc=kvalo@kernel.org \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-wireless@vger.kernel.org \
    --cc=lvc-project@linuxtesting.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox