From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756826AbdKNXBz (ORCPT ); Tue, 14 Nov 2017 18:01:55 -0500 Received: from Galois.linutronix.de ([146.0.238.70]:39547 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756074AbdKNXBl (ORCPT ); Tue, 14 Nov 2017 18:01:41 -0500 Date: Wed, 15 Nov 2017 00:00:46 +0100 (CET) From: Thomas Gleixner To: "Kirill A. Shutemov" cc: "Kirill A. Shutemov" , Ingo Molnar , x86@kernel.org, "H. Peter Anvin" , Linus Torvalds , Andy Lutomirski , Nicholas Piggin , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCHv2 1/2] x86/mm: Do not allow non-MAP_FIXED mapping across DEFAULT_MAP_WINDOW border In-Reply-To: <20171114222718.76w4lmclf6wasbl3@node.shutemov.name> Message-ID: References: <20171114134322.40321-1-kirill.shutemov@linux.intel.com> <20171114202102.crpgiwgv2lu5aboq@node.shutemov.name> <20171114222718.76w4lmclf6wasbl3@node.shutemov.name> User-Agent: Alpine 2.20 (DEB 67 2015-01-07) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Linutronix-Spam-Score: -1.0 X-Linutronix-Spam-Level: - X-Linutronix-Spam-Status: No , -1.0 points, 5.0 required, ALL_TRUSTED=-1,SHORTCIRCUIT=-0.0001 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 15 Nov 2017, Kirill A. Shutemov wrote: > On Tue, Nov 14, 2017 at 09:54:52PM +0100, Thomas Gleixner wrote: > > On Tue, 14 Nov 2017, Kirill A. Shutemov wrote: > > > > > On Tue, Nov 14, 2017 at 05:01:50PM +0100, Thomas Gleixner wrote: > > > > @@ -198,11 +199,14 @@ arch_get_unmapped_area_topdown(struct fi > > > > /* requesting a specific address */ > > > > if (addr) { > > > > addr = PAGE_ALIGN(addr); > > > > + if (!mmap_address_hint_valid(addr, len)) > > > > + goto get_unmapped_area; > > > > + > > > > > > Here and in hugetlb_get_unmapped_area(), we should align the addr after > > > the check, not before. Otherwise the alignment itself can bring us over > > > the borderline as we align up. > > > > Hmm, then I wonder whether the next check against vm_start_gap() which > > checks against the aligned address is correct: > > > > addr = PAGE_ALIGN(addr); > > vma = find_vma(mm, addr); > > > > if (end - len >= addr && > > (!vma || addr + len <= vm_start_gap(vma))) > > return addr; > > I think the check is correct. The check is against resulting addresses > that end up in vm_start/vm_end. In our case we want to figure out what > user asked for. Well, but then checking just against the user supplied addr is only half of the story. addr = boundary - PAGE_SIZE - PAGE_SIZE / 2; len = PAGE_SIZE - PAGE_SIZE / 2; That fits, but then after alignment we end up with addr = boudary - PAGE_SIZE; and due to len > PAGE_SIZE this will result in a mapping which crosses the boundary, right? So checking against the PAGE_ALIGN(addr) should be the right thing to do. Thanks, tglx