[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20170717195325.xwvv4jj4zcghqndh@mwanda>
Date: Mon, 17 Jul 2017 22:53:25 +0300
From: Dan Carpenter <dan.carpenter@...cle.com>
To: Jacob von Chorus <jacobvonchorus@...hoto.ca>
Cc: Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
Insop Song <insop.song@...nspeed.com>,
devel@...verdev.osuosl.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH] staging: gs_fpgaboot: add buffer overflow checks
On Sun, Jul 16, 2017 at 08:38:41PM -0400, Jacob von Chorus wrote:
> diff --git a/drivers/staging/gs_fpgaboot/gs_fpgaboot.c b/drivers/staging/gs_fpgaboot/gs_fpgaboot.c
> index 19b550fff0..2aafd769b8 100644
> --- a/drivers/staging/gs_fpgaboot/gs_fpgaboot.c
> +++ b/drivers/staging/gs_fpgaboot/gs_fpgaboot.c
> @@ -47,7 +47,7 @@ static void read_bitstream(char *bitdata, char *buf, int *offset, int rdsize)
> *offset += rdsize;
> }
>
> -static void readinfo_bitstream(char *bitdata, char *buf, int *offset)
> +static int readinfo_bitstream(char *bitdata, char *buf, int n, int *offset)
Choose a better name than "n" like "size".
> {
> char tbuf[64];
> s32 len;
> @@ -59,9 +59,15 @@ static void readinfo_bitstream(char *bitdata, char *buf, int *offset)
> read_bitstream(bitdata, tbuf, offset, 2);
>
> len = tbuf[0] << 8 | tbuf[1];
Since tbuf is char then, on x86 and arm, that means it's signed and it
means "len" can be negative. Declare tbuf as u8. Which will require
other changes as well...
> + if (len + 1 > n) {
It's more idiomatic to say "if (len >= n)". Plus that's a good habbit
if you want to avoid integer overflows.
> + pr_err("error: readinfo buffer too small\n");
> + return -1;
-1 is not a correct error code.
regards,
dan carpenter
Powered by blists - more mailing lists