From: Heikki Krogerus <heikki.krogerus@linux.intel.com>
To: Kees Cook <keescook@chromium.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org
Subject: usb: typec: tps6598x: Remove VLA usage
Date: Thu, 21 Jun 2018 13:00:03 +0300 [thread overview]
Message-ID: <20180621100003.GF2847@kuha.fi.intel.com> (raw)
On Wed, Jun 20, 2018 at 11:28:40AM -0700, Kees Cook wrote:
> In the quest to remove all stack VLA usage from the kernel[1], this
> uses the maximum buffer size and adds a sanity check.
>
> [1] https://lkml.kernel.org/r/CA+55aFzCG-zNmZwX4A2FQpadafLfEzK6CC=qPXydAacU1RqZWA@mail.gmail.com
>
> Signed-off-by: Kees Cook <keescook@chromium.org>
> ---
> drivers/usb/typec/tps6598x.c | 7 ++++++-
> 1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/usb/typec/tps6598x.c b/drivers/usb/typec/tps6598x.c
> index 4b4c8d271b27..396193f85e6d 100644
> --- a/drivers/usb/typec/tps6598x.c
> +++ b/drivers/usb/typec/tps6598x.c
> @@ -81,12 +81,17 @@ struct tps6598x {
> struct typec_capability typec_cap;
> };
>
> +#define TPS_MAX_LEN sizeof(u64)
That is not big enough. The registers of this chip can be as big as 64
bytes. The identity register alone is 25 bytes, so the above would
make the driver fail quite fast. Can you set the maximum to 64?
#define TPS_MAX_LEN 64
> static int
> tps6598x_block_read(struct tps6598x *tps, u8 reg, void *val, size_t len)
> {
> - u8 data[len + 1];
> + u8 data[TPS_MAX_LEN + 1];
> int ret;
>
> + if (WARN_ON(len + 1 > sizeof(data)))
> + return -EINVAL;
> +
> if (!tps->i2c_protocol)
> return regmap_raw_read(tps->regmap, reg, val, len);
Thanks,
WARNING: multiple messages have this Message-ID (diff)
From: Heikki Krogerus <heikki.krogerus@linux.intel.com>
To: Kees Cook <keescook@chromium.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org
Subject: Re: [PATCH] usb: typec: tps6598x: Remove VLA usage
Date: Thu, 21 Jun 2018 13:00:03 +0300 [thread overview]
Message-ID: <20180621100003.GF2847@kuha.fi.intel.com> (raw)
In-Reply-To: <20180620182840.GA24775@beast>
On Wed, Jun 20, 2018 at 11:28:40AM -0700, Kees Cook wrote:
> In the quest to remove all stack VLA usage from the kernel[1], this
> uses the maximum buffer size and adds a sanity check.
>
> [1] https://lkml.kernel.org/r/CA+55aFzCG-zNmZwX4A2FQpadafLfEzK6CC=qPXydAacU1RqZWA@mail.gmail.com
>
> Signed-off-by: Kees Cook <keescook@chromium.org>
> ---
> drivers/usb/typec/tps6598x.c | 7 ++++++-
> 1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/usb/typec/tps6598x.c b/drivers/usb/typec/tps6598x.c
> index 4b4c8d271b27..396193f85e6d 100644
> --- a/drivers/usb/typec/tps6598x.c
> +++ b/drivers/usb/typec/tps6598x.c
> @@ -81,12 +81,17 @@ struct tps6598x {
> struct typec_capability typec_cap;
> };
>
> +#define TPS_MAX_LEN sizeof(u64)
That is not big enough. The registers of this chip can be as big as 64
bytes. The identity register alone is 25 bytes, so the above would
make the driver fail quite fast. Can you set the maximum to 64?
#define TPS_MAX_LEN 64
> static int
> tps6598x_block_read(struct tps6598x *tps, u8 reg, void *val, size_t len)
> {
> - u8 data[len + 1];
> + u8 data[TPS_MAX_LEN + 1];
> int ret;
>
> + if (WARN_ON(len + 1 > sizeof(data)))
> + return -EINVAL;
> +
> if (!tps->i2c_protocol)
> return regmap_raw_read(tps->regmap, reg, val, len);
Thanks,
--
heikki
next reply other threads:[~2018-06-21 10:00 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-06-21 10:00 Heikki Krogerus [this message]
2018-06-21 10:00 ` [PATCH] usb: typec: tps6598x: Remove VLA usage Heikki Krogerus
-- strict thread matches above, loose matches on Subject: below --
2018-06-25 14:44 Heikki Krogerus
2018-06-25 14:44 ` [PATCH] " Heikki Krogerus
2018-06-21 20:31 Kees Cook
2018-06-21 20:31 ` [PATCH] " Kees Cook
2018-06-20 18:28 Kees Cook
2018-06-20 18:28 ` [PATCH] " Kees Cook
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=20180621100003.GF2847@kuha.fi.intel.com \
--to=heikki.krogerus@linux.intel.com \
--cc=gregkh@linuxfoundation.org \
--cc=keescook@chromium.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.