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: 155128 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp1657010jaa; Thu, 10 Jan 2019 01:01:34 -0800 (PST) X-Google-Smtp-Source: ALg8bN6jpXKCRiMM+pnuThxrWsGG8/qkjiNWMjfjDNUmv9f6UymtZbd1bpohm7qwnuLD5lMRrfPi X-Received: by 2002:a7b:c2a9:: with SMTP id c9mr9711203wmk.44.1547110894782; Thu, 10 Jan 2019 01:01:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547110894; cv=none; d=google.com; s=arc-20160816; b=ulOkJoMymHBZt0vRptql4+pCxHvMHsQocrwAXmb/OAPJP6HVLIvnoB/SWJRiS8IAwK pZAcLdo/K5LYqC0toWMAdBvd6HBP5XVVVJpapde8bmRM5x+D/kU9Nh47fpkCQOKqL/O9 qUQoDIVvx3ZLIy0gV0r3b2oi8FOgnoDnLSqMV4SGWqVGyG2VDALAem6gez6SZC32BnpO CLFf9Vq1FOCYZj+++NkI3AMIKUHuhUsGqMcHx0/BHPVTRc/99KUYG4Qwfxm0P32EwYvF UisxUe/CU9JYhx/leakVPWk0IhXzMmeijLtCMad9iZyQlQrHh8H0dC1j/neym/d2H+jO MXuQ== 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 :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from; bh=cezxLPMp2xxdViyNEcBehmXCCaYdP0A9O7JMMNASRbo=; b=wBNuUQegjVY/C7pUcp5/IugQ8Rgo5fEuD9CMNmdV66J+oCDYx+mKUdkzKFtAlxa7Zl Ma1PACAzbQochhQh/3WXHRLeCP8/PeZTbZnDtHTHrvRtXA5Up8cHoIrR8aX9e0rDxWMp AigyxrSsQY+ITOK1cVk+VqYOKw6CcrU+zULYiRs5UjRrA96/E9uVzM3U8fLxE5EK6eM5 iNLwPP+Ovmukfd4eLTbXuxaRy7AeSoEVXv2D459M82gOmlIsBEpi67wQ5yspMEgIaCw4 uvyD6Hogy+AC/FrZEE9amMD+yGoax5spV8ObqQjqcuzT236OKhxoTkRd6cMB5CzhS5lm DhAg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id z4si42014252wrq.360.2019.01.10.01.01.34 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 10 Jan 2019 01:01:34 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Received: from localhost ([127.0.0.1]:59644 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ghWDV-0008Or-PF for patch@linaro.org; Thu, 10 Jan 2019 04:01:33 -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+patch=linaro.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(-) -- 2.20.1 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;