All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/1] booke/wdt: fix incorrect WDIOC_GETSUPPORT return path
@ 2012-07-30  8:15 ` Tiejun Chen
  0 siblings, 0 replies; 12+ messages in thread
From: Tiejun Chen @ 2012-07-30  8:15 UTC (permalink / raw)
  To: benh, galak; +Cc: linuxppc-dev, linux-watchdog

We miss that correct WDIOC_GETSUPPORT return path when perform
copy_to_user() properly.

Signed-off-by: Tiejun Chen <tiejun.chen@windriver.com>
---
 drivers/watchdog/booke_wdt.c |    7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/watchdog/booke_wdt.c b/drivers/watchdog/booke_wdt.c
index 3fe82d0..2be7f29 100644
--- a/drivers/watchdog/booke_wdt.c
+++ b/drivers/watchdog/booke_wdt.c
@@ -162,12 +162,13 @@ static long booke_wdt_ioctl(struct file *file,
 				unsigned int cmd, unsigned long arg)
 {
 	u32 tmp = 0;
-	u32 __user *p = (u32 __user *)arg;
+	void __user *argp = (u32 __user *)arg;
+	u32 __user *p = argp;
 
 	switch (cmd) {
 	case WDIOC_GETSUPPORT:
-		if (copy_to_user((void *)arg, &ident, sizeof(ident)))
-			return -EFAULT;
+		return copy_to_user(argp, &ident,
+				sizeof(ident)) ? -EFAULT : 0;
 	case WDIOC_GETSTATUS:
 		return put_user(0, p);
 	case WDIOC_GETBOOTSTATUS:
-- 
1.5.6


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

* [PATCH 1/1] booke/wdt: fix incorrect WDIOC_GETSUPPORT return path
@ 2012-07-30  8:15 ` Tiejun Chen
  0 siblings, 0 replies; 12+ messages in thread
From: Tiejun Chen @ 2012-07-30  8:15 UTC (permalink / raw)
  To: benh, galak; +Cc: linuxppc-dev, linux-watchdog

We miss that correct WDIOC_GETSUPPORT return path when perform
copy_to_user() properly.

Signed-off-by: Tiejun Chen <tiejun.chen@windriver.com>
---
 drivers/watchdog/booke_wdt.c |    7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/watchdog/booke_wdt.c b/drivers/watchdog/booke_wdt.c
