From patchwork Thu Jan 10 08:37:37 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 1022804 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=vivier.eu Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 43b0Nx4gYMz9s55 for ; Thu, 10 Jan 2019 20:01:53 +1100 (AEDT) Received: from localhost ([127.0.0.1]:59644 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ghWDn-0008Or-LH for incoming@patchwork.ozlabs.org; Thu, 10 Jan 2019 04:01:51 -0500 Received: from eggs.gnu.org ([209.51.188.92]:55290) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ghW3h-00009G-5E for qemu-devel@nongnu.org; Thu, 10 Jan 2019 03:51:26 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ghVqm-00015j-TN for qemu-devel@nongnu.org; Thu, 10 Jan 2019 03:38:06 -0500 Received: from mout.kundenserver.de ([212.227.126.135]:46975) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ghVqm-000157-44 for qemu-devel@nongnu.org; Thu, 10 Jan 2019 03:38:04 -0500 Received: from localhost.localdomain ([78.238.229.36]) by mrelayeu.kundenserver.de (mreue009 [212.227.15.167]) with ESMTPSA (Nemesis) id 1MYNW6-1glU6w2Zve-00VPfc; Thu, 10 Jan 2019 09:37:48 +0100 From: Laurent Vivier To: qemu-devel@nongnu.org Date: Thu, 10 Jan 2019 09:37:37 +0100 Message-Id: <20190110083737.5036-3-laurent@vivier.eu> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190110083737.5036-1-laurent@vivier.eu> References: <20190110083737.5036-1-laurent@vivier.eu> MIME-Version: 1.0 X-Provags-ID: V03:K1:FCukf0J0R6N2vBb01LFbikhioT4mFtVg5TupSdt6YSBlr5th+bO I1h0Oh6KmtNUKKstWBr7RJY+xgdGMwUOHOUpnr0UMgob3hc3OAFoGOS51fYHt7Gk68C+h8H j/9x3AhvncRi/mxZp1+/VD5zBpJjPEppSHwDzurqZydkdDbM23aQD+LmnTwoYBx/nTxCabV 1DLI7kNMkLL2nrqGDGMHQ== X-UI-Out-Filterresults: notjunk:1; V03:K0:iHF+0gud8BM=:G6AmtAOZVqtdvORfmoKha4 ReqGQTQTTlvYS6W8D0cFwuXsPsIP1rmzt40eXaiK7CfwTzSCGxBQ8IYHV8eCPN8vIBJXmMoUs jY5WoqIKUJ14ohDa6jgr1VGTG+8/RBt0x2sl5AGzGGHJqcCzXCMLu3FVsFllQRQFVzEE1X2Tw NT2vvS3rrZpFCEs1ypkSVdqq18wkqOuoT55eh8Yyfdz/PuMzpIEcDSK/ryWB6nan+Oh2JMv8j xcvA/Vi0Ig8t5+MsLU71fEQ2EYhTE7a7t50XdEJQOQPJlyID2WdzWNdHyZWQQjuASRxB1g7ww uoqnV26kzjHE3NJAGDNYqdyqBeFwoj6qoSnguOH696NgtjC1qR+5U1RSGJqyYjLCcJpV0Hakg ga/i5aq54kp1e8FPLhrwdDxNa+N7fTJlEZ57qKwLkT0jGqZYlshTlHqtWS16ujBdOd4Kueb0V Bgta8k9SqOnXGoZX8Q5SA71tuYDDiszQGEhxo3AIsGpad6qcw8jVT/NZYijNhdrn87iiTBKxG cRjnYV/a1z2o0prBWvGNkUlEHHIdyzDg+oZoW6J2kVuh6ppjkDNljhvsTBiWbAQeVGzEAH8R5 nZu4rgCPyfZQGFy516SUgD7Zm47OZyDiEksxyYaW1Dd7LttH3g0i3JAfz4VUSE1pk8VFBSwxJ j9m+KhaTMCYMCx3oDu1f8oxbmQBtPgvhraUxDfFDD4SeO3eLE3AnQsUZHWRRxrEm5qLp4JnAj gxH9+Gn9PfzARKl2bePK2TYhgIFNK3zsi8u2/YYmvjhTzLaXVgkqhF85Fxo= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 212.227.126.135 Subject: [Qemu-devel] [PULL 2/2] linux-user: make pwrite64/pread64(fd, NULL, 0, offset) return 0 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 , Riku Voipio , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?b?w6k=?= , Laurent Vivier Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Peter Maydell Linux returns success if pwrite64() or pread64() are called with a zero length NULL buffer, but QEMU was returning -TARGET_EFAULT. This is the same bug that we fixed in commit 58cfa6c2e6eb51b23cc9 for the write syscall, and long before that in 38d840e6790c29f59 for the read syscall. Fixes: https://bugs.launchpad.net/qemu/+bug/1810433 Signed-off-by: Peter Maydell Reviewed-by: Laurent Vivier Reviewed-by: Philippe Mathieu-Daudé Message-Id: <20190108184900.9654-1-peter.maydell@linaro.org> Signed-off-by: Laurent Vivier --- linux-user/syscall.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 29bac79b61..d6605b8b50 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -9716,8 +9716,15 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1, arg4 = arg5; arg5 = arg6; } - if (!(p = lock_user(VERIFY_WRITE, arg2, arg3, 0))) - return -TARGET_EFAULT; + if (arg2 == 0 && arg3 == 0) { + /* Special-case NULL buffer and zero length, which should succeed */ + p = 0; + } else { + p = lock_user(VERIFY_WRITE, arg2, arg3, 0); + if (!p) { + return -TARGET_EFAULT; + } + } ret = get_errno(pread64(arg1, p, arg3, target_offset64(arg4, arg5))); unlock_user(p, arg2, ret); return ret; @@ -9726,8 +9733,15 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1, arg4 = arg5; arg5 = arg6; } - if (!(p = lock_user(VERIFY_READ, arg2, arg3, 1))) - return -TARGET_EFAULT; + if (arg2 == 0 && arg3 == 0) { + /* Special-case NULL buffer and zero length, which should succeed */ + p = 0; + } else { + p = lock_user(VERIFY_READ, arg2, arg3, 1); + if (!p) { + return -TARGET_EFAULT; + } + } ret = get_errno(pwrite64(arg1, p, arg3, target_offset64(arg4, arg5))); unlock_user(p, arg2, 0); return ret;