From patchwork Thu May 21 22:18:57 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 475239 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id D8056140DF7 for ; Fri, 22 May 2015 08:20:18 +1000 (AEST) Received: from localhost ([::1]:59694 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YvYp6-0007Gc-Bf for incoming@patchwork.ozlabs.org; Thu, 21 May 2015 18:20:16 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38113) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YvYon-0006kO-C5 for qemu-devel@nongnu.org; Thu, 21 May 2015 18:19:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YvYoj-0006j0-As for qemu-devel@nongnu.org; Thu, 21 May 2015 18:19:57 -0400 Received: from smtp4-g21.free.fr ([2a01:e0c:1:1599::13]:60449) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YvYoj-0006ie-5F for qemu-devel@nongnu.org; Thu, 21 May 2015 18:19:53 -0400 Received: from Quad (unknown [78.238.229.36]) by smtp4-g21.free.fr (Postfix) with ESMTPS id D01534C8035; Fri, 22 May 2015 00:16:16 +0200 (CEST) Received: from laurent by Quad with local (Exim 4.84) (envelope-from ) id 1YvYog-00074J-B1; Fri, 22 May 2015 00:19:50 +0200 From: Laurent Vivier To: Riku Voipio Date: Fri, 22 May 2015 00:18:57 +0200 Message-Id: <1432246737-27125-1-git-send-email-laurent@vivier.eu> X-Mailer: git-send-email 2.1.4 X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a01:e0c:1:1599::13 Cc: Ed Swierk , qemu-devel@nongnu.org, Laurent Vivier Subject: [Qemu-devel] [PATCH] linux-user: ioctl() command type is int X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org When executing a 64bit target chroot on 64bit host, the ioctl() command can mismatch. It seems the previous commit doesn't solve the problem in my case: 9c6bf9c7 linux-user: Fix ioctl cmd type mismatch on 64-bit targets For example, a ppc64 chroot on an x86_64 host: bash-4.3# ls Unsupported ioctl: cmd=0x80087467 Unsupported ioctl: cmd=0x802c7415 The origin of the problem is in syscall.c:do_ioctl(). static abi_long do_ioctl(int fd, abi_long cmd, abi_long arg) In this case (ppc64) abi_long is long (on the x86_64), and cmd = 0x0000000080087467 then if (ie->target_cmd == cmd) target_cmd is int, so target_cmd = 0x80087467 and to compare an int with a long, the sign is extended to 64bit, so the comparison is: if (0xffffffff80087467 == 0x0000000080087467) which doesn't match whereas it should. This patch uses abi_int in the case of the target command type instead of abi_long (and for consistency, update IOCTLEntry). Signed-off-by: Laurent Vivier --- linux-user/syscall.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 1622ad6..68801cf 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -3293,8 +3293,8 @@ typedef abi_long do_ioctl_fn(const IOCTLEntry *ie, uint8_t *buf_temp, int fd, abi_long cmd, abi_long arg); struct IOCTLEntry { - int target_cmd; - unsigned int host_cmd; + abi_int target_cmd; + int host_cmd; const char *name; int access; do_ioctl_fn *do_ioctl; @@ -3849,7 +3849,7 @@ static IOCTLEntry ioctl_entries[] = { /* ??? Implement proper locking for ioctls. */ /* do_ioctl() Must return target values and target errnos. */ -static abi_long do_ioctl(int fd, abi_long cmd, abi_long arg) +static abi_long do_ioctl(int fd, abi_int cmd, abi_long arg) { const IOCTLEntry *ie; const argtype *arg_type;