From patchwork Mon Jun 6 18:58:14 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 9159029 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 1480060573 for ; Mon, 6 Jun 2016 19:03:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DD5F028352 for ; Mon, 6 Jun 2016 19:03:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D238D2835A; Mon, 6 Jun 2016 19:03:02 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 6AE0428352 for ; Mon, 6 Jun 2016 19:03:02 +0000 (UTC) Received: from localhost ([::1]:44599 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b9znh-0003dZ-Ik for patchwork-qemu-devel@patchwork.kernel.org; Mon, 06 Jun 2016 15:03:01 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59538) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b9zjK-0000B2-RK for qemu-devel@nongnu.org; Mon, 06 Jun 2016 14:58:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b9zjI-0003ng-Cw for qemu-devel@nongnu.org; Mon, 06 Jun 2016 14:58:29 -0400 Received: from orth.archaic.org.uk ([2001:8b0:1d0::2]:57555) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b9zjI-0003nM-2R for qemu-devel@nongnu.org; Mon, 06 Jun 2016 14:58:28 -0400 Received: from pm215 by orth.archaic.org.uk with local (Exim 4.84_2) (envelope-from ) id 1b9zjH-0008S8-D9; Mon, 06 Jun 2016 19:58:27 +0100 From: Peter Maydell To: qemu-devel@nongnu.org Date: Mon, 6 Jun 2016 19:58:14 +0100 Message-Id: <1465239499-5048-14-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1465239499-5048-1-git-send-email-peter.maydell@linaro.org> References: <1465239499-5048-1-git-send-email-peter.maydell@linaro.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2001:8b0:1d0::2 Subject: [Qemu-devel] [PATCH 13/18] linux-user: Use safe_syscall wrapper for ioctl X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Riku Voipio , Laurent Vivier , patches@linaro.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Use the safe_syscall wrapper to implement the ioctl syscall. Signed-off-by: Peter Maydell --- linux-user/syscall.c | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index aac2bbd..4cf67c8 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -759,6 +759,11 @@ safe_syscall5(int, mq_timedsend, int, mqdes, const char *, msg_ptr, safe_syscall5(int, mq_timedreceive, int, mqdes, char *, msg_ptr, size_t, len, unsigned *, prio, const struct timespec *, timeout) #endif +/* We do ioctl like this rather than via safe_syscall3 to preserve the + * "third argument might be integer or pointer or not present" behaviour of + * the libc function. + */ +#define safe_ioctl(...) safe_syscall(__NR_ioctl, __VA_ARGS__) static inline int host_to_target_sock_type(int host_type) { @@ -3636,7 +3641,7 @@ static abi_long do_ioctl_fs_ioc_fiemap(const IOCTLEntry *ie, uint8_t *buf_temp, memcpy(fm, buf_temp, sizeof(struct fiemap)); free_fm = 1; } - ret = get_errno(ioctl(fd, ie->host_cmd, fm)); + ret = get_errno(safe_ioctl(fd, ie->host_cmd, fm)); if (!is_error(ret)) { target_size_out = target_size_in; /* An extent_count of 0 means we were only counting the extents @@ -3726,7 +3731,7 @@ static abi_long do_ioctl_ifconf(const IOCTLEntry *ie, uint8_t *buf_temp, host_ifconf->ifc_len = host_ifc_len; host_ifconf->ifc_buf = host_ifc_buf; - ret = get_errno(ioctl(fd, ie->host_cmd, host_ifconf)); + ret = get_errno(safe_ioctl(fd, ie->host_cmd, host_ifconf)); if (!is_error(ret)) { /* convert host ifc_len to target ifc_len */ @@ -3855,7 +3860,7 @@ static abi_long do_ioctl_dm(const IOCTLEntry *ie, uint8_t *buf_temp, int fd, } unlock_user(argptr, guest_data, 0); - ret = get_errno(ioctl(fd, ie->host_cmd, buf_temp)); + ret = get_errno(safe_ioctl(fd, ie->host_cmd, buf_temp)); if (!is_error(ret)) { guest_data = arg + host_dm->data_start; guest_data_size = host_dm->data_size - host_dm->data_start; @@ -4036,7 +4041,7 @@ static abi_long do_ioctl_blkpg(const IOCTLEntry *ie, uint8_t *buf_temp, int fd, /* Swizzle the data pointer to our local copy and call! */ host_blkpg->data = &host_part; - ret = get_errno(ioctl(fd, ie->host_cmd, host_blkpg)); + ret = get_errno(safe_ioctl(fd, ie->host_cmd, host_blkpg)); out: return ret; @@ -4097,7 +4102,7 @@ static abi_long do_ioctl_rt(const IOCTLEntry *ie, uint8_t *buf_temp, } unlock_user(argptr, arg, 0); - ret = get_errno(ioctl(fd, ie->host_cmd, buf_temp)); + ret = get_errno(safe_ioctl(fd, ie->host_cmd, buf_temp)); if (*host_rt_dev_ptr != 0) { unlock_user((void *)*host_rt_dev_ptr, *target_rt_dev_ptr, 0); @@ -4109,7 +4114,7 @@ static abi_long do_ioctl_kdsigaccept(const IOCTLEntry *ie, uint8_t *buf_temp, int fd, int cmd, abi_long arg) { int sig = target_to_host_signal(arg); - return get_errno(ioctl(fd, ie->host_cmd, sig)); + return get_errno(safe_ioctl(fd, ie->host_cmd, sig)); } static IOCTLEntry ioctl_entries[] = { @@ -4153,18 +4158,18 @@ static abi_long do_ioctl(int fd, int cmd, abi_long arg) switch(arg_type[0]) { case TYPE_NULL: /* no argument */ - ret = get_errno(ioctl(fd, ie->host_cmd)); + ret = get_errno(safe_ioctl(fd, ie->host_cmd)); break; case TYPE_PTRVOID: case TYPE_INT: - ret = get_errno(ioctl(fd, ie->host_cmd, arg)); + ret = get_errno(safe_ioctl(fd, ie->host_cmd, arg)); break; case TYPE_PTR: arg_type++; target_size = thunk_type_size(arg_type, 0); switch(ie->access) { case IOC_R: - ret = get_errno(ioctl(fd, ie->host_cmd, buf_temp)); + ret = get_errno(safe_ioctl(fd, ie->host_cmd, buf_temp)); if (!is_error(ret)) { argptr = lock_user(VERIFY_WRITE, arg, target_size, 0); if (!argptr) @@ -4179,7 +4184,7 @@ static abi_long do_ioctl(int fd, int cmd, abi_long arg) return -TARGET_EFAULT; thunk_convert(buf_temp, argptr, arg_type, THUNK_HOST); unlock_user(argptr, arg, 0); - ret = get_errno(ioctl(fd, ie->host_cmd, buf_temp)); + ret = get_errno(safe_ioctl(fd, ie->host_cmd, buf_temp)); break; default: case IOC_RW: @@ -4188,7 +4193,7 @@ static abi_long do_ioctl(int fd, int cmd, abi_long arg) return -TARGET_EFAULT; thunk_convert(buf_temp, argptr, arg_type, THUNK_HOST); unlock_user(argptr, arg, 0); - ret = get_errno(ioctl(fd, ie->host_cmd, buf_temp)); + ret = get_errno(safe_ioctl(fd, ie->host_cmd, buf_temp)); if (!is_error(ret)) { argptr = lock_user(VERIFY_WRITE, arg, target_size, 0); if (!argptr)