Linux Hardening
 help / color / mirror / Atom feed
From: Johannes Berg <johannes@sipsolutions.net>
To: Dmitry Antipov <dmantipov@yandex.ru>
Cc: Kees Cook <kees@kernel.org>,
	linux-wireless@vger.kernel.org,  linux-hardening@vger.kernel.org,
	lvc-project@linuxtesting.org
Subject: Re: [PATCH] wifi: wireless: fix more UBSAN noise in cfg80211_conn_scan()
Date: Tue, 27 Aug 2024 10:12:26 +0200	[thread overview]
Message-ID: <3ddcf25ba09bf99c973c46ef1944c079be2753eb.camel@sipsolutions.net> (raw)
In-Reply-To: <20240716174011.236849-1-dmantipov@yandex.ru>

Hmm.

On Tue, 2024-07-16 at 20:40 +0300, Dmitry Antipov wrote:
> diff --git a/net/wireless/sme.c b/net/wireless/sme.c
> index a8ad55f11133..f5da45331847 100644
> --- a/net/wireless/sme.c
> +++ b/net/wireless/sme.c
> @@ -77,12 +77,16 @@ static int cfg80211_conn_scan(struct wireless_dev *wdev)
>  	else
>  		n_channels = ieee80211_get_num_supported_channels(wdev->wiphy);
>  
> -	request = kzalloc(sizeof(*request) + sizeof(request->ssids[0]) +
> -			  sizeof(request->channels[0]) * n_channels,
> -			  GFP_KERNEL);
> +	request = kzalloc(struct_size(request, channels, n_channels) +
> +			  sizeof(request->ssids[0]), GFP_KERNEL);

That makes sense, sure.

>  	if (!request)
>  		return -ENOMEM;
>  
> +	/* None of the channels are actually set
> +	 * up but let UBSAN know the boundaries.
> +	 */
> +	request->n_channels = n_channels;

Also makes sense, so we tell it how many we allocated early.

Note netdev we dropped the special comment style requirement, so
wouldn't mind

 /*
  * None of ...
  * ...
  */

here either.

> +
>  	if (wdev->conn->params.channel) {
>  		enum nl80211_band band = wdev->conn->params.channel->band;
>  		struct ieee80211_supported_band *sband =
> @@ -112,9 +116,9 @@ static int cfg80211_conn_scan(struct wireless_dev *wdev)
>  			}
>  			request->rates[band] = (1 << bands->n_bitrates) - 1;
>  		}
> -		n_channels = i;
> +		request->n_channels = i;

So this tells it how many were actually used, in this branch, makes
sense.

Functionally, all of this seems OK.

However,

>  	request->ssids = (void *)&request->channels[n_channels];

is this not checked? I mean, if you have n_channels=5 and then take
&channels[5] I can see how that makes sense, but arguably the compiler
might complain if you have &channels[10] for an array you told it has 5
entries?

johannes

      parent reply	other threads:[~2024-08-27  8:12 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-16 17:40 [PATCH] wifi: wireless: fix more UBSAN noise in cfg80211_conn_scan() Dmitry Antipov
2024-07-16 18:21 ` Kees Cook
2024-08-27  8:12 ` Johannes Berg [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=3ddcf25ba09bf99c973c46ef1944c079be2753eb.camel@sipsolutions.net \
    --to=johannes@sipsolutions.net \
    --cc=dmantipov@yandex.ru \
    --cc=kees@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