linux-wireless.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andrey Borzenkov <arvidjaar@mail.ru>
To: orinoco-devel@lists.sourceforge.net
Cc: David Kilroy <kilroyd@googlemail.com>, linux-wireless@vger.kernel.org
Subject: Re: [Orinoco-devel] [PATCH 1/2] orinoco: validate firmware header
Date: Fri, 20 Feb 2009 21:26:08 +0300	[thread overview]
Message-ID: <200902202126.12230.arvidjaar@mail.ru> (raw)
In-Reply-To: <1235087187-23425-2-git-send-email-kilroyd@googlemail.com>

[-- Attachment #1: Type: text/plain, Size: 1643 bytes --]

On 20 of February 2009 02:46:26 David Kilroy wrote:
>
> +static const char *fw_err[] = {
> +	"image too small",
> +	"format not recognised",
> +	"bad headersize",
> +	"bad block offset",
> +	"bad PDR offset",
> +	"bad PRI offset",
> +	"bad compat offset"
> +};
> +
>  /* Structure used to access fields in FW
>   * Make sure LE decoding macros are used
>   */
> @@ -43,6 +53,32 @@ struct orinoco_fw_header {
>  	char signature[0];      /* FW signature length headersize-20 */
>  } __attribute__ ((packed));
>
> +/* Check the range of various header entries */
> +static int validate_fw(const struct orinoco_fw_header *hdr, size_t
> len) +{
> +	u16 hdrsize;
> +
> +	if (len < sizeof(*hdr))
> +		return 1;
> +	if (memcmp(hdr->hdr_vers, "HFW", 3) != 0)
> +		return 2;
> +
> +	hdrsize = le16_to_cpu(hdr->headersize);
> +	if (hdrsize > len)
> +		return 3;
> +	if ((hdrsize + le32_to_cpu(hdr->block_offset)) > len)
> +		return 4;
> +	if ((hdrsize + le32_to_cpu(hdr->pdr_offset)) > len)
> +		return 5;
> +	if ((hdrsize + le32_to_cpu(hdr->pri_offset)) > len)
> +		return 6;
> +	if ((hdrsize + le32_to_cpu(hdr->compat_offset)) > len)
> +		return 7;
> +
> +	/* TODO: consider adding a checksum or CRC to the firmware format
> */ +	return 0;
> +}


I am afraid this can easily go off sync. Any reason those messages 
cannot be printed inline in validate_fw()?

Otherwise what about

#define FW_ERR_OK	0
#define FW_ERR_TOO_SMALL 1
...
static const char *fw_err[] = {
	[FW_ERR_TOO_SMALL] = "image too small",
...

	if (len < sizeof(*hdr))
		return FW_ERR_TOO_SMALL;
...
	return FW_ERR_OK;

?

[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 197 bytes --]

  reply	other threads:[~2009-02-20 18:26 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-02-19 23:46 [PATCH 0/2] orinoco: improve robustness of firmware load David Kilroy
2009-02-19 23:46 ` [PATCH 1/2] orinoco: validate firmware header David Kilroy
2009-02-20 18:26   ` Andrey Borzenkov [this message]
2009-02-20 19:19     ` [Orinoco-devel] " Dave
2009-02-19 23:46 ` [PATCH 2/2] orinoco: prevent accessing memory outside the firmware image David Kilroy
2009-02-20 19:28   ` Dave

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=200902202126.12230.arvidjaar@mail.ru \
    --to=arvidjaar@mail.ru \
    --cc=kilroyd@googlemail.com \
    --cc=linux-wireless@vger.kernel.org \
    --cc=orinoco-devel@lists.sourceforge.net \
    /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).