index 3fe82d0..2be7f29 100644
--- a/drivers/watchdog/booke_wdt.c
+++ b/drivers/watchdog/booke_wdt.c
@@ -162,12 +162,13 @@ static long booke_wdt_ioctl(struct file *file,
 				unsigned int cmd, unsigned long arg)
 {
 	u32 tmp = 0;
-	u32 __user *p = (u32 __user *)arg;
+	void __user *argp = (u32 __user *)arg;
+	u32 __user *p = argp;
 
 	switch (cmd) {
 	case WDIOC_GETSUPPORT:
-		if (copy_to_user((void *)arg, &ident, sizeof(ident)))
-			return -EFAULT;
+		return copy_to_user(argp, &ident,
+				sizeof(ident)) ? -EFAULT : 0;
 	case WDIOC_GETSTATUS:
 		return put_user(0, p);
 	case WDIOC_GETBOOTSTATUS:
-- 
1.5.6

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

* Re: [PATCH 1/1] booke/wdt: fix incorrect WDIOC_GETSUPPORT return path
  2012-07-30  8:15 ` Tiejun Chen
@ 2012-08-06  3:10   ` tiejun.chen
  -1 siblings, 0 replies; 12+ messages in thread
From: tiejun.chen @ 2012-08-06  3:10 UTC (permalink / raw)
  To: benh, galak; +Cc: linuxppc-dev, linux-watchdog

On 07/30/2012 04:15 PM, Tiejun Chen wrote:
> We miss that correct WDIOC_GETSUPPORT return path when perform
> copy_to_user() properly.

Any comments?

Thanks
Tiejun

> 
> Signed-off-by: Tiejun Chen <tiejun.chen@windriver.com>
> ---
>  drivers/watchdog/booke_wdt.c |    7 ++++---
>  1 files changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/watchdog/booke_wdt.c b/drivers/watchdog/booke_wdt.c
> index 3fe82d0..2be7f29 100644
> --- a/drivers/watchdog/booke_wdt.c
> +++ b/drivers/watchdog/booke_wdt.c
> @@ -162,12 +162,13 @@ static long booke_wdt_ioctl(struct file *file,
>  				unsigned int cmd, unsigned long arg)
>  {
>  	u32 tmp = 0;
> -	u32 __user *p = (u32 __user *)arg;
> +	void __user *argp = (u32 __user *)arg;
> +	u32 __user *p = argp;
>  
>  	switch (cmd) {
>  	case WDIOC_GETSUPPORT:
> -		if (copy_to_user((void *)arg, &ident, sizeof(ident)))
> -			return -EFAULT;
> +		return copy_to_user(argp, &ident,
> +				sizeof(ident)) ? -EFAULT : 0;
>  	case WDIOC_GETSTATUS:
>  		return put_user(0, p);
>  	case WDIOC_GETBOOTSTATUS:
> 


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

* Re: [PATCH 1/1] booke/wdt: fix incorrect WDIOC_GETSUPPORT return path
@ 2012-08-06  3:10   ` tiejun.chen
  0 siblings, 0 replies; 12+ messages in thread
From: tiejun.chen @ 2012-08-06  3:10 UTC (permalink / raw)
  To: benh, galak; +Cc: linuxppc-dev, linux-watchdog

On 07/30/2012 04:15 PM, Tiejun Chen wrote:
> We miss that correct WDIOC_GETSUPPORT return path when perform
> copy_to_user() properly.

Any comments?

Thanks
Tiejun

> 
> Signed-off-by: Tiejun Chen <tiejun.chen@windriver.com>
> ---
>  drivers/watchdog/booke_wdt.c |    7 ++++---
>  1 files changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/watchdog/booke_wdt.c b/drivers/watchdog/booke_wdt.c
> index 3fe82d0..2be7f29 100644
> --- a/drivers/watchdog/booke_wdt.c
> +++ b/drivers/watchdog/booke_wdt.c
> @@ -162,12 +162,13 @@ static long booke_wdt_ioctl(struct file *file,
>  				unsigned int cmd, unsigned long arg)
>  {
>  	u32 tmp = 0;
> -	u32 __user *p = (u32 __user *)arg;
> +	void __user *argp = (u32 __user *)arg;
> +	u32 __user *p = argp;
>  
>  	switch (cmd) {
>  	case WDIOC_GETSUPPORT:
> -		if (copy_to_user((void *)arg, &ident, sizeof(ident)))
> -			return -EFAULT;
> +		return copy_to_user(argp, &ident,
> +				sizeof(ident)) ? -EFAULT : 0;
>  	case WDIOC_GETSTATUS:
>  		return put_user(0, p);
>  	case WDIOC_GETBOOTSTATUS:
> 

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

* Re: [PATCH 1/1] booke/wdt: fix incorrect WDIOC_GETSUPPORT return path
  2012-08-06  3:10   ` tiejun.chen
@ 2012-08-06 16:13     ` Kumar Gala
  -1 siblings, 0 replies; 12+ messages in thread
From: Kumar Gala @ 2012-08-06 16:13 UTC (permalink / raw)
  To: tiejun.chen, Timur Tabi
  Cc: Benjamin Herrenschmidt, linuxppc-dev@ozlabs.org list, linux-watchdog


On Aug 5, 2012, at 10:10 PM, tiejun.chen wrote:

> On 07/30/2012 04:15 PM, Tiejun Chen wrote:
>> We miss that correct WDIOC_GETSUPPORT return path when perform
>> copy_to_user() properly.
> 
> Any comments?
> 
> Thanks
> Tiejun

Adding Timur, as he's touched watchdog last.

- k

>> Signed-off-by: Tiejun Chen <tiejun.chen@windriver.com>
>> ---
>> drivers/watchdog/booke_wdt.c |    7 ++++---
>> 1 files changed, 4 insertions(+), 3 deletions(-)
>> 
>> diff --git a/drivers/watchdog/booke_wdt.c b/drivers/watchdog/booke_wdt.c
>> index 3fe82d0..2be7f29 100644
>> --- a/drivers/watchdog/booke_wdt.c
>> +++ b/drivers/watchdog/booke_wdt.c
>> @@ -162,12 +162,13 @@ static long booke_wdt_ioctl(struct file *file,
>> 				unsigned int cmd, unsigned long arg)
>> {
>> 	u32 tmp = 0;
>> -	u32 __user *p = (u32 __user *)arg;
>> +	void __user *argp = (u32 __user *)arg;
>> +	u32 __user *p = argp;
>> 
>> 	switch (cmd) {
>> 	case WDIOC_GETSUPPORT:
>> -		if (copy_to_user((void *)arg, &ident, sizeof(ident)))
>> -			return -EFAULT;
>> +		return copy_to_user(argp, &ident,
>> +				sizeof(ident)) ? -EFAULT : 0;
>> 	case WDIOC_GETSTATUS:
>> 		return put_user(0, p);
>> 	case WDIOC_GETBOOTSTATUS:
>> 


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

* Re: [PATCH 1/1] booke/wdt: fix incorrect WDIOC_GETSUPPORT return path
@ 2012-08-06 16:13     ` Kumar Gala
  0 siblings, 0 replies; 12+ messages in thread
From: Kumar Gala @ 2012-08-06 16:13 UTC (permalink / raw)
  To: tiejun.chen, Timur Tabi; +Cc: linux-watchdog, linuxppc-dev@ozlabs.org list


On Aug 5, 2012, at 10:10 PM, tiejun.chen wrote:

> On 07/30/2012 04:15 PM, Tiejun Chen wrote:
>> We miss that correct WDIOC_GETSUPPORT return path when perform
>> copy_to_user() properly.
> 
> Any comments?
> 
> Thanks
> Tiejun

Adding Timur, as he's touched watchdog last.

- k

>> Signed-off-by: Tiejun Chen <tiejun.chen@windriver.com>
>> ---
>> drivers/watchdog/booke_wdt.c |    7 ++++---
>> 1 files changed, 4 insertions(+), 3 deletions(-)
>> 
>> diff --git a/drivers/watchdog/booke_wdt.c b/drivers/watchdog/booke_wdt.c
>> index 3fe82d0..2be7f29 100644
>> --- a/drivers/watchdog/booke_wdt.c
>> +++ b/drivers/watchdog/booke_wdt.c
>> @@ -162,12 +162,13 @@ static long booke_wdt_ioctl(struct file *file,
>> 				unsigned int cmd, unsigned long arg)
>> {
>> 	u32 tmp = 0;
>> -	u32 __user *p = (u32 __user *)arg;
>> +	void __user *argp = (u32 __user *)arg;
>> +	u32 __user *p = argp;
>> 
>> 	switch (cmd) {
>> 	case WDIOC_GETSUPPORT:
>> -		if (copy_to_user((void *)arg, &ident, sizeof(ident)))
>> -			return -EFAULT;
>> +		return copy_to_user(argp, &ident,
>> +				sizeof(ident)) ? -EFAULT : 0;
>> 	case WDIOC_GETSTATUS:
>> 		return put_user(0, p);
>> 	case WDIOC_GETBOOTSTATUS:
>> 

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

* Re: [PATCH 1/1] booke/wdt: fix incorrect WDIOC_GETSUPPORT return path
  2012-07-30  8:15 ` Tiejun Chen
@ 2012-08-06 23:27   ` Tabi Timur-B04825
  -1 siblings, 0 replies; 12+ messages in thread
From: Tabi Timur-B04825 @ 2012-08-06 23:27 UTC (permalink / raw)
  To: Tiejun Chen; +Cc: benh, galak, linuxppc-dev, linux-watchdog

On Mon, Jul 30, 2012 at 3:15 AM, Tiejun Chen <tiejun.chen@windriver.com> wrote:
> We miss that correct WDIOC_GETSUPPORT return path when perform
> copy_to_user() properly.

Thanks for catching this.  I'm amazed that this driver still has bugs like this.

> diff --git a/drivers/watchdog/booke_wdt.c b/drivers/watchdog/booke_wdt.c
> index 3fe82d0..2be7f29 100644
> --- a/drivers/watchdog/booke_wdt.c
> +++ b/drivers/watchdog/booke_wdt.c
> @@ -162,12 +162,13 @@ static long booke_wdt_ioctl(struct file *file,
>                                 unsigned int cmd, unsigned long arg)
>  {
>         u32 tmp = 0;
> -       u32 __user *p = (u32 __user *)arg;
> +       void __user *argp = (u32 __user *)arg;
> +       u32 __user *p = argp;

You don't need to create 'argp'.  The existing 'p' variable will work
in the copy_to_user() call.

> +               return copy_to_user(argp, &ident,
> +                               sizeof(ident)) ? -EFAULT : 0;

This can fit in one line, especially if you use 'p' instead of 'argp'.

-- 
Timur Tabi
Linux kernel developer at Freescale

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

* Re: [PATCH 1/1] booke/wdt: fix incorrect WDIOC_GETSUPPORT return path
@ 2012-08-06 23:27   ` Tabi Timur-B04825
  0 siblings, 0 replies; 12+ messages in thread
From: Tabi Timur-B04825 @ 2012-08-06 23:27 UTC (permalink / raw)
  To: Tiejun Chen; +Cc: linux-watchdog, linuxppc-dev

On Mon, Jul 30, 2012 at 3:15 AM, Tiejun Chen <tiejun.chen@windriver.com> wr=
ote:
> We miss that correct WDIOC_GETSUPPORT return path when perform
> copy_to_user() properly.

Thanks for catching this.  I'm amazed that this driver still has bugs like =
this.

> diff --git a/drivers/watchdog/booke_wdt.c b/drivers/watchdog/booke_wdt.c
> index 3fe82d0..2be7f29 100644
> --- a/drivers/watchdog/booke_wdt.c
> +++ b/drivers/watchdog/booke_wdt.c
> @@ -162,12 +162,13 @@ static long booke_wdt_ioctl(struct file *file,
>                                 unsigned int cmd, unsigned long arg)
>  {
>         u32 tmp =3D 0;
> -       u32 __user *p =3D (u32 __user *)arg;
> +       void __user *argp =3D (u32 __user *)arg;
> +       u32 __user *p =3D argp;

You don't need to create 'argp'.  The existing 'p' variable will work
in the copy_to_user() call.

> +               return copy_to_user(argp, &ident,
> +                               sizeof(ident)) ? -EFAULT : 0;

This can fit in one line, especially if you use 'p' instead of 'argp'.

--=20
Timur Tabi
Linux kernel developer at Freescale=

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

* Re: [PATCH 1/1] booke/wdt: fix incorrect WDIOC_GETSUPPORT return path
  2012-08-06 23:27   ` Tabi Timur-B04825
@ 2012-08-06 23:36     ` Tabi Timur-B04825
  -1 siblings, 0 replies; 12+ messages in thread
From: Tabi Timur-B04825 @ 2012-08-06 23:36 UTC (permalink / raw)
  To: Tiejun Chen; +Cc: benh, galak, linuxppc-dev, linux-watchdog

On Mon, Aug 6, 2012 at 2:12 PM, Tabi Timur-B04825 <b04825@freescale.com> wrote:
> On Mon, Jul 30, 2012 at 3:15 AM, Tiejun Chen <tiejun.chen@windriver.com> wrote:
>> We miss that correct WDIOC_GETSUPPORT return path when perform
>> copy_to_user() properly.
>
> Thanks for catching this.  I'm amazed that this driver still has bugs like this.

While you're at it, I found a few related bugs.  Can you fix these, also?

1.	case WDIOC_SETOPTIONS:
		if (get_user(tmp, p))
			return -EINVAL;

This should return -EFAULT.

2. 	case WDIOC_GETBOOTSTATUS:
		/* XXX: something is clearing TSR */
		tmp = mfspr(SPRN_TSR) & TSR_WRS(3);
		/* returns CARDRESET if last reset was caused by the WDT */
		return (tmp ? WDIOF_CARDRESET : 0);

This should use put_user() to return the value, instead of returning
it as a return code.

You can title the new patch something like, "booke/wdt: some ioctls do
not return values properly"

-- 
Timur Tabi
Linux kernel developer at Freescale

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

* Re: [PATCH 1/1] booke/wdt: fix incorrect WDIOC_GETSUPPORT return path
@ 2012-08-06 23:36     ` Tabi Timur-B04825
  0 siblings, 0 replies; 12+ messages in thread
From: Tabi Timur-B04825 @ 2012-08-06 23:36 UTC (permalink / raw)
  To: Tiejun Chen; +Cc: linux-watchdog, linuxppc-dev

On Mon, Aug 6, 2012 at 2:12 PM, Tabi Timur-B04825 <b04825@freescale.com> wr=
ote:
> On Mon, Jul 30, 2012 at 3:15 AM, Tiejun Chen <tiejun.chen@windriver.com> =
wrote:
>> We miss that correct WDIOC_GETSUPPORT return path when perform
>> copy_to_user() properly.
>
> Thanks for catching this.  I'm amazed that this driver still has bugs lik=
e this.

While you're at it, I found a few related bugs.  Can you fix these, also?

1.	case WDIOC_SETOPTIONS:
		if (get_user(tmp, p))
			return -EINVAL;

This should return -EFAULT.

2. 	case WDIOC_GETBOOTSTATUS:
		/* XXX: something is clearing TSR */
		tmp =3D mfspr(SPRN_TSR) & TSR_WRS(3);
		/* returns CARDRESET if last reset was caused by the WDT */
		return (tmp ? WDIOF_CARDRESET : 0);

This should use put_user() to return the value, instead of returning
it as a return code.

You can title the new patch something like, "booke/wdt: some ioctls do
not return values properly"

--=20
Timur Tabi
Linux kernel developer at Freescale=

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

* Re: [PATCH 1/1] booke/wdt: fix incorrect WDIOC_GETSUPPORT return path
  2012-08-06 23:36     ` Tabi Timur-B04825
@ 2012-08-07  1:56       ` tiejun.chen
  -1 siblings, 0 replies; 12+ messages in thread
From: tiejun.chen @ 2012-08-07  1:56 UTC (permalink / raw)
  To: Tabi Timur-B04825; +Cc: benh, galak, linuxppc-dev, linux-watchdog

On 08/07/2012 09:19 AM, Tabi Timur-B04825 wrote:
> On Mon, Aug 6, 2012 at 2:12 PM, Tabi Timur-B04825 <b04825@freescale.com> wrote:
>> On Mon, Jul 30, 2012 at 3:15 AM, Tiejun Chen <tiejun.chen@windriver.com> wrote:
>>> We miss that correct WDIOC_GETSUPPORT return path when perform
>>> copy_to_user() properly.
>>
>> Thanks for catching this.  I'm amazed that this driver still has bugs like this.
> 
> While you're at it, I found a few related bugs.  Can you fix these, also?
> 
> 1.	case WDIOC_SETOPTIONS:
> 		if (get_user(tmp, p))
> 			return -EINVAL;
> 
> This should return -EFAULT.
> 
> 2. 	case WDIOC_GETBOOTSTATUS:
> 		/* XXX: something is clearing TSR */
> 		tmp = mfspr(SPRN_TSR) & TSR_WRS(3);
> 		/* returns CARDRESET if last reset was caused by the WDT */
> 		return (tmp ? WDIOF_CARDRESET : 0);
> 
> This should use put_user() to return the value, instead of returning
> it as a return code.
> 
> You can title the new patch something like, "booke/wdt: some ioctls do
> not return values properly"

Will regenerate this patch including these error as v2.

Thanks
Tiejun

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

* Re: [PATCH 1/1] booke/wdt: fix incorrect WDIOC_GETSUPPORT return path
@ 2012-08-07  1:56       ` tiejun.chen
  0 siblings, 0 replies; 12+ messages in thread
From: tiejun.chen @ 2012-08-07  1:56 UTC (permalink / raw)
  To: Tabi Timur-B04825; +Cc: linux-watchdog, linuxppc-dev

On 08/07/2012 09:19 AM, Tabi Timur-B04825 wrote:
> On Mon, Aug 6, 2012 at 2:12 PM, Tabi Timur-B04825 <b04825@freescale.com> wrote:
>> On Mon, Jul 30, 2012 at 3:15 AM, Tiejun Chen <tiejun.chen@windriver.com> wrote:
>>> We miss that correct WDIOC_GETSUPPORT return path when perform
>>> copy_to_user() properly.
>>
>> Thanks for catching this.  I'm amazed that this driver still has bugs like this.
> 
> While you're at it, I found a few related bugs.  Can you fix these, also?
> 
> 1.	case WDIOC_SETOPTIONS:
> 		if (get_user(tmp, p))
> 			return -EINVAL;
> 
> This should return -EFAULT.
> 
> 2. 	case WDIOC_GETBOOTSTATUS:
> 		/* XXX: something is clearing TSR */
> 		tmp = mfspr(SPRN_TSR) & TSR_WRS(3);
> 		/* returns CARDRESET if last reset was caused by the WDT */
> 		return (tmp ? WDIOF_CARDRESET : 0);
> 
> This should use put_user() to return the value, instead of returning
> it as a return code.
> 
> You can title the new patch something like, "booke/wdt: some ioctls do
> not return values properly"

Will regenerate this patch including these error as v2.

Thanks
Tiejun

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

end of thread, other threads:[~2012-08-07  2:01 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-07-30  8:15 [PATCH 1/1] booke/wdt: fix incorrect WDIOC_GETSUPPORT return path Tiejun Chen
2012-07-30  8:15 ` Tiejun Chen
2012-08-06  3:10 ` tiejun.chen
2012-08-06  3:10   ` tiejun.chen
2012-08-06 16:13   ` Kumar Gala
2012-08-06 16:13     ` Kumar Gala
2012-08-06 23:27 ` Tabi Timur-B04825
2012-08-06 23:27   ` Tabi Timur-B04825
2012-08-06 23:36   ` Tabi Timur-B04825
2012-08-06 23:36     ` Tabi Timur-B04825
2012-08-07  1:56     ` tiejun.chen
2012-08-07  1:56       ` tiejun.chen

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.