From patchwork Mon Apr 1 20:59:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 161583 Delivered-To: patch@linaro.org Received: by 2002:a02:c6d8:0:0:0:0:0 with SMTP id r24csp1002716jan; Mon, 1 Apr 2019 15:19:42 -0700 (PDT) X-Google-Smtp-Source: APXvYqzLn3S5F6x9Gr3UyDsukmbX1nh++xL8RxhAKUrb4V+4HparOUUr5/y1T4e2xiyczUVEDO5l X-Received: by 2002:a25:57c4:: with SMTP id l187mr54949001ybb.435.1554157182671; Mon, 01 Apr 2019 15:19:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554157182; cv=none; d=google.com; s=arc-20160816; b=nSU+3TOM2ixI7woAE7sDAn4QEjj0fSC9LFSQmlgE5LlCH0vwolXzZdjr0Glnw6NjI9 map/8IiJCqVryLKiToJF3N+mPKhVII3D44AyBL2m6T4kTIQXH3Vu8TByISiMXuTYQFKm AAmJbBXveNvjB8p/8wLfnpM1XAQS/MXaVUbrWTbIn9nV6x1GK0VC/KuTPFJRDxtT2TX3 0W9flgKMYAzGYRDw75YXK/Z6rt63kPSYmkIGtuoBvKWVfCYZdoKMDdaDfWBa4CYwSJPd g6RcVZg+sycjPTIXLGVbfoQcCnC5/bRRLk7bvKusgTrZ5HqXEdlm8+7FODd76Rac/NdQ qmrA== 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:message-id:mime-version:references :in-reply-to:date:to:from; bh=5DDWuqsJkV/h9T5L2ArmJTqjRP00itWNlLTWMuaDOEY=; b=VBq1LblKlyRLLrZxctnAdRbJkrNzPxFY5vBX64cgoAg4zLCdr1vDZSxZpl73kdAHGQ g1ZK+2rmxT07Z/go1pSobe3ayd0wJdk7CYAN0rxOqqPDZzAPQ8bc7cX1KY42OeI3kkWB HlBFgtCiajrHLuoZtqRxQAW0pDLZPMCulHvdV602JLvP7/YgrE4PtC3nxP24Tra/20a1 El5ceieonBIDYKnmS6+mKjABm79As+1SO6JUo5VNvJDHKgZnDMu0zUhS/z+ahs8GyFs8 mwO4fouMDs3Ka4gfdCB/0CKO7H5CRJ5B9d8KKi7/BJ6Y7pHLAWDmNjqctQtl7rIYf+BY MJ7Q== 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"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id d63si6482621ybf.382.2019.04.01.15.19.42 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 01 Apr 2019 15:19:42 -0700 (PDT) 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"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: from localhost ([127.0.0.1]:58560 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hB5HK-0000HP-3p for patch@linaro.org; Mon, 01 Apr 2019 18:19:42 -0400 Received: from eggs.gnu.org ([209.51.188.92]:42930) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hB478-0003ii-II for qemu-devel@nongnu.org; Mon, 01 Apr 2019 17:05:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hB476-0004ym-Ad for qemu-devel@nongnu.org; Mon, 01 Apr 2019 17:05:06 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:59922 helo=mx0a-001b2d01.pphosted.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hB476-0004pz-4S for qemu-devel@nongnu.org; Mon, 01 Apr 2019 17:05:04 -0400 Received: from pps.filterd (m0098416.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x31L4i17163580 for ; Mon, 1 Apr 2019 17:04:53 -0400 Received: from e34.co.us.ibm.com (e34.co.us.ibm.com [32.97.110.152]) by mx0b-001b2d01.pphosted.com with ESMTP id 2rksx78v4w-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Mon, 01 Apr 2019 17:04:48 -0400 Received: from localhost by e34.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 1 Apr 2019 22:03:03 +0100 Received: from b03cxnp08027.gho.boulder.ibm.com (9.17.130.19) by e34.co.us.ibm.com (192.168.1.134) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Mon, 1 Apr 2019 22:02:59 +0100 Received: from b03ledav005.gho.boulder.ibm.com (b03ledav005.gho.boulder.ibm.com [9.17.130.236]) by b03cxnp08027.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id x31L2wGU52625408 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 1 Apr 2019 21:02:58 GMT Received: from b03ledav005.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C9059BE04F; Mon, 1 Apr 2019 21:02:58 +0000 (GMT) Received: from b03ledav005.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 8FB55BE054; Mon, 1 Apr 2019 21:02:58 +0000 (GMT) Received: from localhost (unknown [9.80.94.43]) by b03ledav005.gho.boulder.ibm.com (Postfix) with ESMTP; Mon, 1 Apr 2019 21:02:58 +0000 (GMT) From: Michael Roth To: qemu-devel@nongnu.org Date: Mon, 1 Apr 2019 15:59:54 -0500 X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190401210011.16009-1-mdroth@linux.vnet.ibm.com> References: <20190401210011.16009-1-mdroth@linux.vnet.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 x-cbid: 19040121-0016-0000-0000-0000099B1DFB X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00010857; HX=3.00000242; KW=3.00000007; PH=3.00000004; SC=3.00000283; SDB=6.01182941; UDB=6.00619269; IPR=6.00963684; MB=3.00026249; MTD=3.00000008; XFM=3.00000015; UTC=2019-04-01 21:03:01 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 19040121-0017-0000-0000-000042A9B24F Message-Id: <20190401210011.16009-81-mdroth@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2019-04-01_06:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1904010136 X-MIME-Autoconverted: from 8bit to quoted-printable by mx0b-001b2d01.pphosted.com id x31L4i17163580 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 148.163.158.5 Subject: [Qemu-devel] [PATCH 80/97] 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 , qemu-stable@nongnu.org, 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 (cherry picked from commit 2bd3f8998e1e7dcd9afc29fab252fb9936f9e956) *drop functional dep. on 2852aafd9d Signed-off-by: Michael Roth --- linux-user/syscall.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) -- 2.17.1 diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 1477509cf2..0859739e9d 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -10910,8 +10910,15 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1, arg4 = arg5; arg5 = arg6; } - if (!(p = lock_user(VERIFY_WRITE, arg2, arg3, 0))) - goto 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) { + goto efault; + } + } ret = get_errno(pread64(arg1, p, arg3, target_offset64(arg4, arg5))); unlock_user(p, arg2, ret); break; @@ -10920,8 +10927,15 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1, arg4 = arg5; arg5 = arg6; } - if (!(p = lock_user(VERIFY_READ, arg2, arg3, 1))) - goto 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) { + goto efault; + } + } ret = get_errno(pwrite64(arg1, p, arg3, target_offset64(arg4, arg5))); unlock_user(p, arg2, 0); break;