linux-wireless.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Pkshih <pkshih@realtek.com>
To: "kvalo@codeaurora.org" <kvalo@codeaurora.org>,
	"tiwai@suse.de" <tiwai@suse.de>
Cc: "linux-wireless@vger.kernel.org" <linux-wireless@vger.kernel.org>,
	"Larry.Finger@gmail.com" <Larry.Finger@gmail.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] rtw89: Fix crash by loading compressed firmware file
Date: Fri, 5 Nov 2021 14:28:39 +0000	[thread overview]
Message-ID: <bd80d3b6cdc42d7818d7d5c6a5036d8188eb4a67.camel@realtek.com> (raw)
In-Reply-To: <87v917q8hw.fsf@codeaurora.org>

On Fri, 2021-11-05 at 11:03 +0200, Kalle Valo wrote:
> Takashi Iwai <tiwai@suse.de> writes:
> 
> > On Fri, 05 Nov 2021 09:25:13 +0100,
> > Kalle Valo wrote:
> > > Takashi Iwai <tiwai@suse.de> writes:
> > > 
> > > > On Fri, 05 Nov 2021 08:17:25 +0100,
> > > > Takashi Iwai wrote:
> > > > > When a firmware is loaded in the compressed format or via user-mode
> > > > > helper, it's mapped in read-only, and the rtw89 driver crashes at
> > > > > rtw89_fw_download() when it tries to modify some data.
> > > > > 
> > > > > This patch is an attemp to avoid the crash by re-allocating the data
> > > > > via vmalloc() for the data modification.
> > > > 
> > > > Alternatively, we may drop the code that modifies the loaded firmware
> > > > data?  At least SET_FW_HDR_PART_SIZE() in rtw89_fw_hdr_parser() looks
> > > > writing it, and I have no idea why this overwrite is needed.
> > > 
> > > Strange, isn't the firmware data marked as const just to avoid this kind
> > > of problem? Does rtw89 have wrong casts somewhere which removes the
> > > const?
> > 
> > Yes.  SET_FW_HDR_PART_SIZE() does the cast, dropping the const.
> 
> Oh man, all of GET and SET macros in fw.h have those casts:
> 
> #define GET_FW_HDR_MAJOR_VERSION(fwhdr)	\
> 	le32_get_bits(*((__le32 *)(fwhdr) + 1), GENMASK(7, 0))
> #define GET_FW_HDR_MINOR_VERSION(fwhdr)	\
> 	le32_get_bits(*((__le32 *)(fwhdr) + 1), GENMASK(15, 8))
> #define GET_FW_HDR_SUBVERSION(fwhdr)	\
> 	le32_get_bits(*((__le32 *)(fwhdr) + 1), GENMASK(23, 16))
> 
> I don't know how I missed those during my review :( But this is exactly
> why I prefer having a proper struct for commands and events, instead of
> u8 buf used with these macros.
> 


I can use a struct to access firmware header, becuase their fields
are multiple of 8 bits.

But, the "firmware section header" that is additional header followed
by firmware header, and it contains bit fields, likes:

#define GET_FWSECTION_HDR_SEC_SIZE(fwhdr)	\
	le32_get_bits(*((__le32 *)(fwhdr) + 1), GENMASK(23, 0))
#define GET_FWSECTION_HDR_CHECKSUM(fwhdr)	\
	le32_get_bits(*((__le32 *)(fwhdr) + 1), BIT(28))
#define GET_FWSECTION_HDR_REDL(fwhdr)	\
	le32_get_bits(*((__le32 *)(fwhdr) + 1), BIT(29))
#define GET_FWSECTION_HDR_DL_ADDR(fwhdr)	\
	le32_get_bits(*((__le32 *)(fwhdr)), GENMASK(31, 0))

If we use a struct, it needs big-/little- endians parts.

Then, we will access firmware header with two methods; is
it reasonable?


The macro SET_FW_HDR_PART_SIZE() is used to set the firmware
partition size we are going to download, and it is only used
by rtw89_fw_download_hdr(). So, I will set the partition size
after copying constant firmware header into skb->data.

--
Ping-Ke


  reply	other threads:[~2021-11-05 14:28 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-05  7:17 [PATCH] rtw89: Fix crash by loading compressed firmware file Takashi Iwai
2021-11-05  7:21 ` Takashi Iwai
2021-11-05  8:25   ` Kalle Valo
2021-11-05  8:40     ` Takashi Iwai
2021-11-05  9:03       ` Kalle Valo
2021-11-05 14:28         ` Pkshih [this message]
2021-11-05 15:07           ` Takashi Iwai
2021-11-11  2:28             ` Pkshih
2021-11-11  6:31               ` Takashi Iwai
2021-11-11 13:34                 ` Takashi Iwai
2021-11-12  0:38                   ` Pkshih

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=bd80d3b6cdc42d7818d7d5c6a5036d8188eb4a67.camel@realtek.com \
    --to=pkshih@realtek.com \
    --cc=Larry.Finger@gmail.com \
    --cc=kvalo@codeaurora.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-wireless@vger.kernel.org \
    --cc=tiwai@suse.de \
    /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;
as well as URLs for NNTP newsgroup(s).