2023-12-14 07:35:50

by Francesco Dolcini

[permalink] [raw]
Subject: Re: [EXT] Re: [PATCH v2] wifi: mwifiex: fix STA cannot connect to AP

Hello David,

On Thu, Dec 14, 2023 at 02:22:57AM +0000, David Lin wrote:
> > From: Brian Norris <[email protected]>
...
> > Nitpick: "fix STA cannot connect to AP" isn't the best commit message; that
> > could describe an enormous number of fixes. Maybe something more like
> > "Configure BSSID consistently when starting AP"?
>
> Thanks for your suggestion. I will change commit message as you
> suggested. Does it mean I should create another patch from v1?

Just create `[PATCH v3] wifi: mwifiex: fix STA cannot connect to AP`

Add the change suggested by Brian and the tags you received on this v2:

- Reviewed-by: Francesco Dolcini <[email protected]>
- Tested-by: Rafael Beims <[email protected]> # Verdin iMX8MP / SD8997 SD
- Acked-by: Brian Norris <[email protected]>

> > Not directly related to this patch, but while you're expanding the size of this
> > command buffer: it always felt like a security-hole-in-waiting that none of
> > these command producers do any kinds of bounds checking.
> > We're just "lucky" that these function only generate contents of ~100 bytes at
> > max, while MWIFIEX_SIZE_OF_CMD_BUFFER=2048. But, just add a few more
> > user-space controlled TLV params, and boom, we'll have ourselves a nice
> > little CVE.
> >
> > It probably wouldn't hurt to significantly write much of this driver, but at a
> > minimum, we could probably use a few checks like this:
> >
> > cmd_size += sizeof(struct host_cmd_tlv_mac_addr);
> > if (cmd_size > MWIFIEX_SIZE_OF_CMD_BUFFER)
> > return -1;
> > // Only touch tlv *after* the bounds check.
> >
> > That doesn't need to block this patch, of course.
> >
> > Brian
> >
>
> I will modify the code for next patch.

I would suggest not modify this in this patch, we should fix all the code that
is subjected to this potential issue.

I would personally do a follow-up patch just to add the check to avoid
overflowing the cmd buffer everywhere it is used.

Francesco



2023-12-14 11:39:05

by David Lin

[permalink] [raw]
Subject: RE: [EXT] Re: [PATCH v2] wifi: mwifiex: fix STA cannot connect to AP

> From: Francesco Dolcini <[email protected]>
> Sent: Thursday, December 14, 2023 3:35 PM
> To: David Lin <[email protected]>
> Cc: Brian Norris <[email protected]>;
> [email protected]; [email protected];
> [email protected]; [email protected]; Pete Hsieh
> <[email protected]>; [email protected]
> Subject: Re: [EXT] Re: [PATCH v2] wifi: mwifiex: fix STA cannot connect to AP
>
> Caution: This is an external email. Please take care when clicking links or
> opening attachments. When in doubt, report the message using the 'Report
> this email' button
>
>
> Hello David,
>
> On Thu, Dec 14, 2023 at 02:22:57AM +0000, David Lin wrote:
> > > From: Brian Norris <[email protected]>
> ...
> > > Nitpick: "fix STA cannot connect to AP" isn't the best commit
> > > message; that could describe an enormous number of fixes. Maybe
> > > something more like "Configure BSSID consistently when starting AP"?
> >
> > Thanks for your suggestion. I will change commit message as you
> > suggested. Does it mean I should create another patch from v1?
>
> Just create `[PATCH v3] wifi: mwifiex: fix STA cannot connect to AP`
>
> Add the change suggested by Brian and the tags you received on this v2:
>
> - Reviewed-by: Francesco Dolcini <[email protected]>
> - Tested-by: Rafael Beims <[email protected]> # Verdin iMX8MP /
> SD8997 SD
> - Acked-by: Brian Norris <[email protected]>
>

O.K. Thanks.

> > > Not directly related to this patch, but while you're expanding the
> > > size of this command buffer: it always felt like a
> > > security-hole-in-waiting that none of these command producers do any
> kinds of bounds checking.
> > > We're just "lucky" that these function only generate contents of
> > > ~100 bytes at max, while MWIFIEX_SIZE_OF_CMD_BUFFER=2048. But, just
> > > add a few more user-space controlled TLV params, and boom, we'll
> > > have ourselves a nice little CVE.
> > >
> > > It probably wouldn't hurt to significantly write much of this
> > > driver, but at a minimum, we could probably use a few checks like this:
> > >
> > > cmd_size += sizeof(struct host_cmd_tlv_mac_addr);
> > > if (cmd_size > MWIFIEX_SIZE_OF_CMD_BUFFER)
> > > return -1;
> > > // Only touch tlv *after* the bounds check.
> > >
> > > That doesn't need to block this patch, of course.
> > >
> > > Brian
> > >
> >
> > I will modify the code for next patch.
>
> I would suggest not modify this in this patch, we should fix all the code that
> is subjected to this potential issue.
>
> I would personally do a follow-up patch just to add the check to avoid
> overflowing the cmd buffer everywhere it is used.
>
> Francesco


