All of lore.kernel.org
 help / color / mirror / Atom feed
From: Miquel Raynal <miquel.raynal@bootlin.com>
To: Colin Ian King <colin.king@canonical.com>
Cc: Stefan Agner <stefan@agner.ch>, Lucas Stach <dev@lynxeye.de>,
	Dmitry Osipenko <digetx@gmail.com>,
	Boris Brezillon <boris.brezillon@bootlin.com>,
	"kernel-janitors@vger.kernel.org"
	<kernel-janitors@vger.kernel.org>,
	linux-mtd@lists.infradead.org
Subject: Re: mtd: rawnand: add NVIDIA Tegra NAND Flash controller driver
Date: Wed, 27 Jun 2018 06:52:57 +0000	[thread overview]
Message-ID: <20180627085257.67aa1eb8@xps13> (raw)
In-Reply-To: <993e40ac-1f06-c2ee-e9fb-4523df368cb7@canonical.com>

Hi Colin, Stefan,

+linux-mtd

Thanks Colin for the report.

On Tue, 26 Jun 2018 16:18:29 +0100, Colin Ian King
<colin.king@canonical.com> wrote:

> Hi there,
> 
> Static analysis with CoverityScan reported a potential issue with the
> following commit:
> 
> commit 0f7b126ca91101d02d525f7cc880e8c71202a2b7
> Author: Stefan Agner <stefan@agner.ch>
> Date:   Sun Jun 24 23:27:25 2018 +0200
> 
>     mtd: rawnand: add NVIDIA Tegra NAND Flash controller driver
> 
> 
> in function tegra_nand_cmd it looks like there maybe potential to pass a
> negative value in size into memcpy():
> 
>         case NAND_OP_DATA_OUT_INSTR:
> 
> negative_return_fn: Function nand_subop_get_data_len(subop, op_id)
> returns a negative number.
> 
> var_assign: Assigning: unsigned variable size = nand_subop_get_data_len.
> 
>                 size = nand_subop_get_data_len(subop, op_id);
>                 offset = nand_subop_get_data_start_off(subop, op_id);

Stefan,

I thought a bit about this and I don't think the right place for such a
fix are the NAND controller drivers (marvell and vf610 have the same
issue). Both nand_subop_get_data/addr_len/start_off() are core helpers
and their result is predictable in a manner that only a bug in your
parsing function would trigger an error value. I think this is safe for
the four helpers to have WARN_ON() on the error conditions to catch
the developer's attention and just return (unsigned int) 0 in this case.

I will propose something soon.

Thanks,
Miquèl
--
To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

WARNING: multiple messages have this Message-ID (diff)
From: Miquel Raynal <miquel.raynal@bootlin.com>
To: Colin Ian King <colin.king@canonical.com>
Cc: Stefan Agner <stefan@agner.ch>, Lucas Stach <dev@lynxeye.de>,
	Dmitry Osipenko <digetx@gmail.com>,
	Boris Brezillon <boris.brezillon@bootlin.com>,
	"kernel-janitors@vger.kernel.org"
	<kernel-janitors@vger.kernel.org>,
	linux-mtd@lists.infradead.org
Subject: Re: mtd: rawnand: add NVIDIA Tegra NAND Flash controller driver
Date: Wed, 27 Jun 2018 08:52:57 +0200	[thread overview]
Message-ID: <20180627085257.67aa1eb8@xps13> (raw)
In-Reply-To: <993e40ac-1f06-c2ee-e9fb-4523df368cb7@canonical.com>

Hi Colin, Stefan,

+linux-mtd

Thanks Colin for the report.

On Tue, 26 Jun 2018 16:18:29 +0100, Colin Ian King
<colin.king@canonical.com> wrote:

> Hi there,
> 
> Static analysis with CoverityScan reported a potential issue with the
> following commit:
> 
> commit 0f7b126ca91101d02d525f7cc880e8c71202a2b7
> Author: Stefan Agner <stefan@agner.ch>
> Date:   Sun Jun 24 23:27:25 2018 +0200
> 
>     mtd: rawnand: add NVIDIA Tegra NAND Flash controller driver
> 
> 
> in function tegra_nand_cmd it looks like there maybe potential to pass a
> negative value in size into memcpy():
> 
>         case NAND_OP_DATA_OUT_INSTR:
> 
> negative_return_fn: Function nand_subop_get_data_len(subop, op_id)
> returns a negative number.
> 
> var_assign: Assigning: unsigned variable size = nand_subop_get_data_len.
> 
>                 size = nand_subop_get_data_len(subop, op_id);
>                 offset = nand_subop_get_data_start_off(subop, op_id);

Stefan,

I thought a bit about this and I don't think the right place for such a
fix are the NAND controller drivers (marvell and vf610 have the same
issue). Both nand_subop_get_data/addr_len/start_off() are core helpers
and their result is predictable in a manner that only a bug in your
parsing function would trigger an error value. I think this is safe for
the four helpers to have WARN_ON() on the error conditions to catch
the developer's attention and just return (unsigned int) 0 in this case.

I will propose something soon.

Thanks,
Miquèl

  reply	other threads:[~2018-06-27  6:52 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-26 15:18 mtd: rawnand: add NVIDIA Tegra NAND Flash controller driver Colin Ian King
2018-06-27  6:52 ` Miquel Raynal [this message]
2018-06-27  6:52   ` Miquel Raynal

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=20180627085257.67aa1eb8@xps13 \
    --to=miquel.raynal@bootlin.com \
    --cc=boris.brezillon@bootlin.com \
    --cc=colin.king@canonical.com \
    --cc=dev@lynxeye.de \
    --cc=digetx@gmail.com \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-mtd@lists.infradead.org \
    --cc=stefan@agner.ch \
    /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.