linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] staging: lustre: lustre: obdclass: lprocfs_status.c:  Fix for possible null pointer dereference
@ 2014-12-14 22:52 Rickard Strandqvist
  2014-12-15  1:51 ` Joe Perches
  2014-12-16  4:40 ` Chris Rorvick
  0 siblings, 2 replies; 10+ messages in thread
From: Rickard Strandqvist @ 2014-12-14 22:52 UTC (permalink / raw)
  To: Oleg Drokin, Andreas Dilger
  Cc: Rickard Strandqvist, Greg Kroah-Hartman, Julia Lawall,
	Greg Donald, John L. Hammond, Andriy Skulysh, Fabian Frederick,
	James Simmons, HPDD-discuss, devel, linux-kernel

There is otherwise a risk of a possible null pointer dereference.

Was largely found by using a static code analysis program called cppcheck.

Signed-off-by: Rickard Strandqvist <rickard_strandqvist@spectrumdigital.se>
---
 .../lustre/lustre/obdclass/lprocfs_status.c        |   24 +++++++++++---------
 1 file changed, 13 insertions(+), 11 deletions(-)

diff --git a/drivers/staging/lustre/lustre/obdclass/lprocfs_status.c b/drivers/staging/lustre/lustre/obdclass/lprocfs_status.c
index 61e04af..5227324 100644
--- a/drivers/staging/lustre/lustre/obdclass/lprocfs_status.c
+++ b/drivers/staging/lustre/lustre/obdclass/lprocfs_status.c
@@ -1897,17 +1897,19 @@ int lprocfs_write_frac_u64_helper(const char *buffer, unsigned long count,
 	}
 
 	units = 1;
