Received: by 10.213.65.68 with SMTP id h4csp12085imn; Mon, 19 Mar 2018 17:51:12 -0700 (PDT) X-Google-Smtp-Source: AG47ELu/BDRb9tqpoyMXMSRmlAU/7pCz/DtEzRGyTEzv6HXxBj3sj6JJ2UGX0qSpaYjPExDYwIJJ X-Received: by 10.99.53.6 with SMTP id c6mr10750632pga.413.1521507072212; Mon, 19 Mar 2018 17:51:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521507072; cv=none; d=google.com; s=arc-20160816; b=rBKtt7v5VbnRRsx1BfE3FNyP8vwUaGVXJZWyNdOPaLfv+FxN/myTyV+eu4v6U7VLBJ j8+J0S72Y2cOauIJmM7Y0CPm2FIldYu7dO2P46a26S7UscoKp4nTStYtIRtC0GkEQbZz 1fhuLkVoN/haQUsyhGIAK3iIDSHEYVtQawwK+sEMV1D/L0xFQnq6EQdKANy1+Qzf3tVs ld4iBjpX/+A5DTIfT6/6EA8SXU2Q11tMKB1Wg5nCcU0Fw9S2Rv9gIwG6+PSf0pZwWkck sG1ApbcR/Qzoz9HTgWvIl7OLfl0XYCVFQY09IK0D0rAStql9j87AwgQXwBuGlHmFiA6L paSw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=QSWNyvGwLqA7C166ixnFHYZPNLHpfyOdXYcbrMN9dRI=; b=SnsvXTi+tfWt2HMdTddm4fgrujb33tXjkBydaEKAJzeSufvRxWrOwoAGVFxQOWqUGF x7/zHrmolc3mnvdly16j3+0/ydc0JZdzAG0+3F+QoIMp71aPs5dECgfiKhAYv05O3DLM 2K3jD4MUkFQVZbHb2n8a/rVL5CG45MzzAMJ0T3YOSLorYWt5pfELouUrvSFrSQO8Zki1 SwQJcvXeZKY10ZKBR4ECu5bhykFoz8pqsKgyudj+NcRUu8+7z9wFICmdB69wFd4jkv0+ l1z0YId5iPyUfqG3y8TLaOOjASq1INu29HD3SFDvXtDAr806RXfmar5R7Vm6fFNeElFC i1yQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k73si289621pgc.707.2018.03.19.17.50.58; Mon, 19 Mar 2018 17:51:12 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1030884AbeCSSSt (ORCPT + 99 others); Mon, 19 Mar 2018 14:18:49 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:46640 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1030567AbeCSSSo (ORCPT ); Mon, 19 Mar 2018 14:18:44 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 8178D1070; Mon, 19 Mar 2018 18:18:43 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dmitry Safonov , 0x7f454c46@gmail.com, linux-mm@kvack.org, Andy Lutomirski , Cyrill Gorcunov , Borislav Petkov , "Kirill A. Shutemov" , Thomas Gleixner , Sasha Levin Subject: [PATCH 4.9 020/241] x86/mm: Make mmap(MAP_32BIT) work correctly Date: Mon, 19 Mar 2018 19:04:45 +0100 Message-Id: <20180319180752.005376139@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180319180751.172155436@linuxfoundation.org> References: <20180319180751.172155436@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.9-stable review patch. If anyone has any objections, please let me know. ------------------ From: Dmitry Safonov [ Upstream commit 3e6ef9c80946f781fc25e8490c9875b1d2b61158 ] mmap(MAP_32BIT) is broken due to the dependency on the TIF_ADDR32 thread flag. For 64bit applications MAP_32BIT will force legacy bottom-up allocations and the 1GB address space restriction even if the application issued a compat syscall, which should not be subject of these restrictions. For 32bit applications, which issue 64bit syscalls the newly introduced mmap base separation into 64-bit and compat bases changed the behaviour because now a 64-bit mapping is returned, but due to the TIF_ADDR32 dependency MAP_32BIT is ignored. Before the separation a 32-bit mapping was returned, so the MAP_32BIT handling was irrelevant. Replace the check for TIF_ADDR32 with a check for the compat syscall. That solves both the 64-bit issuing a compat syscall and the 32-bit issuing a 64-bit syscall problems. [ tglx: Massaged changelog ] Signed-off-by: Dmitry Safonov Cc: 0x7f454c46@gmail.com Cc: linux-mm@kvack.org Cc: Andy Lutomirski Cc: Cyrill Gorcunov Cc: Borislav Petkov Cc: "Kirill A. Shutemov" Link: http://lkml.kernel.org/r/20170306141721.9188-5-dsafonov@virtuozzo.com Signed-off-by: Thomas Gleixner Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- arch/x86/kernel/sys_x86_64.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) --- a/arch/x86/kernel/sys_x86_64.c +++ b/arch/x86/kernel/sys_x86_64.c @@ -100,7 +100,7 @@ out: static void find_start_end(unsigned long flags, unsigned long *begin, unsigned long *end) { - if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) { + if (!in_compat_syscall() && (flags & MAP_32BIT)) { /* This is usually used needed to map code in small model, so it needs to be in the first 31bit. Limit it to that. This means we need to move the @@ -175,7 +175,7 @@ arch_get_unmapped_area_topdown(struct fi return addr; /* for MAP_32BIT mappings we force the legacy mmap base */ - if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) + if (!in_compat_syscall() && (flags & MAP_32BIT)) goto bottomup; /* requesting a specific address */