From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751199AbdKTJKj (ORCPT ); Mon, 20 Nov 2017 04:10:39 -0500 Received: from mx1.redhat.com ([209.132.183.28]:33792 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751042AbdKTJKh (ORCPT ); Mon, 20 Nov 2017 04:10:37 -0500 Subject: Re: [RFC PATCH 1/2] mm: introduce MAP_FIXED_SAFE To: Michal Hocko Cc: linux-api@vger.kernel.org, Khalid Aziz , Michael Ellerman , Andrew Morton , Russell King - ARM Linux , Andrea Arcangeli , linux-mm@kvack.org, LKML , linux-arch@vger.kernel.org References: <20171116101900.13621-1-mhocko@kernel.org> <20171116101900.13621-2-mhocko@kernel.org> <20171120085524.y4onsl5dpd3qbh7y@dhcp22.suse.cz> From: Florian Weimer Message-ID: <37a6e9ba-e0df-b65f-d5ef-871c25b5cb87@redhat.com> Date: Mon, 20 Nov 2017 10:10:32 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 In-Reply-To: <20171120085524.y4onsl5dpd3qbh7y@dhcp22.suse.cz> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Mon, 20 Nov 2017 09:10:37 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 11/20/2017 09:55 AM, Michal Hocko wrote: > On Fri 17-11-17 08:30:48, Florian Weimer wrote: >> On 11/16/2017 11:18 AM, Michal Hocko wrote: >>> + if (flags & MAP_FIXED_SAFE) { >>> + struct vm_area_struct *vma = find_vma(mm, addr); >>> + >>> + if (vma && vma->vm_start <= addr) >>> + return -ENOMEM; >>> + } >> >> Could you pick a different error code which cannot also be caused by a an >> unrelated, possibly temporary condition? Maybe EBUSY or EEXIST? > > Hmm, none of those are described in the man page. I am usually very > careful to not add new and potentially unexpected error codes but it is I think this is a bad idea. It leads to bizarre behavior, like open failing with EOVERFLOW with certain namespace configurations (which have nothing to do with file sizes). Most of the manual pages are incomplete regarding error codes, and with seccomp filters and security modules, what error codes you actually get is anyone's guess. > true that a new flag should warrant a new error code. I am not sure > which one is more appropriate though. EBUSY suggests that retrying might > help which is true only if some other party unmaps the range. So EEXIST > would sound more natural. Sure, EEXIST is completely fine. >> This would definitely help with application-based randomization of mappings, >> and there, actual ENOMEM and this error would have to be handled >> differently. > > I see. Could you be more specific about the usecase you have in mind? I > would incorporate it into the patch description. glibc ld.so currently maps DSOs without hints. This means that the kernel will map right next to each other, and the offsets between them a completely predictable. We would like to change that and supply a random address in a window of the address space. If there is a conflict, we do not want the kernel to pick a non-random address. Instead, we would try again with a random address. Thanks, Florian From mboxrd@z Thu Jan 1 00:00:00 1970 From: Florian Weimer Subject: Re: [RFC PATCH 1/2] mm: introduce MAP_FIXED_SAFE Date: Mon, 20 Nov 2017 10:10:32 +0100 Message-ID: <37a6e9ba-e0df-b65f-d5ef-871c25b5cb87@redhat.com> References: <20171116101900.13621-1-mhocko@kernel.org> <20171116101900.13621-2-mhocko@kernel.org> <20171120085524.y4onsl5dpd3qbh7y@dhcp22.suse.cz> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <20171120085524.y4onsl5dpd3qbh7y@dhcp22.suse.cz> Content-Language: en-US Sender: owner-linux-mm@kvack.org To: Michal Hocko Cc: linux-api@vger.kernel.org, Khalid Aziz , Michael Ellerman , Andrew Morton , Russell King - ARM Linux , Andrea Arcangeli , linux-mm@kvack.org, LKML , linux-arch@vger.kernel.org List-Id: linux-api@vger.kernel.org On 11/20/2017 09:55 AM, Michal Hocko wrote: > On Fri 17-11-17 08:30:48, Florian Weimer wrote: >> On 11/16/2017 11:18 AM, Michal Hocko wrote: >>> + if (flags & MAP_FIXED_SAFE) { >>> + struct vm_area_struct *vma = find_vma(mm, addr); >>> + >>> + if (vma && vma->vm_start <= addr) >>> + return -ENOMEM; >>> + } >> >> Could you pick a different error code which cannot also be caused by a an >> unrelated, possibly temporary condition? Maybe EBUSY or EEXIST? > > Hmm, none of those are described in the man page. I am usually very > careful to not add new and potentially unexpected error codes but it is I think this is a bad idea. It leads to bizarre behavior, like open failing with EOVERFLOW with certain namespace configurations (which have nothing to do with file sizes). Most of the manual pages are incomplete regarding error codes, and with seccomp filters and security modules, what error codes you actually get is anyone's guess. > true that a new flag should warrant a new error code. I am not sure > which one is more appropriate though. EBUSY suggests that retrying might > help which is true only if some other party unmaps the range. So EEXIST > would sound more natural. Sure, EEXIST is completely fine. >> This would definitely help with application-based randomization of mappings, >> and there, actual ENOMEM and this error would have to be handled >> differently. > > I see. Could you be more specific about the usecase you have in mind? I > would incorporate it into the patch description. glibc ld.so currently maps DSOs without hints. This means that the kernel will map right next to each other, and the offsets between them a completely predictable. We would like to change that and supply a random address in a window of the address space. If there is a conflict, we do not want the kernel to pick a non-random address. Instead, we would try again with a random address. Thanks, Florian -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org