From: walter harms <wharms@bfs.de>
To: Dan Carpenter <dan.carpenter@oracle.com>
Cc: Linus Walleij <linus.walleij@linaro.org>,
Alexandre Courbot <gnurou@gmail.com>,
linux-gpio@vger.kernel.org, kernel-janitors@vger.kernel.org
Subject: Re: [patch] gpiolib: potential oops on failure path
Date: Fri, 17 Jun 2016 09:28:33 +0000 [thread overview]
Message-ID: <5763C2C1.8000505@bfs.de> (raw)
In-Reply-To: <20160617091550.GB25609@mwanda>
Am 17.06.2016 11:15, schrieb Dan Carpenter:
> If anon_inode_getfd() fails then "i" is set to GPIOHANDLES_MAX. It
> means that we will read beyond the end of the array and dereference an
> invalid pointer.
>
> Fixes: d7c51b47ac11 ('gpio: userspace ABI for reading/writing GPIO lines')
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
>
> diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
> index 8b3db59..8578b7f 100644
> --- a/drivers/gpio/gpiolib.c
> +++ b/drivers/gpio/gpiolib.c
> @@ -495,6 +495,8 @@ static int linehandle_create(struct gpio_device *gdev, void __user *ip)
> return 0;
>
> out_free_descs:
> + if (i = GPIOHANDLES_MAX)
> + i--;
> for (; i >= 0; i--)
> gpiod_free(lh->descs[i]);
> kfree(lh->label);
Since we have already noticed that programmes are bad at counting backwards
is it possible to change the loop into counting up ?
btw: if lh->descs[i] is initialized to NULL it would be more robust just to free everything like:
for(i=0;i< GPIOHANDLES_MAX; i++)
gpiod_free(lh->descs[i]);
just my two cents,
re,
wh
next prev parent reply other threads:[~2016-06-17 9:28 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-06-17 9:15 [patch] gpiolib: potential oops on failure path Dan Carpenter
2016-06-17 9:28 ` walter harms [this message]
2016-06-17 9:59 ` Dan Carpenter
2016-06-18 8:54 ` Linus Walleij
2016-06-18 8:52 ` Linus Walleij
2016-06-18 8:57 ` Linus Walleij
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=5763C2C1.8000505@bfs.de \
--to=wharms@bfs.de \
--cc=dan.carpenter@oracle.com \
--cc=gnurou@gmail.com \
--cc=kernel-janitors@vger.kernel.org \
--cc=linus.walleij@linaro.org \
--cc=linux-gpio@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