All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kees Cook <kees@kernel.org>
To: Johannes Berg <johannes@sipsolutions.net>
Cc: linux-wireless@vger.kernel.org, Haoyu Li <lihaoyu499@gmail.com>,
	syzbot+e834e757bd9b3d3e1251@syzkaller.appspotmail.com
Subject: Re: [PATCH wireless] wifi: cfg80211: remove scan request n_channels counted_by
Date: Thu, 17 Jul 2025 17:05:49 -0700	[thread overview]
Message-ID: <202507171651.8E89C32F4@keescook> (raw)
In-Reply-To: <adb4d011c640aacb2273f81a4ad6e658ea2f52f1.camel@sipsolutions.net>

On Tue, Jul 15, 2025 at 10:24:16AM +0200, Johannes Berg wrote:
> I'd expect in most cases it's really the same - you allocate, fill, and
> never touch it again before throwing it away at the end. I'd argue
> though that in those cases the whole thing is quite pointless, although
> it still allows finding out-of-bounds reads.

Adding counted_by has filled a large gap in the compiler's ability to
provide the bounds checking. Back in 2022 I had mostly written it off as
"unsolvable" with dynamic sizes being over 60% of the uninstrumentable
memcpy() destinations: https://outflux.net/slides/2022/lss-na/#/6

But thanks to counted_by, we can actually chip away at that percentage
and it's fallen under 50% now, which is nice. :)

> So for now: no, I'm not going to apply any new counted_by() annotations.
> It's cost me far too much time for having absolutely nothing to show for
> the investment. Ask me again again next year maybe.

Yup, totally understood. My desire to get them applied was mainly due to
there being so many (fixed size) array bounds problems in various wifi
drivers that it felt like a good place to focus: dynamic sizes in the
core wifi code. From the same slides above, you can arrow-down through
all of the then-recent array bounds flaws and excepting one in BT,
they're all in wifi: https://outflux.net/slides/2022/lss-na/#/1/6

> If you feel motivated you could help review and perhaps annotate the
> still existing ones I guess, I'm thinking we should have comments there
> like this perhaps:
> 
> --- a/net/mac80211/parse.c
> +++ b/net/mac80211/parse.c
> @@ -54,8 +54,9 @@ struct ieee80211_elems_parse {
>          * scratch buffer that can be used for various element parsing related
>          * tasks, e.g., element de-fragmentation etc.
>          */
> -       size_t scratch_len;
>         u8 *scratch_pos;
> +       /* __counted_by: scratch_len tracks the allocation and doesn't change */
> +       size_t scratch_len;
>         u8 scratch[] __counted_by(scratch_len);
>  };

Sure, I can add this to the TODO list.

> But I'm also not completely sure I've convinced myself that all the
> above discussion about allocated vs. used is really the _entire_
> explanation for it being such a spectacular failure here.

I think it's a big part of it -- having the counted member change after
initial assignment is even frowned upon by the compiler folks, but is
technically supported.

Anyway, sorry again for the wasting of time of yours (and others) that I
caused with this -- I really wasn't expecting it to go that way, and it
hasn't been anywhere near as troublesome in other areas of the kernel,
so it took me by surprise. I have tried to chase down and fix the glitches
when I became aware of them, FWIW.

I'll see if I can write up some patches for comments like you suggest
above with good "proof" attached to them. :)

-Kees

-- 
Kees Cook

  reply	other threads:[~2025-07-18  0:05 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-14 12:21 [PATCH wireless] wifi: cfg80211: remove scan request n_channels counted_by Johannes Berg
2025-07-15  5:04 ` Kees Cook
2025-07-15  8:24   ` Johannes Berg
2025-07-18  0:05     ` Kees Cook [this message]
2025-07-18  8:26       ` Johannes Berg
2025-07-21 18:36     ` Review of __counted_by in wireless (was Re: [PATCH wireless] wifi: cfg80211: remove scan request n_channels counted_by) Kees Cook
2025-07-21 18:52       ` Johannes Berg

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=202507171651.8E89C32F4@keescook \
    --to=kees@kernel.org \
    --cc=johannes@sipsolutions.net \
    --cc=lihaoyu499@gmail.com \
    --cc=linux-wireless@vger.kernel.org \
    --cc=syzbot+e834e757bd9b3d3e1251@syzkaller.appspotmail.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.