Skip to contentSkip to conversation

watchdog/rc32434_wdt: fix ioctl error handling

PATCH In review Michael S. Tsirkin 3 participants 3 messages Feb 28, 2016 – Mar 4, 2016

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 watchdog/rc32434_wdt: fix ioctl error handling

Calling return copy_to_user(...) in an ioctl will not do the right thing if there's a pagefault: copy_to_user returns the number of bytes not copied in this case.

Fix up watchdog/rc32434_wdt to do

	return copy_to_user(...)) ?  -EFAULT : 0;

instead.

---

Untested.

 drivers/watchdog/rc32434_wdt.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/watchdog/rc32434_wdt.c +1 -1
index 71e78ef..3a75f3b 100644
@@ -237,7 +237,7 @@ static long rc32434_wdt_ioctl(struct file *file, unsigned int cmd,
 			return -EINVAL;
 		/* Fall through */
 	case WDIOC_GETTIMEOUT:
-		return copy_to_user(argp, &timeout, sizeof(int));
+		return copy_to_user(argp, &timeout, sizeof(int)) ? -EFAULT : 0;
 	default:
 		return -ENOTTY;
 	}
Signature · 1 line
MST
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 11 lines · Michael S. Tsirkin

Calling return copy_to_user(...) in an ioctl will not do the right thing if there's a pagefault: copy_to_user returns the number of bytes not copied in this case.

Fix up watchdog/rc32434_wdt to do

	return copy_to_user(...)) ?  -EFAULT : 0;

instead.

Quoted 21 lines

---

Untested.

  drivers/watchdog/rc32434_wdt.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/watchdog/rc32434_wdt.c +1 -1
index 71e78ef..3a75f3b 100644
@@ -237,7 +237,7 @@ static long rc32434_wdt_ioctl(struct file *file, unsigned int cmd,
  			return -EINVAL;
  		/* Fall through */
  	case WDIOC_GETTIMEOUT:
-		return copy_to_user(argp, &timeout, sizeof(int));
+		return copy_to_user(argp, &timeout, sizeof(int)) ? -EFAULT : 0;
  	default:
  		return -ENOTTY;
  	}
#2 lore raw
In reply to Michael S. Tsirkin

Hi Michael,

Quoted 33 lines

Calling return copy_to_user(...) in an ioctl will not do the right thing if there's a pagefault: copy_to_user returns the number of bytes not copied in this case.

Fix up watchdog/rc32434_wdt to do

	return copy_to_user(...)) ?  -EFAULT : 0;

instead.

---

Untested.

 drivers/watchdog/rc32434_wdt.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/watchdog/rc32434_wdt.c +1 -1
index 71e78ef..3a75f3b 100644
@@ -237,7 +237,7 @@ static long rc32434_wdt_ioctl(struct file *file, unsigned int cmd,
 			return -EINVAL;
 		/* Fall through */
 	case WDIOC_GETTIMEOUT:
-		return copy_to_user(argp, &timeout, sizeof(int));
+		return copy_to_user(argp, &timeout, sizeof(int)) ? -EFAULT : 0;
 	default:
 		return -ENOTTY;
 	}
Signature · 1 line
MST

Patch has been added to linux-watchdog-next.

Kind regards,
Wim.