mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Lee Jones <lee.jones@linaro.org>
To: Kyle Spiers <ksspiers@google.com>
Cc: linux-kernel@vger.kernel.org, keescook@chromium.org
Subject: Re: [PATCH] rave-sp: Remove VLA
Date: Tue, 24 Apr 2018 06:43:15 +0100	[thread overview]
Message-ID: <20180424054315.2yjpnht5pu62i54q@dell> (raw)
In-Reply-To: <20180423200255.154645-1-ksspiers@google.com>

On Mon, 23 Apr 2018, Kyle Spiers wrote:

> As part of the effort to remove VLAs from the kernel[1], this creates
> constants for the checksum lengths of CCITT and 8B2C and changes
> crc_calculated to be the maximum size of a checksum.
> 
> https://lkml.org/lkml/2018/3/7/621
> 
> Signed-off-by: Kyle Spiers <ksspiers@google.com>
> ---
>  drivers/mfd/rave-sp.c | 11 +++++++++--
>  1 file changed, 9 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/mfd/rave-sp.c b/drivers/mfd/rave-sp.c
> index 5c858e784a89..99fa482419f9 100644
> --- a/drivers/mfd/rave-sp.c
> +++ b/drivers/mfd/rave-sp.c
> @@ -45,7 +45,9 @@
>  #define RAVE_SP_DLE			0x10
>  
>  #define RAVE_SP_MAX_DATA_SIZE		64
> -#define RAVE_SP_CHECKSUM_SIZE		2  /* Worst case scenario on RDU2 */
> +#define RAVE_SP_CHECKSUM_8B2C		1
> +#define RAVE_SP_CHECKSUM_CCITT		2
> +#define RAVE_SP_CHECKSUM_SIZE		RAVE_SP_CHECKSUM_CCITT
>  /*
>   * We don't store STX, ETX and unescaped bytes, so Rx is only
>   * DATA + CSUM
> @@ -415,7 +417,12 @@ static void rave_sp_receive_frame(struct rave_sp *sp,
>  	const size_t payload_length  = length - checksum_length;
>  	const u8 *crc_reported       = &data[payload_length];
>  	struct device *dev           = &sp->serdev->dev;
> -	u8 crc_calculated[checksum_length];
> +	u8 crc_calculated[RAVE_SP_CHECKSUM_SIZE];
> +
> +	if (unlikely(length > sizeof(crc_calculated))) {

Forgive me if I have this wrong (it's still very early here), but this
doesn't leave any room for the payload?

    <--       length         -->
    <ck len><- payload length ->
    [CK][CK][D][A][T][A] .. [64]

It is my hope that length would always be larger than the size of the
checksum, or else there would never be any data?

Should this not be:

    if (unlikely(length > RAVE_SP_MAX_DATA_SIZE))

Nit: Adding the check is also an unrelated change, so would require a
separate patch.

> +		dev_warn(dev, "Dropping oversized frame\n");
> +		return;
> +	}
>  
>  	print_hex_dump(KERN_DEBUG, "rave-sp rx: ", DUMP_PREFIX_NONE,
>  		       16, 1, data, length, false);

-- 
Lee Jones [李琼斯]
Linaro Services Technical Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog

  parent reply	other threads:[~2018-04-24  5:43 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-23 20:02 Kyle Spiers
2018-04-23 20:08 ` Kees Cook
2018-04-24  5:43 ` Lee Jones [this message]
2018-04-24 16:07   ` Kees Cook
2018-04-25 10:31     ` Lee Jones
2018-04-25 16:51       ` Kyle Spiers
2018-04-26  7:44         ` Lee Jones

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=20180424054315.2yjpnht5pu62i54q@dell \
    --to=lee.jones@linaro.org \
    --cc=keescook@chromium.org \
    --cc=ksspiers@google.com \
    --cc=linux-kernel@vger.kernel.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

all inboxes | Powered by JetHome®