O.K. I will only change commit message. In fact, this TLV command is added as the first one command.

2023-12-14 18:52:50

by Brian Norris

[permalink] [raw]
Subject: Re: [EXT] Re: [PATCH v2] wifi: mwifiex: fix STA cannot connect to AP

On Thu, Dec 14, 2023 at 3:38 AM David Lin <[email protected]> wrote:
> > From: Francesco Dolcini <[email protected]>
> >
> > On Thu, Dec 14, 2023 at 02:22:57AM +0000, David Lin wrote:
> > > > From: Brian Norris <[email protected]>
> > > > It probably wouldn't hurt to significantly write much of this
> > > > driver, but at a minimum, we could probably use a few checks like this:
> > > >
> > > > cmd_size += sizeof(struct host_cmd_tlv_mac_addr);
> > > > if (cmd_size > MWIFIEX_SIZE_OF_CMD_BUFFER)
> > > > return -1;
> > > > // Only touch tlv *after* the bounds check.
> > > >
> > > > That doesn't need to block this patch, of course.
> > > >
> > > > Brian
> > > >
> > >
> > > I will modify the code for next patch.
> >
> > I would suggest not modify this in this patch, we should fix all the code that
> > is subjected to this potential issue.
> >
> > I would personally do a follow-up patch just to add the check to avoid
> > overflowing the cmd buffer everywhere it is used.

Right, there's tons of code that could potentially be affected, and
this is definitely a separate patch. (Your feature only adds on to the
existing issue, so these are separate logical changes.)

> O.K. I will only change commit message. In fact, this TLV command is added as the first one command.

Well, it doesn't really matter than your TLV is "first" -- if there's
an overflow, there's an overflow. Maybe the 8 bytes you're adding here
are the necessary tipping point. I don't know without doing some kind
of informal mathematics/proof.

Brian

2023-12-14 23:05:16

by David Lin

[permalink] [raw]
Subject: RE: [EXT] Re: [PATCH v2] wifi: mwifiex: fix STA cannot connect to AP

> From: Brian Norris <[email protected]>
> Sent: Friday, December 15, 2023 2:52 AM
> To: David Lin <[email protected]>
> Cc: Francesco Dolcini <[email protected]>; [email protected];
> [email protected]; [email protected]; Pete Hsieh
> <[email protected]>; [email protected]
> Subject: Re: [EXT] Re: [PATCH v2] wifi: mwifiex: fix STA cannot connect to AP
>
> Caution: This is an external email. Please take care when clicking links or
> opening attachments. When in doubt, report the message using the 'Report
> this email' button
>
>
> On Thu, Dec 14, 2023 at 3:38 AM David Lin <[email protected]> wrote:
> > > From: Francesco Dolcini <[email protected]>
> > >
> > > On Thu, Dec 14, 2023 at 02:22:57AM +0000, David Lin wrote:
> > > > > From: Brian Norris <[email protected]> It probably
> > > > > wouldn't hurt to significantly write much of this driver, but at
> > > > > a minimum, we could probably use a few checks like this:
> > > > >
> > > > > cmd_size += sizeof(struct host_cmd_tlv_mac_addr);
> > > > > if (cmd_size > MWIFIEX_SIZE_OF_CMD_BUFFER)
> > > > > return -1;
> > > > > // Only touch tlv *after* the bounds check.
> > > > >
> > > > > That doesn't need to block this patch, of course.
> > > > >
> > > > > Brian
> > > > >
> > > >
> > > > I will modify the code for next patch.
> > >
> > > I would suggest not modify this in this patch, we should fix all the
> > > code that is subjected to this potential issue.
> > >
> > > I would personally do a follow-up patch just to add the check to
> > > avoid overflowing the cmd buffer everywhere it is used.
>
> Right, there's tons of code that could potentially be affected, and this is
> definitely a separate patch. (Your feature only adds on to the existing issue,
> so these are separate logical changes.)
>
> > O.K. I will only change commit message. In fact, this TLV command is added
> as the first one command.
>
> Well, it doesn't really matter than your TLV is "first" -- if there's an overflow,
> there's an overflow. Maybe the 8 bytes you're adding here are the necessary
> tipping point. I don't know without doing some kind of informal
> mathematics/proof.
>
> Brian

Understood. Thanks.