From patchwork Tue Jun 28 19:12:37 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Riku Voipio X-Patchwork-Id: 641707 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 3rfG0Z57fsz9s9n for ; Wed, 29 Jun 2016 05:22:38 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b=F9BmZXHo; dkim-atps=neutral Received: from localhost ([::1]:39033 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bHyai-0003mf-K2 for incoming@patchwork.ozlabs.org; Tue, 28 Jun 2016 15:22:36 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38350) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bHyRc-0001r9-5H for qemu-devel@nongnu.org; Tue, 28 Jun 2016 15:13:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bHyRW-0006pO-LN for qemu-devel@nongnu.org; Tue, 28 Jun 2016 15:13:12 -0400 Received: from mail-lf0-x233.google.com ([2a00:1450:4010:c07::233]:34517) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bHyRW-0006p9-8e for qemu-devel@nongnu.org; Tue, 28 Jun 2016 15:13:06 -0400 Received: by mail-lf0-x233.google.com with SMTP id h129so18184541lfh.1 for ; Tue, 28 Jun 2016 12:13:06 -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=6wzsuqoiNvUDEK7J0CYVQju9ke3+nTIE8LimR/5K5O4=; b=F9BmZXHoFmJvLpIjqky7b9Nvtm2/2WcR16ViOmXSzBwLRT8BInwxjkk80jK6C7V2no uB5jhskMol4TrgAi+jnby/JW1qamGs/lrsLLyGCCRMtyEBbnPnj1SBLvXii2sCGJuOl2 6KkxHDD53r3OZPOvCrByGZQB53xy1txFdvJ6Y= 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=6wzsuqoiNvUDEK7J0CYVQju9ke3+nTIE8LimR/5K5O4=; b=O5bFQU1pmQPvizavWAlhaDP7kSn6hxe/0YnQEGVVhBkoCRw76K9VRO33xDwqqP+kh9 7qFSqmAKlx5OGJEgt3aeYUstbyUNb/4PrA78r+quYJMeO3M+qMTJdmjunbbdNwA1IsMG Xck65CN6p0EjY+2cunCC6fTRolKpsuNdY0QOgRZXmZhH0XFRDEAqpqLIWigwrDKbLf/L VyzmpXVTXXNGwtc0ERYVXfU3sn9nCtHkNrjeZrHviGWwW98BORaJRd8v02UPUBPNqs1Q t/3z3EymeaNjfrDaMqYiPdjzrkwxIGf/QE0sMAjIwKfrdgLxJKjuEjaIpjsbmjUBjcoz wzvw== X-Gm-Message-State: ALyK8tIqMBnEn6WQcjH6XUe3X0L5Mwp9mko6595mdZJ7eB3v+m9bkbCTsLCrsDS5Ud5KYCLY X-Received: by 10.25.153.148 with SMTP id b142mr1842548lfe.61.1467141185540; Tue, 28 Jun 2016 12:13:05 -0700 (PDT) Received: from beaming.home (91-157-170-157.elisa-laajakaista.fi. [91.157.170.157]) by smtp.gmail.com with ESMTPSA id h10sm4262823ljh.38.2016.06.28.12.13.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 28 Jun 2016 12:13:04 -0700 (PDT) From: riku.voipio@linaro.org To: qemu-devel@nongnu.org Date: Tue, 28 Jun 2016 22:12:37 +0300 Message-Id: <435da5e7092aa54e12044b9401b42c4a9333c74d.1467138806.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::233 Subject: [Qemu-devel] [PULL v2 03/24] linux-user: Use safe_syscall wrapper for fcntl 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Peter Maydell Use the safe_syscall wrapper for fcntl. This is straightforward now that we always use 'struct fcntl64' on the host, as we don't need to select whether to call the host's fcntl64 or fcntl syscall (a detail that the libc previously hid for us). Signed-off-by: Peter Maydell Reviewed-by: Laurent Vivier Signed-off-by: Riku Voipio --- linux-user/syscall.c | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 5c0d111..3dfaea9 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -783,6 +783,16 @@ safe_syscall5(int, mq_timedreceive, int, mqdes, char *, msg_ptr, * the libc function. */ #define safe_ioctl(...) safe_syscall(__NR_ioctl, __VA_ARGS__) +/* Similarly for fcntl. Note that callers must always: + * pass the F_GETLK64 etc constants rather than the unsuffixed F_GETLK + * use the flock64 struct rather than unsuffixed flock + * This will then work and use a 64-bit offset for both 32-bit and 64-bit hosts. + */ +#ifdef __NR_fcntl64 +#define safe_fcntl(...) safe_syscall(__NR_fcntl64, __VA_ARGS__) +#else +#define safe_fcntl(...) safe_syscall(__NR_fcntl, __VA_ARGS__) +#endif static inline int host_to_target_sock_type(int host_type) { @@ -5740,7 +5750,7 @@ static abi_long do_fcntl(int fd, int cmd, abi_ulong arg) if (ret) { return ret; } - ret = get_errno(fcntl(fd, host_cmd, &fl64)); + ret = get_errno(safe_fcntl(fd, host_cmd, &fl64)); if (ret == 0) { ret = copy_to_user_flock(arg, &fl64); } @@ -5752,7 +5762,7 @@ static abi_long do_fcntl(int fd, int cmd, abi_ulong arg) if (ret) { return ret; } - ret = get_errno(fcntl(fd, host_cmd, &fl64)); + ret = get_errno(safe_fcntl(fd, host_cmd, &fl64)); break; case TARGET_F_GETLK64: @@ -5760,7 +5770,7 @@ static abi_long do_fcntl(int fd, int cmd, abi_ulong arg) if (ret) { return ret; } - ret = get_errno(fcntl(fd, host_cmd, &fl64)); + ret = get_errno(safe_fcntl(fd, host_cmd, &fl64)); if (ret == 0) { ret = copy_to_user_flock64(arg, &fl64); } @@ -5771,23 +5781,25 @@ static abi_long do_fcntl(int fd, int cmd, abi_ulong arg) if (ret) { return ret; } - ret = get_errno(fcntl(fd, host_cmd, &fl64)); + ret = get_errno(safe_fcntl(fd, host_cmd, &fl64)); break; case TARGET_F_GETFL: - ret = get_errno(fcntl(fd, host_cmd, arg)); + ret = get_errno(safe_fcntl(fd, host_cmd, arg)); if (ret >= 0) { ret = host_to_target_bitmask(ret, fcntl_flags_tbl); } break; case TARGET_F_SETFL: - ret = get_errno(fcntl(fd, host_cmd, target_to_host_bitmask(arg, fcntl_flags_tbl))); + ret = get_errno(safe_fcntl(fd, host_cmd, + target_to_host_bitmask(arg, + fcntl_flags_tbl))); break; #ifdef F_GETOWN_EX case TARGET_F_GETOWN_EX: - ret = get_errno(fcntl(fd, host_cmd, &fox)); + ret = get_errno(safe_fcntl(fd, host_cmd, &fox)); if (ret >= 0) { if (!lock_user_struct(VERIFY_WRITE, target_fox, arg, 0)) return -TARGET_EFAULT; @@ -5805,7 +5817,7 @@ static abi_long do_fcntl(int fd, int cmd, abi_ulong arg) fox.type = tswap32(target_fox->type); fox.pid = tswap32(target_fox->pid); unlock_user_struct(target_fox, arg, 0); - ret = get_errno(fcntl(fd, host_cmd, &fox)); + ret = get_errno(safe_fcntl(fd, host_cmd, &fox)); break; #endif @@ -5815,11 +5827,11 @@ static abi_long do_fcntl(int fd, int cmd, abi_ulong arg) case TARGET_F_GETSIG: case TARGET_F_SETLEASE: case TARGET_F_GETLEASE: - ret = get_errno(fcntl(fd, host_cmd, arg)); + ret = get_errno(safe_fcntl(fd, host_cmd, arg)); break; default: - ret = get_errno(fcntl(fd, cmd, arg)); + ret = get_errno(safe_fcntl(fd, cmd, arg)); break; } return ret; @@ -10252,7 +10264,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1, if (ret) { break; } - ret = get_errno(fcntl(arg1, cmd, &fl)); + ret = get_errno(safe_fcntl(arg1, cmd, &fl)); break; default: ret = do_fcntl(arg1, arg2, arg3);