All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mtd: nand: fix NULL pointer dereference in of_get_nand_ecc_algo
@ 2016-04-26 18:36 Rafał Miłecki
  2016-04-26 18:53 ` Boris Brezillon
  2016-04-26 21:16 ` [PATCH V2] " Rafał Miłecki
  0 siblings, 2 replies; 5+ messages in thread
From: Rafał Miłecki @ 2016-04-26 18:36 UTC (permalink / raw)
  To: Boris Brezillon
  Cc: linux-mtd, Rafał Miłecki, Richard Weinberger,
	David Woodhouse, Brian Norris, open list

Our array nand_ecc_algos doesn't specify mappings for all available
enum nand_ecc_algo values. The one missing there is NAND_ECC_UNKNOWN
as this value is reserved for algorithm not being specified at all.
It means we have to be careful when iterating this array and handle
NULL values.

Signed-off-by: Rafał Miłecki <zajec5@gmail.com>
---
Hi Boris,

Sorry for this crash in nand subsystem :( If you think it's OK you may
pick this patch as a fixup for
c6e002a7ca9f ("mtd: nand: add support for "nand-ecc-algo" DT property")
---
 drivers/mtd/nand/nand_base.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c
index a5417a0..0eaa9dc 100644
--- a/drivers/mtd/nand/nand_base.c
+++ b/drivers/mtd/nand/nand_base.c
@@ -4016,6 +4016,8 @@ static int of_get_nand_ecc_algo(struct device_node *np)
 	err = of_property_read_string(np, "nand-ecc-algo", &pm);
 	if (!err) {
 		for (i = 0; i < ARRAY_SIZE(nand_ecc_algos); i++)
+			if (!nand_ecc_algos[i])
+				continue;
 			if (!strcasecmp(pm, nand_ecc_algos[i]))
 				return i;
 		return -ENODEV;
-- 
1.8.4.5

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] mtd: nand: fix NULL pointer dereference in of_get_nand_ecc_algo
  2016-04-26 18:36 [PATCH] mtd: nand: fix NULL pointer dereference in of_get_nand_ecc_algo Rafał Miłecki
@ 2016-04-26 18:53 ` Boris Brezillon
  2016-04-26 19:57   ` Rafał Miłecki
  2016-04-26 21:16 ` [PATCH V2] " Rafał Miłecki
  1 sibling, 1 reply; 5+ messages in thread
From: Boris Brezillon @ 2016-04-26 18:53 UTC (permalink / raw)
  To: Rafał Miłecki
  Cc: linux-mtd, Richard Weinberger, David Woodhouse, Brian Norris, open list

On Tue, 26 Apr 2016 20:36:16 +0200
Rafał Miłecki <zajec5@gmail.com> wrote:

> Our array nand_ecc_algos doesn't specify mappings for all available
> enum nand_ecc_algo values. The one missing there is NAND_ECC_UNKNOWN
> as this value is reserved for algorithm not being specified at all.
> It means we have to be careful when iterating this array and handle
> NULL values.
> 
> Signed-off-by: Rafał Miłecki <zajec5@gmail.com>
> ---
> Hi Boris,
> 
> Sorry for this crash in nand subsystem :( If you think it's OK you may
> pick this patch as a fixup for
> c6e002a7ca9f ("mtd: nand: add support for "nand-ecc-algo" DT property")
> ---
>  drivers/mtd/nand/nand_base.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c
> index a5417a0..0eaa9dc 100644
> --- a/drivers/mtd/nand/nand_base.c
> +++ b/drivers/mtd/nand/nand_base.c
> @@ -4016,6 +4016,8 @@ static int of_get_nand_ecc_algo(struct device_node *np)
>  	err = of_property_read_string(np, "nand-ecc-algo", &pm);
>  	if (!err) {
>  		for (i = 0; i < ARRAY_SIZE(nand_ecc_algos); i++)
> +			if (!nand_ecc_algos[i])
> +				continue;

Can we add an "unknown" entry, or start iterating at NAND_ECC_HAMMING
or NAND_ECC_UNKNOWN + 1 instead of adding this extra test?

BTW, since the original commit has been applied recently I'll squash the
changes into the previous commit and rebase my branch instead of adding
a new patch (I hate breaking bisectability).


-- 
Boris Brezillon, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] mtd: nand: fix NULL pointer dereference in of_get_nand_ecc_algo
  2016-04-26 18:53 ` Boris Brezillon
@ 2016-04-26 19:57   ` Rafał Miłecki
  0 siblings, 0 replies; 5+ messages in thread
From: Rafał Miłecki @ 2016-04-26 19:57 UTC (permalink / raw)
  To: Boris Brezillon
  Cc: linux-mtd, Richard Weinberger, David Woodhouse, Brian Norris, open list

On 26 April 2016 at 20:53, Boris Brezillon
<boris.brezillon@free-electrons.com> wrote:
> On Tue, 26 Apr 2016 20:36:16 +0200
> Rafał Miłecki <zajec5@gmail.com> wrote:
>
>> Our array nand_ecc_algos doesn't specify mappings for all available
>> enum nand_ecc_algo values. The one missing there is NAND_ECC_UNKNOWN
>> as this value is reserved for algorithm not being specified at all.
>> It means we have to be careful when iterating this array and handle
>> NULL values.
>>
>> Signed-off-by: Rafał Miłecki <zajec5@gmail.com>
>> ---
>> Hi Boris,
>>
>> Sorry for this crash in nand subsystem :( If you think it's OK you may
>> pick this patch as a fixup for
>> c6e002a7ca9f ("mtd: nand: add support for "nand-ecc-algo" DT property")
>> ---
>>  drivers/mtd/nand/nand_base.c | 2 ++
>>  1 file changed, 2 insertions(+)
>>
>> diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c
>> index a5417a0..0eaa9dc 100644
>> --- a/drivers/mtd/nand/nand_base.c
>> +++ b/drivers/mtd/nand/nand_base.c
>> @@ -4016,6 +4016,8 @@ static int of_get_nand_ecc_algo(struct device_node *np)
>>       err = of_property_read_string(np, "nand-ecc-algo", &pm);
>>       if (!err) {
>>               for (i = 0; i < ARRAY_SIZE(nand_ecc_algos); i++)
>> +                     if (!nand_ecc_algos[i])
>> +                             continue;
>
> Can we add an "unknown" entry, or start iterating at NAND_ECC_HAMMING
> or NAND_ECC_UNKNOWN + 1 instead of adding this extra test?

Sure, if you think it's better. I'll send V2.

-- 
Rafał

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH V2] mtd: nand: fix NULL pointer dereference in of_get_nand_ecc_algo
  2016-04-26 18:36 [PATCH] mtd: nand: fix NULL pointer dereference in of_get_nand_ecc_algo Rafał Miłecki
  2016-04-26 18:53 ` Boris Brezillon
@ 2016-04-26 21:16 ` Rafał Miłecki
  2016-04-27  7:54   ` Boris Brezillon
  1 sibling, 1 reply; 5+ messages in thread
From: Rafał Miłecki @ 2016-04-26 21:16 UTC (permalink / raw)
  To: Boris Brezillon
  Cc: linux-mtd, Rafał Miłecki, Richard Weinberger,
	David Woodhouse, Brian Norris, open list

Our array nand_ecc_algos doesn't specify mappings for all available
enum nand_ecc_algo values. The one missing there is NAND_ECC_UNKNOWN
as this value is reserved for algorithm not being specified at all.
It means we have to be careful when iterating this array and avoid
NULL values.

Signed-off-by: Rafał Miłecki <zajec5@gmail.com>
---
V2: Iterate from NAND_ECC_HAMMING instead of checking for NULL as preferred by
Boris.
---
 drivers/mtd/nand/nand_base.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c
index a5417a0..2e6ba44 100644
--- a/drivers/mtd/nand/nand_base.c
+++ b/drivers/mtd/nand/nand_base.c
@@ -4015,7 +4015,7 @@ static int of_get_nand_ecc_algo(struct device_node *np)
 
 	err = of_property_read_string(np, "nand-ecc-algo", &pm);
 	if (!err) {
-		for (i = 0; i < ARRAY_SIZE(nand_ecc_algos); i++)
+		for (i = NAND_ECC_HAMMING; i < ARRAY_SIZE(nand_ecc_algos); i++)
 			if (!strcasecmp(pm, nand_ecc_algos[i]))
 				return i;
 		return -ENODEV;
-- 
1.8.4.5

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH V2] mtd: nand: fix NULL pointer dereference in of_get_nand_ecc_algo
  2016-04-26 21:16 ` [PATCH V2] " Rafał Miłecki
@ 2016-04-27  7:54   ` Boris Brezillon
  0 siblings, 0 replies; 5+ messages in thread
From: Boris Brezillon @ 2016-04-27  7:54 UTC (permalink / raw)
  To: Rafał Miłecki
  Cc: linux-mtd, Richard Weinberger, David Woodhouse, Brian Norris, open list

On Tue, 26 Apr 2016 23:16:47 +0200
Rafał Miłecki <zajec5@gmail.com> wrote:

> Our array nand_ecc_algos doesn't specify mappings for all available
> enum nand_ecc_algo values. The one missing there is NAND_ECC_UNKNOWN
> as this value is reserved for algorithm not being specified at all.
> It means we have to be careful when iterating this array and avoid
> NULL values.
> 
> Signed-off-by: Rafał Miłecki <zajec5@gmail.com>

Changes squashed into "mtd: nand: add support for "nand-ecc-algo" DT
property".

Thanks,

Boris

> ---
> V2: Iterate from NAND_ECC_HAMMING instead of checking for NULL as preferred by
> Boris.
> ---
>  drivers/mtd/nand/nand_base.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c
> index a5417a0..2e6ba44 100644
> --- a/drivers/mtd/nand/nand_base.c
> +++ b/drivers/mtd/nand/nand_base.c
> @@ -4015,7 +4015,7 @@ static int of_get_nand_ecc_algo(struct device_node *np)
>  
>  	err = of_property_read_string(np, "nand-ecc-algo", &pm);
>  	if (!err) {
> -		for (i = 0; i < ARRAY_SIZE(nand_ecc_algos); i++)
> +		for (i = NAND_ECC_HAMMING; i < ARRAY_SIZE(nand_ecc_algos); i++)
>  			if (!strcasecmp(pm, nand_ecc_algos[i]))
>  				return i;
>  		return -ENODEV;



-- 
Boris Brezillon, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2016-04-27  7:54 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-04-26 18:36 [PATCH] mtd: nand: fix NULL pointer dereference in of_get_nand_ecc_algo Rafał Miłecki
2016-04-26 18:53 ` Boris Brezillon
2016-04-26 19:57   ` Rafał Miłecki
2016-04-26 21:16 ` [PATCH V2] " Rafał Miłecki
2016-04-27  7:54   ` Boris Brezillon

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.