From patchwork Fri Dec 15 15:18:00 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 122110 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp605878qgn; Fri, 15 Dec 2017 07:20:32 -0800 (PST) X-Google-Smtp-Source: ACJfBouPn/IGbWg1hoTSgR2IB69OCd+Hwj8xjNw4cRJYXD+W50SPD2uaGaQcC0f6+U/tbmJDUDhl X-Received: by 10.37.123.69 with SMTP id w66mr7663991ybc.520.1513351232252; Fri, 15 Dec 2017 07:20:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1513351232; cv=none; d=google.com; s=arc-20160816; b=PkDEXCQBbTXlmy6VrRh0yZvxGm03TXtYyNvTxbNHn4BZqDIl1NsMUFvfbGtEWgKQSU ctt6tzvLUEUYp1TiiMgq8/TgYzrNMc9zhSc3/zk6G2vMtKYrElxnlDD5/RhcMtnmR6rP U123GwJy2q78J49GPZ7Q4BBl5Jc86oBvc2jl9i4hSXr8iCbv3CwMSEBJUdDFg2ICaj2L RQiqJQZdday467BnQsUfhNTGghqrmIcB70Rgg8prleN2NyNo8XpvrdAFmxqfitfTojQ8 h8rPYBrLSfaCPeYN9nlNASjjcPrlLQvyexkISZjo1ct03p7dPFiqrRtJHDadx+cgxjrZ 1Tkw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:message-id:date:to:from :arc-authentication-results; bh=2Qqa3lw1kRuxM/DNq8xw3KRP1RXh77sQY1sBkxRc2aU=; b=kzHGvMRdnGxvy+96Rzb8XpMiEOB4YFpuzf85ppxhjVkHX+m+KRNTrNJeGaH6sWMm7n 2pyRTvVO/j8/pJJkJ+rJ2XFx3E0PmwSNvp/7IPYTk3y5nQZ4m4+n6nQyTFCAUatz09aj eg/+I+La7xH42equPvYV87IrVeLzBK4lOWCbTgmUa20JQBbOIjSpHF5Zw90IjAVYORsn IV92vpw3tD71bm3rBPLtYDarQENkwfTk5rm/TlwpWJiFcaccp0XNS2lxSIEquxk0OCYX W+aCcHNZT4g+UtCBWKzF+Lj34D2CHJKziqkCzVvDB95xGNjvHjR9+1IPWtt3ifdMH7X+ IkxA== ARC-Authentication-Results: i=1; mx.google.com; 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 sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id f6si1369442ybm.520.2017.12.15.07.20.32 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 15 Dec 2017 07:20:32 -0800 (PST) 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; 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 sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:47094 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ePrmp-0006sk-QF for patch@linaro.org; Fri, 15 Dec 2017 10:20:31 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46158) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ePrkY-0005RX-Ui for qemu-devel@nongnu.org; Fri, 15 Dec 2017 10:18:11 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ePrkT-0008Re-B0 for qemu-devel@nongnu.org; Fri, 15 Dec 2017 10:18:10 -0500 Received: from orth.archaic.org.uk ([2001:8b0:1d0::2]:39210) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ePrkT-0008QM-43 for qemu-devel@nongnu.org; Fri, 15 Dec 2017 10:18:05 -0500 Received: from pm215 by orth.archaic.org.uk with local (Exim 4.89) (envelope-from ) id 1ePrkP-00027j-La; Fri, 15 Dec 2017 15:18:01 +0000 From: Peter Maydell To: qemu-devel@nongnu.org Date: Fri, 15 Dec 2017 15:18:00 +0000 Message-Id: <1513351080-25917-1-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 2.7.4 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2001:8b0:1d0::2 Subject: [Qemu-devel] [PATCH] linux-user: Translate flags argument to dup3 syscall 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 , Bruno Haible , Laurent Vivier Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" The third argument to dup3() is a flags word which may be O_CLOEXEC. We weren't translating this flag from target to host value, which meant that if the target used a different value from the host (eg sparc guest and x86 host) the dup3() call would fail EINVAL. Do the correct translation. Fixes: https://bugs.launchpad.net/qemu/+bug/1704658 Reported-by: Bruno Haible Signed-off-by: Peter Maydell --- linux-user/syscall.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) -- 2.7.4 Reviewed-by: Laurent Vivier diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 39553c8..41ded90 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -8490,11 +8490,19 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1, #endif #if defined(CONFIG_DUP3) && defined(TARGET_NR_dup3) case TARGET_NR_dup3: - ret = get_errno(dup3(arg1, arg2, arg3)); + { + int host_flags; + + if ((arg3 & ~TARGET_O_CLOEXEC) != 0) { + return -EINVAL; + } + host_flags = target_to_host_bitmask(arg3, fcntl_flags_tbl); + ret = get_errno(dup3(arg1, arg2, host_flags)); if (ret >= 0) { fd_trans_dup(arg1, arg2); } break; + } #endif #ifdef TARGET_NR_getppid /* not on alpha */ case TARGET_NR_getppid: