From patchwork Thu Jul 26 13:29:46 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 142969 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp463396ljj; Thu, 26 Jul 2018 06:30:15 -0700 (PDT) X-Google-Smtp-Source: AAOMgpc4XkrC8/+nIB7KDV6JUPp5ZhaqtW27Fs89fkD/WbtDZllUc09SzETjEYS878/FgbxG8zEX X-Received: by 2002:a0c:9cca:: with SMTP id j10-v6mr1590858qvf.241.1532611815755; Thu, 26 Jul 2018 06:30:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532611815; cv=none; d=google.com; s=arc-20160816; b=B/HzFcwrDgAZMZeuTENYhJH2qBlIFqKyHhtmM7vPOXxd7V5Zr8C5yiDHAxc24XAcnW qiNW5W9rMZovY2OaLb3ZfJc01/R7q65w41V7ha2FhrZ2W8DnsEaj/6wtO/aZnxmY+kK9 Z99KVHSWiWc0UuQoPcwaUfJDtvQK0PVgtKUiZ/hDrN3EQflXz1LldmG1b/yY+GTKSxup 4id3LYajIcm0V/QTDpuJOw+grwVQPnfts7/oJMsT9tXqjBFfWll0fn/vvN+kg1qplC27 rJl9YSKs7A6Lm2Cdov04vmyj9fI1xo74it88Ea7FiP9oQKLLqF1bjoKViZadOYqYzk4t hbPQ== 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:dkim-signature:arc-authentication-results; bh=wgb29qVTxsksM7UXTcNm6n8cOSpKpK2tp1eBDFY0WJs=; b=Wnt+yJJq7taHVj1x+fsEi9K0nEvhQr3D+PGselNdQy6Pg3aw3GPYZbwc5omzfFq9Wk L7GGLTHVt100qFEkI3lheQV5js2G7Qub3eOULDgK2nzynVbumGf/9idduJiPaVmTKLPa 7UhzTzdh/r6Pv1egDURo47uvAEtSvnvdidTaMO3J7aIEca0OVavL6ZbqWAZYgN62k+4a G4nAF4Y1cVmNnOw2kBhb5vQTP2tkPO8EBvx6UBLe6pp/ZIQ3EDj9K5xhObuOyUk+nij2 c39dPYsHNcemT4jBzOCP8wkxLTKFJcePwUOqIkfBKPSbLMcitIIQ1VzJ0nudbH4Ar7du 4L+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=J4qj3i2G; 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 o5-v6si1295346qki.164.2018.07.26.06.30.15 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 26 Jul 2018 06:30:15 -0700 (PDT) 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; dkim=fail header.i=@linaro.org header.s=google header.b=J4qj3i2G; 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]:36015 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1figLP-0004PS-3e for patch@linaro.org; Thu, 26 Jul 2018 09:30:15 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50795) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1figL3-0004Oy-WB for qemu-devel@nongnu.org; Thu, 26 Jul 2018 09:29:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1figL1-0004G6-0r for qemu-devel@nongnu.org; Thu, 26 Jul 2018 09:29:54 -0400 Received: from mail-wm0-x241.google.com ([2a00:1450:400c:c09::241]:39181) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1figL0-0004Dx-Pk for qemu-devel@nongnu.org; Thu, 26 Jul 2018 09:29:50 -0400 Received: by mail-wm0-x241.google.com with SMTP id h20-v6so2005017wmb.4 for ; Thu, 26 Jul 2018 06:29:50 -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 :mime-version:content-transfer-encoding; bh=wgb29qVTxsksM7UXTcNm6n8cOSpKpK2tp1eBDFY0WJs=; b=J4qj3i2GGtcFgP3f6JnpPd1kG3YRz2J77491Q+GUXs8OZJKYEWtiHJbw9lEeYoh88+ oOsWfpIaicGqolG+UBhxVbXty6FnVD+7ER7UQEn3GpqhiXNeXPlOkKc/+j5LuEVAPGrt U4mJO3JCG/Cp+YUTUmzCOmIm4HqzfCEzONj1w= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=wgb29qVTxsksM7UXTcNm6n8cOSpKpK2tp1eBDFY0WJs=; b=qb5rx1PfWM3T1iC+2LbxGW3Mci8sTSCL+uyduKMuFETO1qlZ5Qw8u4RTZn3ZWPFlU8 FTe9ai9QwL13c8X3ao5ntzdPlN6vNMIzsgpD5QmQ1TpFmspOol9HWCjxRzv4G4fjVNeS HvrWkRaNmgOrKxO6g8AhaIc4LXBkjbPnuyPsFVonMtzhWgNJVsGQk51fzOJGx5dvF3zG +QTic0qyKn8F//PmpxsPB7iN73rTn/xaoBqvTkejeCSJgY3PbdFaXngy793Yy1QcxhE/ gGKV78ZxOje1V0ccEZq0LqEBlS7nw+/dtQJvwtKwx0c0VB3k3AFKktm6VL4WO6nyWJeC kStg== X-Gm-Message-State: AOUpUlFV4ILCH2G52uFRC8eNwNjWNljjdAp5+dap19Qx6IDE6CbUffrq lYZYMrngGoy52Dxc1qWYhPt3kA== X-Received: by 2002:a1c:9042:: with SMTP id s63-v6mr1520967wmd.91.1532611789732; Thu, 26 Jul 2018 06:29:49 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id d7-v6sm1547694wro.92.2018.07.26.06.29.48 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 26 Jul 2018 06:29:48 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id C88533E012E; Thu, 26 Jul 2018 14:29:47 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Date: Thu, 26 Jul 2018 14:29:46 +0100 Message-Id: <20180726132947.28538-2-alex.bennee@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180726132947.28538-1-alex.bennee@linaro.org> References: <20180726132947.28538-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c09::241 Subject: [Qemu-devel] [PATCH v1 for 3.0 1/2] linux-user/mmap.c: handle len = 0 maps correctly 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: umarcor <1783362@bugs.launchpad.net>, Riku Voipio , =?utf-8?q?Alex_Benn=C3=A9e?= , Laurent Vivier Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" I've slightly re-organised the check to more closely match the sequence that the kernel uses in do_mmap(). Signed-off-by: Alex Bennée Cc: umarcor <1783362@bugs.launchpad.net> --- linux-user/mmap.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) -- 2.17.1 diff --git a/linux-user/mmap.c b/linux-user/mmap.c index d0c50e4888..3ef69fa2d0 100644 --- a/linux-user/mmap.c +++ b/linux-user/mmap.c @@ -391,14 +391,22 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int prot, } #endif - if (offset & ~TARGET_PAGE_MASK) { + if (!len) { errno = EINVAL; goto fail; } len = TARGET_PAGE_ALIGN(len); - if (len == 0) - goto the_end; + if (!len) { + errno = EINVAL; + goto fail; + } + + if (offset & ~TARGET_PAGE_MASK) { + errno = EINVAL; + goto fail; + } + real_start = start & qemu_host_page_mask; host_offset = offset & qemu_host_page_mask;