Received: by 10.223.164.202 with SMTP id h10csp387328wrb; Mon, 13 Nov 2017 08:01:24 -0800 (PST) X-Google-Smtp-Source: AGs4zMZsQUgc0YuUmG4K82GxsT0xGpSkRJ7fLT7VV2YzuccbnLxKL7dIjTAQlOpUMMtPBHiFT/gv X-Received: by 10.99.95.22 with SMTP id t22mr8945728pgb.195.1510588884082; Mon, 13 Nov 2017 08:01:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510588884; cv=none; d=google.com; s=arc-20160816; b=AEaNT0gC7TuzoVcFW5vXTLHEnpcuvtHh3ViEy7+0uAeeBmXrypBUx3UurJnlbTEE2b ArJA2C4kKGaUzxqCReAYSnFwzAgBMMyfkEDwzBV5Cr9p1gCVYONH8MxWBtt04U7cjBJ0 rPNJUvQj2LrMX2p+uiGFBTRdzs9Ri14Uv2VAxmd+5dwPP9yvas5WiH2ahj0kUKLDoz5M eIMIAoZlOanL2JA1RWiY508mj95mpTCj84FHPbyYYKeKnGJPeeWqdqxS874PR3W6eFZ2 4IKUqtlBCCk10gGjTU2wRt5E71mOGWwQMfB54q0sUeJtrCdNtRFOT0C2Jx4tkG+StIrO b9WA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:arc-authentication-results; bh=9h8hVOTiOLOjzxvSKZzAInsdVi81pv+WtxLoij90IGY=; b=CumYG9GN6sseS30SR4JV0IFkNNlMMcZBCIK67UrfdZ8BdPA3coJBeXf5MG1mUBwUn0 JdPFm+k6vFBRO2Fc8UGh+IDLSjXqM46CeU4ghkli8Xqd6aCMkYBCTDigdIFPbJVNwVt4 gNIH7bQeirOcLSTGafJNYOqHrZC8UUjOesfo4OvR7tbt0RS0aFPixWODfb0uN4mVpxAa irQ5Caf/g8/jos/T74MPVEDMOpte3MOTSYFkKoU18C43VplLfHVIRHD5+uQbf8nX7qsM ahr4P8Sf5m31Z2Sh/1vdsF1fcbadcSIwC6D5C3shyPC849US/74fvg9ZL+bMWjn51IPZ f7sA== 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 p9si14280464pgq.526.2017.11.13.08.01.10; Mon, 13 Nov 2017 08:01:24 -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; 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 S1753541AbdKMP7T (ORCPT + 88 others); Mon, 13 Nov 2017 10:59:19 -0500 Received: from mx2.suse.de ([195.135.220.15]:34002 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753439AbdKMP7Q (ORCPT ); Mon, 13 Nov 2017 10:59:16 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 87849AAC3; Mon, 13 Nov 2017 15:59:14 +0000 (UTC) Date: Mon, 13 Nov 2017 16:59:14 +0100 From: Michal Hocko To: Russell King - ARM Linux Cc: Michael Ellerman , Joel Stanley , Stephen Rothwell , Andrew Morton , Linux-Next Mailing List , Linux Kernel Mailing List , Benjamin Herrenschmidt , Abdul Haleem , Ralf Baechle , "James E.J. Bottomley" , Helge Deller , Yoshinori Sato , Rich Felker , "David S. Miller" , Chris Zankel , Max Filippov , linux-arm-kernel@lists.infradead.org, linuxppc-dev@lists.ozlabs.org, linux-mips@linux-mips.org, linux-parisc@vger.kernel.org, linux-sh@vger.kernel.org, sparclinux@vger.kernel.org, linux-xtensa@linux-xtensa.org Subject: Re: linux-next: Tree for Nov 7 Message-ID: <20171113155914.5uwmycui4qdwsbw3@dhcp22.suse.cz> References: <20171108142050.7w3yliulxjeco3b7@dhcp22.suse.cz> <20171110123054.5pnefm3mczsfv7bz@dhcp22.suse.cz> <20171113092006.cjw2njjukt6limvb@dhcp22.suse.cz> <20171113094203.aofz2e7kueitk55y@dhcp22.suse.cz> <87lgjawgx1.fsf@concordia.ellerman.id.au> <20171113120057.555mvrs4fjq5tyng@dhcp22.suse.cz> <20171113151641.yfqrecpcxllpn5mq@dhcp22.suse.cz> <20171113154811.GM12318@n2100.armlinux.org.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20171113154811.GM12318@n2100.armlinux.org.uk> User-Agent: NeoMutt/20170609 (1.8.3) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon 13-11-17 15:48:13, Russell King - ARM Linux wrote: > On Mon, Nov 13, 2017 at 04:16:41PM +0100, Michal Hocko wrote: > > On Mon 13-11-17 13:00:57, Michal Hocko wrote: > > [...] > > > Yes, I have mentioned that in the previous email but the amount of code > > > would be even larger. Basically every arch which reimplements > > > arch_get_unmapped_area would have to special case new MAP_FIXED flag to > > > do vma lookup. > > > > It turned out that this might be much more easier than I thought after > > all. It seems we can really handle that in the common code. This would > > mean that we are exposing a new functionality to the userspace though. > > Myabe this would be useful on its own though. Just a quick draft (not > > even compile tested) whether this makes sense in general. I would be > > worried about unexpected behavior when somebody set other bit without a > > good reason and we might fail with ENOMEM for such a call now. > > > > Elf loader would then use MAP_FIXED_SAFE rather than MAP_FIXED. > > --- > > diff --git a/arch/alpha/include/uapi/asm/mman.h b/arch/alpha/include/uapi/asm/mman.h > > index 3b26cc62dadb..d021c21f9b01 100644 > > --- a/arch/alpha/include/uapi/asm/mman.h > > +++ b/arch/alpha/include/uapi/asm/mman.h > > @@ -31,6 +31,9 @@ > > #define MAP_STACK 0x80000 /* give out an address that is best suited for process/thread stacks */ > > #define MAP_HUGETLB 0x100000 /* create a huge page mapping */ > > > > +#define MAP_KEEP_MAPPING 0x2000000 > > +#define MAP_FIXED_SAFE MAP_FIXED|MAP_KEEP_MAPPING /* enforce MAP_FIXED without clobbering an existing mapping */ > > A few things... > > 1. Does this need to be exposed to userland? As I've written in another email, exposing the flag this way would be really dangerous wrt. backward compatibility. So we would either need some translation or make it a flag on its own and touch the arch specific code which I really wanted to prevent from. Whether this is something useful for the userspace is a separate question which I should bring up to linux-api for a wider audience to discuss. So I guess this goes down to whether we want/need something like MAP_FIXED_SAFE or opt out the specific hardening code for arches that cannot make unaligned mappings for the requested address. > 2. Can it end up in include/uapi/asm-generic/mman*.h ? > 3. The definition of MAP_FIXED_SAFE should really have parens around it. Of course. I thought I did... > > @@ -1365,6 +1365,13 @@ unsigned long do_mmap(struct file *file, unsigned long addr, > > if (offset_in_page(addr)) > > return addr; > > > > + if ((flags & MAP_FIXED_SAFE) == MAP_FIXED_SAFE) { > > I'm surprised this doesn't warn - since this effectively expands to: > > flags & MAP_FIXED | MAP_KEEP_MAPPING > > hence why MAP_FIXED_SAFE needs parens. It sure does. Thanks! -- Michal Hocko SUSE Labs From 1583966660825090133@xxx Mon Nov 13 15:52:02 +0000 2017 X-GM-THRID: 1583423641769727671 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread