Received: by 10.223.185.116 with SMTP id b49csp4211118wrg; Mon, 26 Feb 2018 13:15:59 -0800 (PST) X-Google-Smtp-Source: AH8x225QOSH97fAZ/ur3QYBARmDZYX8XTLSuqsyWrH97PNsMB2/mZcxjQtwoCjOnXW6XSPl1klpu X-Received: by 2002:a17:902:6bc6:: with SMTP id m6-v6mr12158656plt.100.1519679759477; Mon, 26 Feb 2018 13:15:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519679759; cv=none; d=google.com; s=arc-20160816; b=ieVB2woMZQkLKm9V6HWPaOmKUYEp5xelNbSqggjw5q4nvw75ytqPlD1CEkk3qGr+na jzT3axvvNNcPFsIKYBJY7FSfxO4TFplVpgHV25FzUhc77BxCUAAiJPGHT//o2sH7Ovl4 681VcyajCGfJHf7jO1QgJr+llLrNp7WSSeim1Z0p5vi6jwNIJ7Ie7qbO9noD2k4MHeMa x7Dl9GDDRcZCKLJbEk73dXltn7aUHCyEMe4ECQ6rUKaK6JqCXHgn7wvjRDk3r+Y2chnm RokxOVZ0fNOoqt+PWSszD7sayxZYbD3otYigriHW7MM98oYheRPZ4zcWclMXe3AcId21 FAjA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=i289Kps8/WCOZz8b3MsDosmihuLz7vh+cC/s4mwF54Q=; b=wWffi48BARE+6zPJrg2mTcSxATCztaBhLYTFjWRo4NMMF3pauTMUPO4Mk1xjk6Nz+G npzK7LzTkO9KHoN0ZuszzoCbzuxl2sPgbLUnZmqjeP9OjRgST2iXet+q0W6Ih179oVGs 4iBXuK3d3QPTpGsWyBX7+sDnuenv3IQwUfBRZSJjcPc06+1odhawnnrnBXfdAW4sR7Vl E44og/qook0dRkzv1+UwlqQY2CqBz6HKcMCj8oDa4KeFXc6FCYqb5zZKOi2u/FHsDxgi mG4uGJj/jUGfspKYljctKwb0e0+qZCWQCr+7j2QlB89Wri4J3S8IO5BxIfDpMIIceUAJ Aqpg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=eYxOgkXv; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u19si5902403pgv.195.2018.02.26.13.15.40; Mon, 26 Feb 2018 13:15:59 -0800 (PST) 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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=eYxOgkXv; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751761AbeBZVOW (ORCPT + 99 others); Mon, 26 Feb 2018 16:14:22 -0500 Received: from mail-lf0-f67.google.com ([209.85.215.67]:34252 "EHLO mail-lf0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750826AbeBZVOU (ORCPT ); Mon, 26 Feb 2018 16:14:20 -0500 Received: by mail-lf0-f67.google.com with SMTP id l191so24374297lfe.1 for ; Mon, 26 Feb 2018 13:14:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=i289Kps8/WCOZz8b3MsDosmihuLz7vh+cC/s4mwF54Q=; b=eYxOgkXvl7Emc035/QMC/yaOhtepnZRabVoPU5aD69SUIsPDi5MQFxpprHcHF3b0yC ufwL0+KXA82wnr6LoKQ9dkgzPCZCduH4ZcGZIUf6M3vGXlfOotPBrrGdQcOU8xMXo7M9 TgriM9BaLmSqPJt9P9ZTOdBtvzdaXUZ3+Ps0nXryDVJs71KjTjqSGG+eKvi6a3USNMC3 d/dS59thA6beF91qCvY+kPF0iaGAJycmXF7DXQYHY/9rvLMiEfoEngAnwIh2dTUVHadK QFiusJRPz5nafYlzt0MUX8caW9lD0q4taUhq2bFFGwpIK82VKba8uuvDwD9O+syw3NW2 TKjw== 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; bh=i289Kps8/WCOZz8b3MsDosmihuLz7vh+cC/s4mwF54Q=; b=Y8C8pekkcffdeGknIHgWhummUPwiUsfUUyN5X3rJEp4cdAFt7FCWiq2aigX1zT4cg7 0Ry5nJJcWv8x2jcjam9Zhf9z0KYY/S75jAvslz+trvS/4027zWsAltSXAVIV1KoyB1Ua qqyeXCNgSvRXNxIA0STxJeNDLZtrlUkusERT5nynbpg5UOAllpOp5FdeVMxj8SP6wmbM 6kkAAvlf1vtRriPrOKPrMpwUm7zwhBr5ytidxobmrcjFeleDUKuUUlXLm2Kt4AwSphli lu3qjKartLXPXCCdDGVcXqfo0euek5ilu9oKc9BFsJ1GDsuysIx/ciXuZsF5Qpe2IZVy GY2A== X-Gm-Message-State: APf1xPCDoiKMFZQqiOZ/tvpsa9JmKdIifjo/uEbZYQnUemQua1IdlYy6 B5BzUwkVRm4eit8Nliy1Skk= X-Received: by 10.46.129.144 with SMTP id e16mr9097658ljg.94.1519679659432; Mon, 26 Feb 2018 13:14:19 -0800 (PST) Received: from localhost.localdomain (broadband-188-255-70-164.moscow.rt.ru. [188.255.70.164]) by smtp.gmail.com with ESMTPSA id n18sm2196248lfh.24.2018.02.26.13.14.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 26 Feb 2018 13:14:17 -0800 (PST) From: Ilya Smith To: tglx@linutronix.de, mingo@redhat.com, hpa@zytor.com, x86@kernel.org, kirill.shutemov@linux.intel.com, dsafonov@virtuozzo.com, mhocko@suse.com, hughd@google.com, gregkh@linuxfoundation.org, craigb@google.com, oleg@redhat.com, linux-kernel@vger.kernel.org Cc: Ilya Smith Subject: [RFC PATCH] Take mmap_min_addr into account while choosing unmapped address for x86-64. Date: Tue, 27 Feb 2018 00:12:57 +0300 Message-Id: <20180226211257.63067-1-blackzert@gmail.com> X-Mailer: git-send-email 2.14.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org It prevent situation when vm_unmapped_area chose address between PAGE_SIZE and mmap_min_addr range. In this case mmap will fail with EPERM without a good reason. As test-case of such situation we may hard-code address between PAGE_SIZE and 65536 inside unmapped_area_topdown function. Signed-off-by: Ilya Smith --- arch/x86/kernel/sys_x86_64.c | 5 +++-- arch/x86/mm/mmap.c | 4 ++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c index 676774b9bb8d..1752fe5cb735 100644 --- a/arch/x86/kernel/sys_x86_64.c +++ b/arch/x86/kernel/sys_x86_64.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include @@ -185,7 +186,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0, return addr; /* requested length too big for entire address space */ - if (len > TASK_SIZE) + if (len > TASK_SIZE - mmap_min_addr) return -ENOMEM; /* No address checking. See comment at mmap_address_hint_valid() */ @@ -210,7 +211,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0, info.flags = VM_UNMAPPED_AREA_TOPDOWN; info.length = len; - info.low_limit = PAGE_SIZE; + info.low_limit = max(PAGE_SIZE, mmap_min_addr); info.high_limit = get_mmap_base(0); /* diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c index 155ecbac9e28..b6d0c317639e 100644 --- a/arch/x86/mm/mmap.c +++ b/arch/x86/mm/mmap.c @@ -31,6 +31,7 @@ #include #include #include +#include #include #include "physaddr.h" @@ -220,6 +221,9 @@ bool mmap_address_hint_valid(unsigned long addr, unsigned long len) if (TASK_SIZE - len < addr) return false; + if (addr < mmap_min_addr) + return false; + return (addr > DEFAULT_MAP_WINDOW) == (addr + len > DEFAULT_MAP_WINDOW); } -- 2.14.1