Re: [PATCH] [PATCH] powerpc/vio: use strcpy in modalias_show

2013-10-17 Thread Prarit Bhargava


On 10/17/2013 08:22 AM, David Laight wrote:
>> Commit e82b89a6f19bae73fb064d1b3dd91fcefbb478f4 used strcat instead of
>> strcpy which can result in an overflow of newlines on the buffer.
> ...
>> --- a/arch/powerpc/kernel/vio.c
>> +++ b/arch/powerpc/kernel/vio.c
>> @@ -1531,12 +1531,12 @@ static ssize_t modalias_show(struct device *dev, 
>> struct device_attribute
>> *attr,
>>
>>  dn = dev->of_node;
>>  if (!dn) {
>> -strcat(buf, "\n");
>> +strcpy(buf, "\n");
>>  return strlen(buf);
>>  }
>>  cp = of_get_property(dn, "compatible", NULL);
>>  if (!cp) {
>> -strcat(buf, "\n");
>> +strcpy(buf, "\n");
>>  return strlen(buf);
>>  }
> 
> Why not just:
>   buf[0] = '\n';
>   buf[1] = 0;
>   return 1;
> 
> The assignment to buf[1] might not even be needed.

Sure, I guess that'd work too.  But it really seems like 1/2 a dozen of one and
six of the other.  I'll defer to the preference of the maintainers to see what
they want.

P.

> 
>   David
> 
> 
> 
___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


[PATCH] [PATCH] powerpc/vio: use strcpy in modalias_show

2013-10-17 Thread Prarit Bhargava
Commit e82b89a6f19bae73fb064d1b3dd91fcefbb478f4 used strcat instead of
strcpy which can result in an overflow of newlines on the buffer.

Signed-off-by: Prarit Bhargava
Cc: b...@kernel.crashing.org
Cc: b...@decadent.org.uk
Cc: sta...@vger.kernel.org
---
 arch/powerpc/kernel/vio.c |4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/kernel/vio.c b/arch/powerpc/kernel/vio.c
index d38cc08..cb92d82 100644
--- a/arch/powerpc/kernel/vio.c
+++ b/arch/powerpc/kernel/vio.c
@@ -1531,12 +1531,12 @@ static ssize_t modalias_show(struct device *dev, struct 
device_attribute *attr,
 
dn = dev->of_node;
if (!dn) {
-   strcat(buf, "\n");
+   strcpy(buf, "\n");
return strlen(buf);
}
cp = of_get_property(dn, "compatible", NULL);
if (!cp) {
-   strcat(buf, "\n");
+   strcpy(buf, "\n");
return strlen(buf);
}
 
-- 
1.7.9.3

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


Re: [PATCH] powerpc/vio: Fix modalias_show return values

2013-10-17 Thread Prarit Bhargava


On 10/16/2013 11:53 PM, Ben Hutchings wrote:
> Commit e82b89a6f19bae73fb064d1b3dd91fcefbb478f4 introduces a trivial
> local denial of service.
> 
>> --- a/arch/powerpc/kernel/vio.c
>> +++ b/arch/powerpc/kernel/vio.c
>> @@ -1351,11 +1351,15 @@ static ssize_t modalias_show(struct devi
>>  const char *cp;
>>  
>>  dn = dev->of_node;
>> -if (!dn)
>> -return -ENODEV;
>> +if (!dn) {
>> +strcat(buf, "\n");
> 
> Every read from the same sysfs file handle uses the same buffer, which
> gets zero-initialised just once.  So if I open the file, read it and
> seek back to 0 repeatedly, I can make modalias_show() write arbitrary
> numbers of newlines into *and beyond* that page-sized buffer.
> 
> Obviously strcat() should be strcpy().
> 

D'oh!  Of course -- I wasn't thinking clearly about that.  I'll send out a new
patch.

P.

> Ben.
> 
>> +return strlen(buf);
>> +}
>>  cp = of_get_property(dn, "compatible", NULL);
>> -if (!cp)
>> -return -ENODEV;
>> +if (!cp) {
>> +strcat(buf, "\n");
>> +return strlen(buf);
>> +}
>>  
>>  return sprintf(buf, "vio:T%sS%s\n", vio_dev->type, cp);
>>  }
> 
___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


[PATCH] ppc, vio fix modalias_show return values

2013-09-23 Thread Prarit Bhargava
[2nd try at this ... 1st one seems to have gone AWOL]

modalias_show() should return an empty string on error, not -ENODEV.

This causes the following false and annoying error:

> find /sys/devices -name modalias -print0 | xargs -0 cat >/dev/null
cat: /sys/devices/vio/4000/modalias: No such device
cat: /sys/devices/vio/4001/modalias: No such device
cat: /sys/devices/vio/4002/modalias: No such device
cat: /sys/devices/vio/4004/modalias: No such device
cat: /sys/devices/vio/modalias: No such device

Signed-off-by: Prarit Bhargava 
Cc: Paul Mackerras 
Cc: Steve Best 
---
 arch/powerpc/kernel/vio.c |   12 
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/arch/powerpc/kernel/vio.c b/arch/powerpc/kernel/vio.c
index 78a3506..d38cc08 100644
--- a/arch/powerpc/kernel/vio.c
+++ b/arch/powerpc/kernel/vio.c
@@ -1530,11 +1530,15 @@ static ssize_t modalias_show(struct device *dev, struct 
device_attribute *attr,
const char *cp;
 
dn = dev->of_node;
-   if (!dn)
-   return -ENODEV;
+   if (!dn) {
+   strcat(buf, "\n");
+   return strlen(buf);
+   }
cp = of_get_property(dn, "compatible", NULL);
-   if (!cp)
-   return -ENODEV;
+   if (!cp) {
+   strcat(buf, "\n");
+   return strlen(buf);
+   }
 
return sprintf(buf, "vio:T%sS%s\n", vio_dev->type, cp);
 }
-- 
1.7.9.3

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


[PATCH] ppc, vio fix modalias_show return values

2013-09-23 Thread Prarit Bhargava
modalias_show() should return an empty string on error, not -ENODEV.

This causes the following false and annoying error:

> find /sys/devices -name modalias -print0 | xargs -0 cat >/dev/null
cat: /sys/devices/vio/4000/modalias: No such device
cat: /sys/devices/vio/4001/modalias: No such device
cat: /sys/devices/vio/4002/modalias: No such device
cat: /sys/devices/vio/4004/modalias: No such device
cat: /sys/devices/vio/modalias: No such device

Signed-off-by: Prarit Bhargava 
---
 arch/powerpc/kernel/vio.c |   12 
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/arch/powerpc/kernel/vio.c b/arch/powerpc/kernel/vio.c
index 78a3506..d38cc08 100644
--- a/arch/powerpc/kernel/vio.c
+++ b/arch/powerpc/kernel/vio.c
@@ -1530,11 +1530,15 @@ static ssize_t modalias_show(struct device *dev, struct 
device_attribute *attr,
const char *cp;
 
dn = dev->of_node;
-   if (!dn)
-   return -ENODEV;
+   if (!dn) {
+   strcat(buf, "\n");
+   return strlen(buf);
+   }
cp = of_get_property(dn, "compatible", NULL);
-   if (!cp)
-   return -ENODEV;
+   if (!cp) {
+   strcat(buf, "\n");
+   return strlen(buf);
+   }
 
return sprintf(buf, "vio:T%sS%s\n", vio_dev->type, cp);
 }
-- 
1.7.9.3

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


[PATCH]: ppc: notifier_from_errno() cleanup

2011-01-13 Thread Prarit Bhargava
Minor cleanup of notifier_from_errno() in powerpc.

notifier_from_errno() now contains the if(ret)/else conditional.  There is no
need to do it in the powerpc code.

Signed-off-by: Prarit Bhargava 

diff --git a/arch/powerpc/platforms/pseries/cmm.c 
b/arch/powerpc/platforms/pseries/cmm.c
index f480386..3cafc30 100644
--- a/arch/powerpc/platforms/pseries/cmm.c
+++ b/arch/powerpc/platforms/pseries/cmm.c
@@ -508,12 +508,7 @@ static int cmm_memory_isolate_cb(struct notifier_block 
*self,
if (action == MEM_ISOLATE_COUNT)
ret = cmm_count_pages(arg);
 
-   if (ret)
-   ret = notifier_from_errno(ret);
-   else
-   ret = NOTIFY_OK;
-
-   return ret;
+   return notifier_from_errno(ret);
 }
 
 static struct notifier_block cmm_mem_isolate_nb = {
@@ -635,12 +630,7 @@ static int cmm_memory_cb(struct notifier_block *self,
break;
}
 
-   if (ret)
-   ret = notifier_from_errno(ret);
-   else
-   ret = NOTIFY_OK;
-
-   return ret;
+   return notifier_from_errno(ret);
 }
 
 static struct notifier_block cmm_mem_nb = {
___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev