From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:38735) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TsKQb-0001Ve-5x for qemu-devel@nongnu.org; Mon, 07 Jan 2013 16:40:18 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TsKQa-00069S-0J for qemu-devel@nongnu.org; Mon, 07 Jan 2013 16:40:17 -0500 Received: from smtp6-g21.free.fr ([2a01:e0c:1:1599::15]:37121) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TsKQZ-000693-D3 for qemu-devel@nongnu.org; Mon, 07 Jan 2013 16:40:15 -0500 From: Laurent Vivier Date: Mon, 7 Jan 2013 22:40:06 +0100 Message-Id: <1357594806-16621-1-git-send-email-laurent@vivier.eu> In-Reply-To: <1357590634-9768-1-git-send-email-laurent@vivier.eu> References: <1357590634-9768-1-git-send-email-laurent@vivier.eu> Subject: [Qemu-devel] [PATCH][v2] linux-user: correct reboot() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Peter Maydell Cc: Riku Voipio , qemu-devel@nongnu.org, Laurent Vivier 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 --- 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(-) 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 #include #include +#include #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: -- 1.7.10.4