-	switch (*end) {
-	case 'p': case 'P':
-		units <<= 10;
-	case 't': case 'T':
-		units <<= 10;
-	case 'g': case 'G':
-		units <<= 10;
-	case 'm': case 'M':
-		units <<= 10;
-	case 'k': case 'K':
-		units <<= 10;
+	if (end) {
+		switch (*end) {
+		case 'p': case 'P':
+			units <<= 10;
+		case 't': case 'T':
+			units <<= 10;
+		case 'g': case 'G':
+			units <<= 10;
+		case 'm': case 'M':
+			units <<= 10;
+		case 'k': case 'K':
+			units <<= 10;
+		}
 	}
 	/* Specified units override the multiplier */
 	if (units)
-- 
1.7.10.4


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

* Re: [PATCH] staging: lustre: lustre: obdclass: lprocfs_status.c:  Fix for possible null pointer dereference
  2014-12-14 22:52 [PATCH] staging: lustre: lustre: obdclass: lprocfs_status.c: Fix for possible null pointer dereference Rickard Strandqvist
@ 2014-12-15  1:51 ` Joe Perches
  2014-12-15 22:23   ` Rickard Strandqvist
  2014-12-16  4:40 ` Chris Rorvick
  1 sibling, 1 reply; 10+ messages in thread
From: Joe Perches @ 2014-12-15  1:51 UTC (permalink / raw)
  To: Rickard Strandqvist
  Cc: Oleg Drokin, Andreas Dilger, Greg Kroah-Hartman, Julia Lawall,
	Greg Donald, John L. Hammond, Andriy Skulysh, Fabian Frederick,
	James Simmons, HPDD-discuss, devel, linux-kernel

On Sun, 2014-12-14 at 23:52 +0100, Rickard Strandqvist wrote:
> There is otherwise a risk of a possible null pointer dereference.
> 
> Was largely found by using a static code analysis program called cppcheck.

Perhaps the tool could use a little work.
It's not possible for end to be NULL no?

unsigned long long simple_strtoull(const char *cp, char **endp, unsigned int base)
{
	unsigned long long result;
	unsigned int rv;

	cp = _parse_integer_fixup_radix(cp, &base);
	rv = _parse_integer(cp, base, &result);
	/* FIXME */
	cp += (rv & ~KSTRTOX_OVERFLOW);

	if (endp)
		*endp = (char *)cp;

	return result;
}
EXPORT_SYMBOL(simple_strtoull);


> diff --git a/drivers/staging/lustre/lustre/obdclass/lprocfs_status.c b/drivers/staging/lustre/lustre/obdclass/lprocfs_status.c
[]

Above this:

	whole = simple_strtoull(pbuf, &end, 10);

> +++ b/drivers/staging/lustre/lustre/obdclass/lprocfs_status.c
> @@ -1897,17 +1897,19 @@ int lprocfs_write_frac_u64_helper(const char *buffer, unsigned long count,
>  	}
>  
>  	units = 1;
> -	switch (*end) {
> -	case 'p': case 'P':
> -		units <<= 10;
> -	case 't': case 'T':
> -		units <<= 10;
> -	case 'g': case 'G':
> -		units <<= 10;
> -	case 'm': case 'M':
> -		units <<= 10;
> -	case 'k': case 'K':
> -		units <<= 10;
> +	if (end) {
> +		switch (*end) {
> +		case 'p': case 'P':
> +			units <<= 10;
> +		case 't': case 'T':
> +			units <<= 10;
> +		case 'g': case 'G':
> +			units <<= 10;
> +		case 'm': case 'M':
> +			units <<= 10;
> +		case 'k': case 'K':
> +			units <<= 10;
> +		}

The only thing I might do is

	switch (tolower(*end)) {

and remove the second case entry for each line


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

* Re: [PATCH] staging: lustre: lustre: obdclass: lprocfs_status.c: Fix for possible null pointer dereference
  2014-12-15  1:51 ` Joe Perches
@ 2014-12-15 22:23   ` Rickard Strandqvist
  2014-12-15 23:53     ` Joe Perches
  2014-12-16  9:27     ` Dan Carpenter
  0 siblings, 2 replies; 10+ messages in thread
From: Rickard Strandqvist @ 2014-12-15 22:23 UTC (permalink / raw)
  To: Joe Perches
  Cc: Oleg Drokin, Andreas Dilger, Greg Kroah-Hartman, Julia Lawall,
	Greg Donald, John L. Hammond, Andriy Skulysh, Fabian Frederick,
	James Simmons, HPDD-discuss, devel, linux-kernel

Hi Joe

No, it does not look like end can be NULL then.
Then remove the end != NULL instead?
...
    if (end != NULL && *end == '.') {


However, I am hesitant to the tolower()  I think double case is faster...?


Kind regards
Rickard Strandqvist


2014-12-15 2:51 GMT+01:00 Joe Perches <joe@perches.com>:
> On Sun, 2014-12-14 at 23:52 +0100, Rickard Strandqvist wrote:
>> There is otherwise a risk of a possible null pointer dereference.
>>
>> Was largely found by using a static code analysis program called cppcheck.
>
> Perhaps the tool could use a little work.
> It's not possible for end to be NULL no?
>
> unsigned long long simple_strtoull(const char *cp, char **endp, unsigned int base)
> {
>         unsigned long long result;
>         unsigned int rv;
>
>         cp = _parse_integer_fixup_radix(cp, &base);
>         rv = _parse_integer(cp, base, &result);
>         /* FIXME */
>         cp += (rv & ~KSTRTOX_OVERFLOW);
>
>         if (endp)
>                 *endp = (char *)cp;
>
>         return result;
> }
> EXPORT_SYMBOL(simple_strtoull);
>
>
>> diff --git a/drivers/staging/lustre/lustre/obdclass/lprocfs_status.c b/drivers/staging/lustre/lustre/obdclass/lprocfs_status.c
> []
>
> Above this:
>
>         whole = simple_strtoull(pbuf, &end, 10);
>
>> +++ b/drivers/staging/lustre/lustre/obdclass/lprocfs_status.c
>> @@ -1897,17 +1897,19 @@ int lprocfs_write_frac_u64_helper(const char *buffer, unsigned long count,
>>       }
>>
>>       units = 1;
>> -     switch (*end) {
>> -     case 'p': case 'P':
>> -             units <<= 10;
>> -     case 't': case 'T':
>> -             units <<= 10;
>> -     case 'g': case 'G':
>> -             units <<= 10;
>> -     case 'm': case 'M':
>> -             units <<= 10;
>> -     case 'k': case 'K':
>> -             units <<= 10;
>> +     if (end) {
>> +             switch (*end) {
>> +             case 'p': case 'P':
>> +                     units <<= 10;
>> +             case 't': case 'T':
>> +                     units <<= 10;
>> +             case 'g': case 'G':
>> +                     units <<= 10;
>> +             case 'm': case 'M':
>> +                     units <<= 10;
>> +             case 'k': case 'K':
>> +                     units <<= 10;
>> +             }
>
> The only thing I might do is
>
>         switch (tolower(*end)) {
>
> and remove the second case entry for each line
>

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

* Re: [PATCH] staging: lustre: lustre: obdclass: lprocfs_status.c: Fix for possible null pointer dereference
  2014-12-15 22:23   ` Rickard Strandqvist
@ 2014-12-15 23:53     ` Joe Perches
  2014-12-16  3:08       ` [HPDD-discuss] " Patrick Farrell
  2014-12-16  9:27     ` Dan Carpenter
  1 sibling, 1 reply; 10+ messages in thread
From: Joe Perches @ 2014-12-15 23:53 UTC (permalink / raw)
  To: Rickard Strandqvist
  Cc: Oleg Drokin, Andreas Dilger, Greg Kroah-Hartman, Julia Lawall,
	Greg Donald, John L. Hammond, Andriy Skulysh, Fabian Frederick,
	James Simmons, HPDD-discuss, devel, linux-kernel

On Mon, 2014-12-15 at 23:23 +0100, Rickard Strandqvist wrote:
> Hi Joe

Hello Rickard

> No, it does not look like end can be NULL then.
> Then remove the end != NULL instead?
> ...
>     if (end != NULL && *end == '.') {

Up to you.

> However, I am hesitant to the tolower()  I think double case is faster...?

I doubt code execution speed is paramount here.
Maybe see if the object code size is smaller one
way or the other.



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

* RE: [HPDD-discuss] [PATCH] staging: lustre: lustre: obdclass: lprocfs_status.c: Fix for possible null pointer dereference
  2014-12-15 23:53     ` Joe Perches
@ 2014-12-16  3:08       ` Patrick Farrell
  0 siblings, 0 replies; 10+ messages in thread
From: Patrick Farrell @ 2014-12-16  3:08 UTC (permalink / raw)
  To: Joe Perches, Rickard Strandqvist
  Cc: devel, Fabian Frederick, Julia Lawall, James Simmons,
	Greg Kroah-Hartman, linux-kernel, Greg Donald,
	HPDD-discuss@lists.01.org, Andriy Skulysh

Strongly agreed that execution speed is not critical here.  It's the update of a proc variable, not a tight loop or critical section.

Normally I'd leave it alone, but since you're writing a patch anyway, I'd do 'tolower' myself.  I dislike the stacked case statements on a single line like that.  (It's the only time I've seen them written that way.  Perhaps it's common and I've just missed it.)

Regards,
- Patrick
________________________________________
From: HPDD-discuss [hpdd-discuss-bounces@lists.01.org] on behalf of Joe Perches [joe@perches.com]
Sent: Monday, December 15, 2014 5:53 PM
To: Rickard Strandqvist
Cc: devel@driverdev.osuosl.org; Fabian Frederick; Julia Lawall; James Simmons; Greg Kroah-Hartman; linux-kernel@vger.kernel.org; Greg Donald; HPDD-discuss@lists.01.org; Andriy Skulysh
Subject: Re: [HPDD-discuss] [PATCH] staging: lustre: lustre: obdclass: lprocfs_status.c: Fix for possible null pointer dereference

On Mon, 2014-12-15 at 23:23 +0100, Rickard Strandqvist wrote:
> Hi Joe

Hello Rickard

> No, it does not look like end can be NULL then.
> Then remove the end != NULL instead?
> ...
>     if (end != NULL && *end == '.') {

Up to you.

> However, I am hesitant to the tolower()  I think double case is faster...?

I doubt code execution speed is paramount here.
Maybe see if the object code size is smaller one
way or the other.


_______________________________________________
HPDD-discuss mailing list
HPDD-discuss@lists.01.org
https://lists.01.org/mailman/listinfo/hpdd-discuss

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

* Re: [PATCH] staging: lustre: lustre: obdclass: lprocfs_status.c: Fix for possible null pointer dereference
  2014-12-14 22:52 [PATCH] staging: lustre: lustre: obdclass: lprocfs_status.c: Fix for possible null pointer dereference Rickard Strandqvist
  2014-12-15  1:51 ` Joe Perches
@ 2014-12-16  4:40 ` Chris Rorvick
  1 sibling, 0 replies; 10+ messages in thread
From: Chris Rorvick @ 2014-12-16  4:40 UTC (permalink / raw)
  To: Rickard Strandqvist
  Cc: Oleg Drokin, Andreas Dilger, Greg Kroah-Hartman, Julia Lawall,
	Greg Donald, John L. Hammond, Andriy Skulysh, Fabian Frederick,
	James Simmons, HPDD-discuss, devel, linux-kernel

On Sun, Dec 14, 2014 at 4:52 PM, Rickard Strandqvist
<rickard_strandqvist@spectrumdigital.se> wrote:
>         units = 1;
...
>         /* Specified units override the multiplier */
>         if (units)

That doesn't make much sense.  The conditional logic will always be
executed.  Maybe this is what's intended?

        /* Specified units override the multiplier */
-       if (units)
+       if (units > 1)
                mult = mult < 0 ? -units : units;

Chris

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

* Re: [PATCH] staging: lustre: lustre: obdclass: lprocfs_status.c: Fix for possible null pointer dereference
  2014-12-15 22:23   ` Rickard Strandqvist
  2014-12-15 23:53     ` Joe Perches
@ 2014-12-16  9:27     ` Dan Carpenter
  1 sibling, 0 replies; 10+ messages in thread
From: Dan Carpenter @ 2014-12-16  9:27 UTC (permalink / raw)
  To: Rickard Strandqvist
  Cc: Joe Perches, devel, Fabian Frederick, Andreas Dilger,
	Julia Lawall, James Simmons, Greg Kroah-Hartman, linux-kernel,
	Oleg Drokin, Greg Donald, HPDD-discuss, Andriy Skulysh,
	John L. Hammond

On Mon, Dec 15, 2014 at 11:23:25PM +0100, Rickard Strandqvist wrote:
> Hi Joe
> 
> No, it does not look like end can be NULL then.
> Then remove the end != NULL instead?
> ...
>     if (end != NULL && *end == '.') {
> 

Yes.  Please do.

regards,
dan carpenter


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

* Re: [PATCH] staging: lustre: lustre: obdclass: lprocfs_status.c: Fix for possible null pointer dereference
  2014-12-14 22:39 ` Greg Kroah-Hartman
@ 2014-12-14 22:43   ` Rickard Strandqvist
  0 siblings, 0 replies; 10+ messages in thread
From: Rickard Strandqvist @ 2014-12-14 22:43 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Oleg Drokin, Andreas Dilger, Julia Lawall, Greg Donald,
	John L. Hammond, Andriy Skulysh, Fabian Frederick, James Simmons,
	HPDD-discuss, devel, linux-kernel

Sorry! extremely stupid. Sending new patch immediately.

Kind regards
Rickard Strandqvist


2014-12-14 23:39 GMT+01:00 Greg Kroah-Hartman <gregkh@linuxfoundation.org>:
> On Sun, Dec 14, 2014 at 11:36:22PM +0100, Rickard Strandqvist wrote:
>> There is otherwise a risk of a possible null pointer dereference.
>>
>> Was largely found by using a static code analysis program called cppcheck.
>>
>> Signed-off-by: Rickard Strandqvist <rickard_strandqvist@spectrumdigital.se>
>> ---
>>  .../lustre/lustre/obdclass/lprocfs_status.c        |   20 +++++++++-----------
>>  1 file changed, 9 insertions(+), 11 deletions(-)
>>
>> diff --git a/drivers/staging/lustre/lustre/obdclass/lprocfs_status.c b/drivers/staging/lustre/lustre/obdclass/lprocfs_status.c
>> index 61e04af..4a7891a 100644
>> --- a/drivers/staging/lustre/lustre/obdclass/lprocfs_status.c
>> +++ b/drivers/staging/lustre/lustre/obdclass/lprocfs_status.c
>> @@ -1897,17 +1897,15 @@ int lprocfs_write_frac_u64_helper(const char *buffer, unsigned long count,
>>       }
>>
>>       units = 1;
>> -     switch (*end) {
>> -     case 'p': case 'P':
>> -             units <<= 10;
>> -     case 't': case 'T':
>> -             units <<= 10;
>> -     case 'g': case 'G':
>> -             units <<= 10;
>> -     case 'm': case 'M':
>> -             units <<= 10;
>> -     case 'k': case 'K':
>> -             units <<= 10;
>> +     if (end) {
>> +             switch (*end) {
>> +             case 'p': case 'P':
>> +             case 't': case 'T':
>> +             case 'g': case 'G':
>> +             case 'm': case 'M':
>> +             case 'k': case 'K':
>> +                     units <<= 10;
>> +             }
>
> You know you just changed the logic in the code, right?
>
> Why?  Have you tested this?
>
> greg k-h

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

* Re: [PATCH] staging: lustre: lustre: obdclass: lprocfs_status.c: Fix for possible null pointer dereference
  2014-12-14 22:36 Rickard Strandqvist
@ 2014-12-14 22:39 ` Greg Kroah-Hartman
  2014-12-14 22:43   ` Rickard Strandqvist
  0 siblings, 1 reply; 10+ messages in thread
From: Greg Kroah-Hartman @ 2014-12-14 22:39 UTC (permalink / raw)
  To: Rickard Strandqvist
  Cc: Oleg Drokin, Andreas Dilger, Julia Lawall, Greg Donald,
	John L. Hammond, Andriy Skulysh, Fabian Frederick, James Simmons,
	HPDD-discuss, devel, linux-kernel

On Sun, Dec 14, 2014 at 11:36:22PM +0100, Rickard Strandqvist wrote:
> There is otherwise a risk of a possible null pointer dereference.
> 
> Was largely found by using a static code analysis program called cppcheck.
> 
> Signed-off-by: Rickard Strandqvist <rickard_strandqvist@spectrumdigital.se>
> ---
>  .../lustre/lustre/obdclass/lprocfs_status.c        |   20 +++++++++-----------
>  1 file changed, 9 insertions(+), 11 deletions(-)
> 
> diff --git a/drivers/staging/lustre/lustre/obdclass/lprocfs_status.c b/drivers/staging/lustre/lustre/obdclass/lprocfs_status.c
> index 61e04af..4a7891a 100644
> --- a/drivers/staging/lustre/lustre/obdclass/lprocfs_status.c
> +++ b/drivers/staging/lustre/lustre/obdclass/lprocfs_status.c
> @@ -1897,17 +1897,15 @@ int lprocfs_write_frac_u64_helper(const char *buffer, unsigned long count,
>  	}
>  
>  	units = 1;
> -	switch (*end) {
> -	case 'p': case 'P':
> -		units <<= 10;
> -	case 't': case 'T':
> -		units <<= 10;
> -	case 'g': case 'G':
> -		units <<= 10;
> -	case 'm': case 'M':
> -		units <<= 10;
> -	case 'k': case 'K':
> -		units <<= 10;
> +	if (end) {
> +		switch (*end) {
> +		case 'p': case 'P':
> +		case 't': case 'T':
> +		case 'g': case 'G':
> +		case 'm': case 'M':
> +		case 'k': case 'K':
> +			units <<= 10;
> +		}

You know you just changed the logic in the code, right?

Why?  Have you tested this?

greg k-h

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

* [PATCH] staging: lustre: lustre: obdclass: lprocfs_status.c:  Fix for possible null pointer dereference
@ 2014-12-14 22:36 Rickard Strandqvist
  2014-12-14 22:39 ` Greg Kroah-Hartman
  0 siblings, 1 reply; 10+ messages in thread
From: Rickard Strandqvist @ 2014-12-14 22:36 UTC (permalink / raw)
  To: Oleg Drokin, Andreas Dilger
  Cc: Rickard Strandqvist, Greg Kroah-Hartman, Julia Lawall,
	Greg Donald, John L. Hammond, Andriy Skulysh, Fabian Frederick,
	James Simmons, HPDD-discuss, devel, linux-kernel

There is otherwise a risk of a possible null pointer dereference.

Was largely found by using a static code analysis program called cppcheck.

Signed-off-by: Rickard Strandqvist <rickard_strandqvist@spectrumdigital.se>
---
 .../lustre/lustre/obdclass/lprocfs_status.c        |   20 +++++++++-----------
 1 file changed, 9 insertions(+), 11 deletions(-)

diff --git a/drivers/staging/lustre/lustre/obdclass/lprocfs_status.c b/drivers/staging/lustre/lustre/obdclass/lprocfs_status.c
index 61e04af..4a7891a 100644
--- a/drivers/staging/lustre/lustre/obdclass/lprocfs_status.c
+++ b/drivers/staging/lustre/lustre/obdclass/lprocfs_status.c
@@ -1897,17 +1897,15 @@ int lprocfs_write_frac_u64_helper(const char *buffer, unsigned long count,
 	}
 
 	units = 1;
-	switch (*end) {
-	case 'p': case 'P':
-		units <<= 10;
-	case 't': case 'T':
-		units <<= 10;
-	case 'g': case 'G':
-		units <<= 10;
-	case 'm': case 'M':
-		units <<= 10;
-	case 'k': case 'K':
-		units <<= 10;
+	if (end) {
+		switch (*end) {
+		case 'p': case 'P':
+		case 't': case 'T':
+		case 'g': case 'G':
+		case 'm': case 'M':
+		case 'k': case 'K':
+			units <<= 10;
+		}
 	}
 	/* Specified units override the multiplier */
 	if (units)
-- 
1.7.10.4


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

end of thread, other threads:[~2014-12-16  9:28 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-12-14 22:52 [PATCH] staging: lustre: lustre: obdclass: lprocfs_status.c: Fix for possible null pointer dereference Rickard Strandqvist
2014-12-15  1:51 ` Joe Perches
2014-12-15 22:23   ` Rickard Strandqvist
2014-12-15 23:53     ` Joe Perches
2014-12-16  3:08       ` [HPDD-discuss] " Patrick Farrell
2014-12-16  9:27     ` Dan Carpenter
2014-12-16  4:40 ` Chris Rorvick
  -- strict thread matches above, loose matches on Subject: below --
2014-12-14 22:36 Rickard Strandqvist
2014-12-14 22:39 ` Greg Kroah-Hartman
2014-12-14 22:43   ` Rickard Strandqvist

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).