From patchwork Wed Jun 8 13:30:21 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Riku Voipio X-Patchwork-Id: 69666 Delivered-To: patch@linaro.org Received: by 10.140.106.246 with SMTP id e109csp2526451qgf; Wed, 8 Jun 2016 07:28:29 -0700 (PDT) X-Received: by 10.200.39.27 with SMTP id g27mr5035604qtg.88.1465396109701; Wed, 08 Jun 2016 07:28:29 -0700 (PDT) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id l66si822934qgd.0.2016.06.08.07.28.29 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 08 Jun 2016 07:28:29 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:57329 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bAeT7-0007Ko-74 for patch@linaro.org; Wed, 08 Jun 2016 10:28:29 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37347) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bAdZr-0004iM-I5 for qemu-devel@nongnu.org; Wed, 08 Jun 2016 09:31:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bAdZl-0005t0-4h for qemu-devel@nongnu.org; Wed, 08 Jun 2016 09:31:22 -0400 Received: from mail-lf0-x235.google.com ([2a00:1450:4010:c07::235]:33789) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bAdZk-0005sp-JN for qemu-devel@nongnu.org; Wed, 08 Jun 2016 09:31:17 -0400 Received: by mail-lf0-x235.google.com with SMTP id s64so5911198lfe.0 for ; Wed, 08 Jun 2016 06:31:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=y+6gc7FQaWYcK06GMnBAECNRR6+t1rWlCu1x1EacRoo=; b=kUsXAXbgAi3zJEZOvSmLqE8uTc3Zw/L/j677UV1x/Ng9xAIRq6DBZV7MF0R3zyNQjC 7Owj9wW3Ex+Rv7O8WiDn2dHgypU/xRX2LZR7fhOaB8z1OgL0GKAPBSzx7bb3phQ5gxZP txVvvT6itQhBvZEOJp3+zWK3B8ZUvUqYeuXGc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=y+6gc7FQaWYcK06GMnBAECNRR6+t1rWlCu1x1EacRoo=; b=JV38M1lKqniSvhV5OBXdmnNG4oGGiuGe0RSr6BTnPnzVUaZTZMK39sYC62ggy7Ui+T Bf1D4xWv+nJYTSsjVeUj6MBOexp12MtAIZ8OVZpokj2DUr0qqMS2tafyjQ907CXA0jTa zghGo7ieDTx+/0TCGY9yydDINkY710LZ0aT6fwNZYL/j3ytpDXOIONEG2bS5iC9wGWLi CRi/xq6joi34INY4ipF76z858UtFQBlgiABzmzLEID6EVoGF9qXD19k06+KgYcLdbFP9 B2oriP/9RpXh17mmlCipBQxwuw/PojO8zXTZzbeLXSitEXOZctkKPSkrFE3vuMZWdEqS 28+w== X-Gm-Message-State: ALyK8tL9nxxUC5EI6V4+4xobUwBPWtmWMShrO1joTB89UMNrv1FSsDKTZoIoUBX3ZfPFaRdY X-Received: by 10.46.1.66 with SMTP id 63mr1383232ljb.26.1465392675844; Wed, 08 Jun 2016 06:31:15 -0700 (PDT) Received: from beaming.home (91-157-170-157.elisa-laajakaista.fi. [91.157.170.157]) by smtp.gmail.com with ESMTPSA id 2sm139854lja.37.2016.06.08.06.31.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 08 Jun 2016 06:31:15 -0700 (PDT) From: riku.voipio@linaro.org To: qemu-devel@nongnu.org Date: Wed, 8 Jun 2016 16:30:21 +0300 Message-Id: <49ca6f3e24ee45de514604b8116e541332b23a84.1465392531.git.riku.voipio@linaro.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:4010:c07::235 Subject: [Qemu-devel] [PULL 40/44] 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: Peter Maydell Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Peter Maydell Use the safe_syscall wrapper to implement the ioctl syscall. Signed-off-by: Peter Maydell Signed-off-by: Riku Voipio --- linux-user/syscall.c | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) -- 2.1.4 diff --git a/linux-user/syscall.c b/linux-user/syscall.c index d414dc4..7b7bae6 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -772,6 +772,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) { @@ -4277,7 +4282,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 @@ -4367,7 +4372,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 */ @@ -4496,7 +4501,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; @@ -4677,7 +4682,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; @@ -4738,7 +4743,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); @@ -4750,7 +4755,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[] = { @@ -4794,18 +4799,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) @@ -4820,7 +4825,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: @@ -4829,7 +4834,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)