pm_qos_params: cleanup: terminate a string
PATCH 1/1 pm_qos_params: cleanup: terminate a string
This is just a picky thing, but we pass an possibly unterminated string to printk if debugging is turned on. Also printk level is set to "debug" by pr_debug() so the "KERN_ERR" isn't used.
kernel/pm_qos_params.c +2 -1
@@ -389,10 +389,11 @@ static ssize_t pm_qos_power_write(struct file *filp, const char __user *buf, }else if (count =11 ) {/* len('0x12345678/0') */ if (copy_from_user (ascii_value, buf,11 ))return -EFAULT ; + ascii_value[10 ] ='\0' ; x =sscanf (ascii_value,"%x" , &value);if (x !=1 )return -EINVAL ; -pr_debug (KERN_ERR "%s, %d, 0x%x\n" , ascii_value, x, value); +pr_debug ("%s, %d, 0x%x\n" , ascii_value, x, value); }else return -EINVAL ;
Quoted 3 lines · Dan Carpenter
This is just a picky thing, but we pass an possibly unterminated string to printk if debugging is turned on. Also printk level is set to "debug" by
pr_debug()so the "KERN_ERR" isn't used.
Picky is good. But we should probably get the other pr_debug fixed and return -EINVAL if the strlen of the ascii_value is not bigger than 10.
thanks for finding my screw up!
Quoted 10 lines
Signed-off-by Dan Carpenter <[email protected]>kernel/pm_qos_params.c +0
-0@@ -389,10 +389,11 @@ static ssize_t pm_qos_power_write(struct file *filp, const char __user *buf, }else if (count =11 ) {/* len('0x12345678/0') */ if (copy_from_user (ascii_value, buf,11 ))
kernel/pm_qos_params.c static ssize_t pm_qos_power_write(struct file *filp, const char __user *buf, · line 399
Quoted 10 lines
kernel/pm_qos_params.c +2
-1return -EFAULT ; + ascii_value[10 ] ='\0' ; x =sscanf (ascii_value,"%x" , &value);if (x !=1 )return -EINVAL ; -pr_debug (KERN_ERR "%s, %d, 0x%x\n" , ascii_value, x, value); +pr_debug ("%s, %d, 0x%x\n" , ascii_value, x, value); }else return -EINVAL ;
Updated version of this patch:
--mark
Subject: [PATCH] correct some pr_debug misuse and add a stronger parrameter check to
pm_qos_write for the ascii hex value case. Thanks to Dan Carpenter for pointing out the problem!
--- kernel/pm_qos_params.c | 6 ++++-- 1 files changed, 4 insertions(+), 2 deletions(-)
kernel/pm_qos_params.c +4 -2
@@ -155,7 +155,7 @@ static void update_target(int pm_qos_class) call_notifier =1 ;atomic_set (&pm_qos_array[pm_qos_class]->target_value, extreme_value); -pr_debug (KERN_ERR "new target for qos %d is %d\n" , pm_qos_class, +pr_debug ("new target for qos %d is %d\n" , pm_qos_class,atomic_read (&pm_qos_array[pm_qos_class]->target_value)); }spin_unlock_irqrestore (&pm_qos_lock, flags);
@@ -374,10 +374,12 @@ static ssize_t pm_qos_power_write(struct file *filp, const char __user *buf, }else if (count =11 ) {/* len('0x12345678/0') */ if (copy_from_user (ascii_value, buf,11 ))return -EFAULT ; +if (strlen (ascii_value) >10 ) +return -EINVAL ; x =sscanf (ascii_value,"%x" , &value);if (x !=1 )return -EINVAL ; -pr_debug (KERN_ERR "%s, %d, 0x%x\n" , ascii_value, x, value); +pr_debug ("%s, %d, 0x%x\n" , ascii_value, x, value); }else return -EINVAL ;
Signature · 1 line
1.7.0.4
Quoted 60 lines · mark gross
Quoted 3 lines · Dan Carpenter
This is just a picky thing, but we pass an possibly unterminated string to printk if debugging is turned on. Also printk level is set to "debug" by
pr_debug()so the "KERN_ERR" isn't used.Picky is good. But we should probably get the other
pr_debugfixed and return-EINVALif the strlen of theascii_valueis not bigger than 10.thanks for finding my screw up!
Quoted 10 lines
Signed-off-by Dan Carpenter <[email protected]>kernel/pm_qos_params.c +0
-0@@ -389,10 +389,11 @@ static ssize_t pm_qos_power_write(struct file *filp, const char __user *buf, }else if (count =11 ) {/* len('0x12345678/0') */ if (copy_from_user (ascii_value, buf,11 ))kernel/pm_qos_params.c static ssize_t pm_qos_power_write(struct file *filp, const char __user *buf, · line 399
Quoted 10 lines
kernel/pm_qos_params.c +2
-1return -EFAULT ; + ascii_value[10 ] ='\0' ; x =sscanf (ascii_value,"%x" , &value);if (x !=1 )return -EINVAL ; -pr_debug (KERN_ERR "%s, %d, 0x%x\n" , ascii_value, x, value); +pr_debug ("%s, %d, 0x%x\n" , ascii_value, x, value); }else return -EINVAL ;Updated version of this patch:
--mark
Signed-off-by mark gross <[email protected]>Subject: [PATCH] correct some
pr_debugmisuse and add a stronger parrameter check to
pm_qos_writefor the ascii hex value case. Thanks to Dan Carpenter for pointing out the problem!--- kernel/pm_qos_params.c | 6 ++++-- 1 files changed, 4 insertions(+), 2 deletions(-)kernel/pm_qos_params.c +1
-1@@ -155,7 +155,7 @@ static void update_target(int pm_qos_class) call_notifier =1 ;atomic_set (&pm_qos_array[pm_qos_class]->target_value, extreme_value); -pr_debug (KERN_ERR "new target for qos %d is %d\n" , pm_qos_class, +pr_debug ("new target for qos %d is %d\n" , pm_qos_class,atomic_read (&pm_qos_array[pm_qos_class]->target_value)); }spin_unlock_irqrestore (&pm_qos_lock, flags);
kernel/pm_qos_params.c static ssize_t pm_qos_power_write(struct file *filp, const char __user *buf, · line 377
Quoted 4 lines
kernel/pm_qos_params.c +1
-0@@ -374,10 +374,12 @@ static ssize_t pm_qos_power_write(struct file *filp, const char __user *buf, }else if (count =11 ) {/* len('0x12345678/0') */ if (copy_from_user (ascii_value, buf,11 ))return -EFAULT ; +if (strlen (ascii_value) >10 )
should be !
Quoted 11 lines
kernel/pm_qos_params.c +2
-1+return -EINVAL ; x =sscanf (ascii_value,"%x" , &value);if (x !=1 )return -EINVAL ; -pr_debug (KERN_ERR "%s, %d, 0x%x\n" , ascii_value, x, value); +pr_debug ("%s, %d, 0x%x\n" , ascii_value, x, value); }else return -EINVAL ;Signature · 1 line
1.7.0.4
updated patch
--mgross
Subject: [PATCH] correct some pr_debug misuse and add a stronger parrameter check to
pm_qos_write for the ascii hex value case. Thanks to Dan Carpenter for pointing out the problem!
--- kernel/pm_qos_params.c | 6 ++++-- 1 files changed, 4 insertions(+), 2 deletions(-)
kernel/pm_qos_params.c +4 -2
@@ -155,7 +155,7 @@ static void update_target(int pm_qos_class) call_notifier =1 ;atomic_set (&pm_qos_array[pm_qos_class]->target_value, extreme_value); -pr_debug (KERN_ERR "new target for qos %d is %d\n" , pm_qos_class, +pr_debug ("new target for qos %d is %d\n" , pm_qos_class,atomic_read (&pm_qos_array[pm_qos_class]->target_value)); }spin_unlock_irqrestore (&pm_qos_lock, flags);
@@ -374,10 +374,12 @@ static ssize_t pm_qos_power_write(struct file *filp, const char __user *buf, }else if (count =11 ) {/* len('0x12345678/0') */ if (copy_from_user (ascii_value, buf,11 ))return -EFAULT ; +if (strlen (ascii_value) !=10 ) +return -EINVAL ; x =sscanf (ascii_value,"%x" , &value);if (x !=1 )return -EINVAL ; -pr_debug (KERN_ERR "%s, %d, 0x%x\n" , ascii_value, x, value); +pr_debug ("%s, %d, 0x%x\n" , ascii_value, x, value); }else return -EINVAL ;
Signature · 1 line
1.7.0.4
Quoted 11 lines · mark gross
kernel/pm_qos_params.c static ssize_t pm_qos_power_write(struct file *filp, const char __user *buf, · line 377
Quoted 6 lines
kernel/pm_qos_params.c +1
-0spin_unlock_irqrestore (&pm_qos_lock, flags);@@ -374,10 +374,12 @@ static ssize_t pm_qos_power_write(struct file *filp, const char __user *buf, }else if (count =11 ) {/* len('0x12345678/0') */ if (copy_from_user (ascii_value, buf,11 ))return -EFAULT ; +if (strlen (ascii_value) >10 )should be !>
kernel/pm_qos_params.c static ssize_t pm_qos_power_write(struct file *filp, const char __user *buf, · line 381
Quoted 4 lines
kernel/pm_qos_params.c +1
-0+return -EINVAL ; x =sscanf (ascii_value,"%x" , &value);if (x !=1 )return -EINVAL ;
With the original code you could do:
char buf[11]; /* must be 11 chars */ snprintf(buf, sizeof(buf), "0x%x", 42); write(fd, buf, sizeof(buf));
But the new code is stricter so the number would have to be zero padded.
regards,
dan carpenter
Quoted 2 lines · mark gross
Quoted 1 line · mark gross
On Fri, Sep 03, 2010 at 02:41:06PM +0200, Dan Carpenter wrote:
...
Quoted 20 lines
updated patch
Signed-off-by mark gross <[email protected]>--mgross
Subject: [PATCH] correct some
pr_debugmisuse and add a stronger parrameter check to
pm_qos_writefor the ascii hex value case. Thanks to Dan Carpenter for pointing out the problem!--- kernel/pm_qos_params.c | 6 ++++-- 1 files changed, 4 insertions(+), 2 deletions(-)kernel/pm_qos_params.c +0
-0
kernel/pm_qos_params.c static void update_target(int pm_qos_class) · line 161
Quoted 8 lines
kernel/pm_qos_params.c +1
-1@@ -155,7 +155,7 @@ static void update_target(int pm_qos_class) call_notifier =1 ;atomic_set (&pm_qos_array[pm_qos_class]->target_value, extreme_value); -pr_debug (KERN_ERR "new target for qos %d is %d\n" , pm_qos_class, +pr_debug ("new target for qos %d is %d\n" , pm_qos_class,atomic_read (&pm_qos_array[pm_qos_class]->target_value)); }spin_unlock_irqrestore (&pm_qos_lock, flags);
The above doesn't apply to the Linus' tree any more. Care to fix?
Rafael
Quoted 35 lines · Rafael J. Wysocki
Quoted 2 lines · mark gross
Quoted 1 line · mark gross
On Fri, Sep 03, 2010 at 02:41:06PM +0200, Dan Carpenter wrote:
...
Quoted 20 lines
updated patch
Signed-off-by mark gross <[email protected]>--mgross
Subject: [PATCH] correct some
pr_debugmisuse and add a stronger parrameter check to
pm_qos_writefor the ascii hex value case. Thanks to Dan Carpenter for pointing out the problem!--- kernel/pm_qos_params.c | 6 ++++-- 1 files changed, 4 insertions(+), 2 deletions(-)kernel/pm_qos_params.c +0
-0kernel/pm_qos_params.c static void update_target(int pm_qos_class) · line 161
Quoted 8 lines
kernel/pm_qos_params.c +1
-1@@ -155,7 +155,7 @@ static void update_target(int pm_qos_class) call_notifier =1 ;atomic_set (&pm_qos_array[pm_qos_class]->target_value, extreme_value); -pr_debug (KERN_ERR "new target for qos %d is %d\n" , pm_qos_class, +pr_debug ("new target for qos %d is %d\n" , pm_qos_class,atomic_read (&pm_qos_array[pm_qos_class]->target_value)); }spin_unlock_irqrestore (&pm_qos_lock, flags);The above doesn't apply to the Linus' tree any more. Care to fix?
Quoted 1 line
Rafael
no problem. (I screwed up on my fetch and forgot to merge the linus remote....) This bit doesn't apply post 2.6.35.
--mgross
From 64753f68e2baaef21783192566469abc54aca90d Mon Sep 17 00:00:00 2001
From: mgross <mgross@mgross-laptop.(none)>
Date: Wed, 8 Sep 2010 19:52:39 -0700
Subject: [PATCH] make it harder to misuse the pm_qos user mode api.
--- kernel/pm_qos_params.c | 4 +++- 1 files changed, 3 insertions(+), 1 deletions(-)
kernel/pm_qos_params.c +3 -1
@@ -389,10 +389,12 @@ static ssize_t pm_qos_power_write(struct file *filp, const char __user *buf, }else if (count =11 ) {/* len('0x12345678/0') */ if (copy_from_user (ascii_value, buf,11 ))return -EFAULT ; +if (strlen (ascii_value) !=10 ) +return -EINVAL ; x =sscanf (ascii_value,"%x" , &value);if (x !=1 )return -EINVAL ; -pr_debug (KERN_ERR "%s, %d, 0x%x\n" , ascii_value, x, value); +pr_debug ("%s, %d, 0x%x\n" , ascii_value, x, value); }else return -EINVAL ;
Signature · 1 line
1.7.0.4
Rafael J. Wysocki
AppliedQuoted 36 lines · mark gross
Quoted 35 lines · Rafael J. Wysocki
Quoted 2 lines · mark gross
Quoted 1 line · mark gross
On Fri, Sep 03, 2010 at 02:41:06PM +0200, Dan Carpenter wrote:
...
Quoted 20 lines
updated patch
Signed-off-by mark gross <[email protected]>--mgross
Subject: [PATCH] correct some
pr_debugmisuse and add a stronger parrameter check to
pm_qos_writefor the ascii hex value case. Thanks to Dan Carpenter for pointing out the problem!--- kernel/pm_qos_params.c | 6 ++++-- 1 files changed, 4 insertions(+), 2 deletions(-)kernel/pm_qos_params.c +0
-0kernel/pm_qos_params.c static void update_target(int pm_qos_class) · line 161
Quoted 8 lines
kernel/pm_qos_params.c +1
-1@@ -155,7 +155,7 @@ static void update_target(int pm_qos_class) call_notifier =1 ;atomic_set (&pm_qos_array[pm_qos_class]->target_value, extreme_value); -pr_debug (KERN_ERR "new target for qos %d is %d\n" , pm_qos_class, +pr_debug ("new target for qos %d is %d\n" , pm_qos_class,atomic_read (&pm_qos_array[pm_qos_class]->target_value)); }spin_unlock_irqrestore (&pm_qos_lock, flags);The above doesn't apply to the Linus' tree any more. Care to fix?
Quoted 5 lines
Quoted 1 line
Rafael
no problem. (I screwed up on my fetch and forgot to merge the linus remote....) This bit doesn't apply post 2.6.35.
--mgross
Thanks, applied to suspend-2.6/linux-next .
Rafael
Quoted 31 lines
Signed-off-by mark gross <[email protected])From
64753f68e2baaef21783192566469abc54aca90dMon Sep 17 00:00:00 2001
From: mgross <mgross@mgross-laptop.(none)>
Date: Wed, 8 Sep 2010 19:52:39 -0700
Subject: [PATCH] make it harder to misuse thepm_qosuser mode api.--- kernel/pm_qos_params.c | 4 +++- 1 files changed, 3 insertions(+), 1 deletions(-)kernel/pm_qos_params.c +3
-1@@ -389,10 +389,12 @@ static ssize_t pm_qos_power_write(struct file *filp, const char __user *buf, }else if (count =11 ) {/* len('0x12345678/0') */ if (copy_from_user (ascii_value, buf,11 ))return -EFAULT ; +if (strlen (ascii_value) !=10 ) +return -EINVAL ; x =sscanf (ascii_value,"%x" , &value);if (x !=1 )return -EINVAL ; -pr_debug (KERN_ERR "%s, %d, 0x%x\n" , ascii_value, x, value); +pr_debug ("%s, %d, 0x%x\n" , ascii_value, x, value); }else return -EINVAL ;