From patchwork Thu Aug 11 17:59:39 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 9275733 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 1C8E060780 for ; Thu, 11 Aug 2016 18:00:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 10C2E286EC for ; Thu, 11 Aug 2016 18:00:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 03A7F286F0; Thu, 11 Aug 2016 18:00:01 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 903D5286EC for ; Thu, 11 Aug 2016 18:00:00 +0000 (UTC) Received: from localhost ([::1]:49996 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bXuGt-0003Nx-Bu for patchwork-qemu-devel@patchwork.kernel.org; Thu, 11 Aug 2016 13:59:59 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37678) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bXuGf-0003Nr-Dn for qemu-devel@nongnu.org; Thu, 11 Aug 2016 13:59:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bXuGd-0000xc-GM for qemu-devel@nongnu.org; Thu, 11 Aug 2016 13:59:44 -0400 Received: from orth.archaic.org.uk ([2001:8b0:1d0::2]:58608) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bXuGd-0000xB-8K for qemu-devel@nongnu.org; Thu, 11 Aug 2016 13:59:43 -0400 Received: from pm215 by orth.archaic.org.uk with local (Exim 4.84_2) (envelope-from ) id 1bXuGa-0002k9-Oq; Thu, 11 Aug 2016 18:59:40 +0100 From: Peter Maydell To: qemu-devel@nongnu.org Date: Thu, 11 Aug 2016 18:59:39 +0100 Message-Id: <1470938379-1133-1-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 2.7.4 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2001:8b0:1d0::2 Subject: [Qemu-devel] [PATCH for-2.7] linux-user: Fix llseek with high bit of offset_low set 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 , Chanho Park , patches@linaro.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP The llseek syscall takes two 32-bit arguments, offset_high and offset_low, which must be combined to form a single 64-bit offset. Unfortunately we were combining them with (uint64_t)arg2 << 32) | arg3 and arg3 is a signed type; this meant that when promoting arg3 to a 64-bit type it would be sign-extended. The effect was that if the offset happened to have bit 31 set then this bit would get sign-extended into all of bits 63..32. Explicitly cast arg3 to abi_ulong to avoid the erroneous sign extension. Reported-by: Chanho Park Signed-off-by: Peter Maydell Tested-by: Chanho Park --- Long-standing bug and we're quite close to 2.7 but the fix is trivial so if somebody would like to review it I think we could put it in... linux-user/syscall.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index ebdb753..b4e21d3 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -9406,7 +9406,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1, { int64_t res; #if !defined(__NR_llseek) - res = lseek(arg1, ((uint64_t)arg2 << 32) | arg3, arg5); + res = lseek(arg1, ((uint64_t)arg2 << 32) | (abi_ulong)arg3, arg5); if (res == -1) { ret = get_errno(res); } else {