diff mbox

[v2] linux-user: correct reboot()

Message ID 1357594806-16621-1-git-send-email-laurent@vivier.eu
State New
Headers show

Commit Message

Laurent Vivier Jan. 7, 2013, 9:40 p.m. UTC
According to man reboot(2), the 4th argument is only used with
LINUX_REBOOT_CMD_RESTART2. In other cases, trying to convert
the value can generate EFAULT.

Signed-off-by: Laurent Vivier <laurent@vivier.eu>
---
v2: Set arg4 to NULL when arg3 != LINUX_REBOOT_CMD_RESTART2
    use get_errno()
    check patch checkpatch.pl
 linux-user/syscall.c |   16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

Comments

Peter Maydell Jan. 7, 2013, 9:46 p.m. UTC | #1
On 7 January 2013 21:40, Laurent Vivier <laurent@vivier.eu> wrote:
> According to man reboot(2), the 4th argument is only used with
> LINUX_REBOOT_CMD_RESTART2. In other cases, trying to convert
> the value can generate EFAULT.
>
> Signed-off-by: Laurent Vivier <laurent@vivier.eu>

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

-- PMM
Laurent Vivier Jan. 19, 2013, 11:26 p.m. UTC | #2
Le lundi 07 janvier 2013 à 21:46 +0000, Peter Maydell a écrit :
> On 7 January 2013 21:40, Laurent Vivier <laurent@vivier.eu> wrote:
> > According to man reboot(2), the 4th argument is only used with
> > LINUX_REBOOT_CMD_RESTART2. In other cases, trying to convert
> > the value can generate EFAULT.
> >
> > Signed-off-by: Laurent Vivier <laurent@vivier.eu>
> 
> Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

ping ?

Laurent
Laurent Vivier Jan. 26, 2013, 11:25 a.m. UTC | #3
ping

Le dimanche 20 janvier 2013 à 00:26 +0100, Laurent Vivier a écrit :
> Le lundi 07 janvier 2013 à 21:46 +0000, Peter Maydell a écrit :
> > On 7 January 2013 21:40, Laurent Vivier <laurent@vivier.eu> wrote:
> > > According to man reboot(2), the 4th argument is only used with
> > > LINUX_REBOOT_CMD_RESTART2. In other cases, trying to convert
> > > the value can generate EFAULT.
> > >
> > > Signed-off-by: Laurent Vivier <laurent@vivier.eu>
> > 
> > Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
> 
> ping ?
> 
> Laurent
>
diff mbox

Patch

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 3167a87..24c70e3 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -101,6 +101,7 @@  int __clone2(int (*fn)(void *), void *child_stack_base,
 #include <linux/fb.h>
 #include <linux/vt.h>
 #include <linux/dm-ioctl.h>
+#include <linux/reboot.h>
 #include "linux_loop.h"
 #include "cpu-uname.h"
 
@@ -6415,10 +6416,17 @@  abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
         break;
 #endif
     case TARGET_NR_reboot:
-        if (!(p = lock_user_string(arg4)))
-            goto efault;
-        ret = reboot(arg1, arg2, arg3, p);
-        unlock_user(p, arg4, 0);
+        if (arg3 == LINUX_REBOOT_CMD_RESTART2) {
+           /* arg4 must be ignored in all other cases */
+           p = lock_user_string(arg4);
+           if (!p) {
+              goto efault;
+           }
+           ret = get_errno(reboot(arg1, arg2, arg3, p));
+           unlock_user(p, arg4, 0);
+        } else {
+           ret = get_errno(reboot(arg1, arg2, arg3, NULL));
+        }
         break;
 #ifdef TARGET_NR_readdir
     case TARGET_NR_readdir: