Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp318697ybz; Thu, 30 Apr 2020 22:46:08 -0700 (PDT) X-Google-Smtp-Source: APiQypJpXSSkuW6atyqBzPbx+eQhUpFzPh9v+jVU9jLN7Rp9Ek3rUksHDn32ijQ/xVOpsrhwIbaJ X-Received: by 2002:a17:906:37d0:: with SMTP id o16mr1676171ejc.368.1588311968690; Thu, 30 Apr 2020 22:46:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588311968; cv=none; d=google.com; s=arc-20160816; b=biCJJ/g02EViFmCu175wykVfXuhyGQyApc40oTGZBsIrrRDBWOI4V2xK/5DnmfmAJK am51PB1gbiXWZtHncua5A5BL4ASx09FGaKN4e0/LHG30/0Q0h/0+d7t5hAwxcyycgMFo ZdDxqhxNrNF/qaTNnV3zwFqJ7mDu/NhT/gol5SPQPq6NEOt7ZbCV0iqI33X1OIkKsDxp 485LuGvMWXf9dxqvptd01tsUw1g9cQSeTazTjLJmxpTRwqjiqe7arYlJBjbbCQY1X/zP XLE2+yKWuiK+xpUyn91585DSPzERCtSPUBogpRP644Cbfk9qCpwmYnLVFXkztGAQgTQm tFFg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:references:cc:to:subject:from; bh=XqLYpwuksh/4O+FzDEBflUQK91+NdtKmnWc33K5rZ8E=; b=0NLM0IZx6U8cAlt8muTEqoOxdlCWrDi3ss6qhVC/HodGu00cFbxfkiOz0FiI+gYyB4 nHGCzauIF76JSiskwG4eFisWSsYpRuYTwnR1tVU2gQmnb9kf08/s+IgO9BCOc2AO5bpO EeR+mTCJX4+y/zduSUz86hUOYOPVUCd/uSR/Zxd1MDPabcMTLqtI9tvK5qbc3ZlLNSvh 2Uh1/q6KpcRE/4IwuxSTy4zfBrLImaT/Ab0jzgNqG3NXo2087j1i14hEoDQ64vNTl2lm cYuAV7BhpoPI50WLnUugF13BaIHXCNlKhOaQIL6XRC8nbEqOR90konUNv6EMysRaPssA WTTA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g16si1094493ejf.272.2020.04.30.22.45.46; Thu, 30 Apr 2020 22:46:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728244AbgEAFo2 (ORCPT + 99 others); Fri, 1 May 2020 01:44:28 -0400 Received: from mail.kernel.org ([198.145.29.99]:53134 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726452AbgEAFo2 (ORCPT ); Fri, 1 May 2020 01:44:28 -0400 Received: from [10.44.0.192] (unknown [103.48.210.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id DEAF820731; Fri, 1 May 2020 05:44:20 +0000 (UTC) From: Greg Ungerer Subject: Re: [PATCH v2 0/5] Fix ELF / FDPIC ELF core dumping, and use mmap_sem properly in there To: "Eric W. Biederman" , Linus Torvalds Cc: Russell King - ARM Linux admin , Jann Horn , Nicolas Pitre , Andrew Morton , Christoph Hellwig , Linux Kernel Mailing List , Linux-MM , linux-fsdevel , Alexander Viro , Oleg Nesterov , Linux ARM , Mark Salter , Aurelien Jacquiot , linux-c6x-dev@linux-c6x.org, Yoshinori Sato , Rich Felker , Linux-sh list References: <20200429214954.44866-1-jannh@google.com> <20200429215620.GM1551@shell.armlinux.org.uk> <31196268-2ff4-7a1d-e9df-6116e92d2190@linux-m68k.org> <87imhgyeqt.fsf@x220.int.ebiederm.org> Message-ID: <9dd76936-0009-31e4-d869-f64d01886642@linux-m68k.org> Date: Fri, 1 May 2020 15:44:03 +1000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.7.0 MIME-Version: 1.0 In-Reply-To: <87imhgyeqt.fsf@x220.int.ebiederm.org> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 1/5/20 5:07 am, Eric W. Biederman wrote: > Linus Torvalds writes: > >> On Thu, Apr 30, 2020 at 7:10 AM Greg Ungerer wrote: > >>>> Most of that file goes back to pre-git days. And most of the commits >>>> since are not so much about binfmt_flat, as they are about cleanups or >>>> changes elsewhere where binfmt_flat was just a victim. >>> >>> I'll have a look at this. >> >> Thanks. >> >>> Quick hack test shows moving setup_new_exec(bprm) to be just before >>> install_exec_creds(bprm) works fine for the static binaries case. >>> Doing the flush_old_exec(bprm) there too crashed out - I'll need to >>> dig into that to see why. >> >> Just moving setup_new_exec() would at least allow us to then join the >> two together, and just say "setup_new_exec() does the credential >> installation too". > > But it is only half a help if we allow failure points between > flush_old_exec and install_exec_creds. > > Greg do things work acceptably if install_exec_creds is moved to right > after setup_new_exec? (patch below) Yes, confirmed. Worked fine with that patch applied. > Looking at the code in load_flat_file after setup_new_exec it looks like > the kinds of things that in binfmt_elf.c we do after install_exec_creds > (aka vm_map). So I think we want install_exec_creds sooner, instead > of setup_new_exec later. > >> But if it's true that nobody really uses the odd flat library support >> any more and there are no testers, maybe we should consider ripping it >> out... > > I looked a little deeper and there is another reason to think about > ripping out the flat library loader. The code is recursive, and > supports a maximum of 4 shared libraries in the entire system. > > load_flat_binary > load_flat_file > calc_reloc > load_flat_shared_libary > load_flat_file > .... > > I am mystified with what kind of system can survive with a grand total > of 4 shared libaries. I think my a.out slackware system that I ran on > my i486 had more shared libraries. The kind of embedded systems that were built with this stuff 20 years ago didn't have lots of applications and libraries. I think we found back then that most of your savings were from making libc shared. Less significant gains from making other libraries shared. And there was a bit of extra pain in setting them up with the shared library code generation options (that had to be unique for each one). The whole mechanism is a bit of hack, and there was a few other limitations with the way it worked (I don't recall what they were right now). I am definitely in favor of removing it. Regards Greg > Having read just a bit more it is definitely guaranteed (by the code) > that the first time load_flat_file is called id 0 will be used (aka id 0 > is guaranteed to be the binary), and the ids 1, 2, 3 and 4 will only be > used if a relocation includes that id to reference an external shared > library. That part of the code is drop dead simple. > > --- > > This is what I was thinking about applying. > > diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c > index 831a2b25ba79..1a1d1fcb893f 100644 > --- a/fs/binfmt_flat.c > +++ b/fs/binfmt_flat.c > @@ -541,6 +541,7 @@ static int load_flat_file(struct linux_binprm *bprm, > /* OK, This is the point of no return */ > set_personality(PER_LINUX_32BIT); > setup_new_exec(bprm); > + install_exec_creds(bprm); > } > > /* > @@ -963,8 +964,6 @@ static int load_flat_binary(struct linux_binprm *bprm) > } > } > > - install_exec_creds(bprm); > - > set_binfmt(&flat_format); > > #ifdef CONFIG_MMU > >