Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp2810747ybi; Sun, 2 Jun 2019 01:41:24 -0700 (PDT) X-Google-Smtp-Source: APXvYqwvNK7arKotmUlxHPBrZ6wPLyKqyvx51Fh1J65oRxu4WyLj6bhIwk9Q8qMabI/yCBkIB9ZC X-Received: by 2002:a17:902:e40f:: with SMTP id ci15mr22168614plb.280.1559464884613; Sun, 02 Jun 2019 01:41:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559464884; cv=none; d=google.com; s=arc-20160816; b=kLZO1xf7iF08AgWUYVKerQhNBsWkUWY0mfnNxHqQcnf0KCuUkg4Twys1N+YRXdgwYi 4GFwl1J0dpwGUW6i7LZT4eATb7GIe49OzvjbrfG+2snDpj+hm0e5BXetOshIKl0PiACl 5H4sae4H8z6/TkAogrEIpHmv8+qSdxmpek7tck8VNqP/YpkLMKWViHIQFJgh9oGtqSUM oEclkimDMbKhkw0M4G4/4iu4MQK3srPFMvchC3W6KNkibP4S/oiUtJn+g9ByfIi+yyRB E9JZPKoX7dFG31cwDVhTLYjlV1WR0qd0hNZobLy7IouczP3NCcHBOYsUqk/vte1o3MF3 QNWw== 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:mime-version :user-agent:organization:references:in-reply-to:date:cc:to:from :subject:message-id; bh=fiJSVPgbY3UrE+Rhm0yGBQlXNLHGCJMTaLvi34cAP4s=; b=hyt3zPhfjvpNOhGqG/QMY4Qah8dB7SWw+NqfPKeSuXm59zOcwSfYGRJOHkZRsCffwy 8oNFOpISVfvXRdaSu7dRcB0ZyP9eT2dDDBGrCFLtM7tCe2+F07tC6W59OMP9mlTA55zO YTo6AsRLtzfLueukovmFtXVXI3jOBNdOrMnqa58DJsF9HdSGpfmPw2rvrVnavYn69XOH FgKN9lfz6zAxH+y01LVaQZDtsk07eLZJRFlLRZ96nb5OLBObHu184K+MT3t+UVIreGMd OfCmPseqP1SgwJlq76MXpOuobp9lauTIaVtoOj3eYcJ3O6p3PvCE4LP5qcyrNgzQKShg QAUA== 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 y24si13560804pgh.372.2019.06.02.01.40.31; Sun, 02 Jun 2019 01:41:24 -0700 (PDT) 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 S1726292AbfFBIgw (ORCPT + 99 others); Sun, 2 Jun 2019 04:36:52 -0400 Received: from [176.110.122.116] ([176.110.122.116]:52152 "EHLO ocean.emcraft.com" rhost-flags-FAIL-FAIL-OK-OK) by vger.kernel.org with ESMTP id S1725925AbfFBIgw (ORCPT ); Sun, 2 Jun 2019 04:36:52 -0400 X-Greylist: delayed 4503 seconds by postgrey-1.27 at vger.kernel.org; Sun, 02 Jun 2019 04:36:51 EDT Received: from [10.8.0.10] (helo=mehome.localdomain) by ocean.emcraft.com with esmtps (TLSv1:AES256-SHA:256) (Exim 4.76) (envelope-from ) id 1hXKoA-0002FG-S7; Sun, 02 Jun 2019 10:21:37 +0300 Message-ID: <34079b6a34abbad5ab13925dc004e397f70524e3.camel@emcraft.com> Subject: Re: [PATCH] binfmt_flat: make load_flat_shared_library() work From: Sergei Poselenov To: Arnd Bergmann , Greg Ungerer Cc: arch@emcraft.com, Jann Horn , Andrew Morton , Alexander Viro , linux-fsdevel , kernel list , Kees Cook , Nicolas Pitre , Geert Uytterhoeven , Linux/m68k , Russell King , Linux ARM Date: Sun, 02 Jun 2019 10:21:33 +0300 In-Reply-To: References: <20190524201817.16509-1-jannh@google.com> <20190525144304.e2b9475a18a1f78a964c5640@linux-foundation.org> <6956cfe5-90d4-aad4-48e3-66b0ece91fed@linux-m68k.org> Organization: Emcraft Systems Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.32.2 (3.32.2-1.fc30) MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hello Arnd, all, On Wed, 2019-05-29 at 14:05 +0200, Arnd Bergmann wrote: > On Tue, May 28, 2019 at 12:56 PM Greg Ungerer > wrote: > > On 27/5/19 11:38 pm, Jann Horn wrote: > > > On Sat, May 25, 2019 at 11:43 PM Andrew Morton > > > wrote: > > > > On Fri, 24 May 2019 22:18:17 +0200 Jann Horn > > > > wrote: > > > > > load_flat_shared_library() is broken: It only calls > > > > > load_flat_file() if > > > > > prepare_binprm() returns zero, but prepare_binprm() returns > > > > > the number of > > > > > bytes read - so this only happens if the file is empty. > > > > > > > > ouch. > > > > > > > > > Instead, call into load_flat_file() if the number of bytes > > > > > read is > > > > > non-negative. (Even if the number of bytes is zero - in that > > > > > case, > > > > > load_flat_file() will see nullbytes and return a nice > > > > > -ENOEXEC.) > > > > > > > > > > In addition, remove the code related to bprm creds and stop > > > > > using > > > > > prepare_binprm() - this code is loading a library, not a main > > > > > executable, > > > > > and it only actually uses the members "buf", "file" and > > > > > "filename" of the > > > > > linux_binprm struct. Instead, call kernel_read() directly. > > > > > > > > > > Cc: stable@vger.kernel.org > > > > > Fixes: 287980e49ffc ("remove lots of IS_ERR_VALUE abuses") > > > > > Signed-off-by: Jann Horn > > > > > --- > > > > > I only found the bug by looking at the code, I have not > > > > > verified its > > > > > existence at runtime. > > > > > Also, this patch is compile-tested only. > > > > > It would be nice if someone who works with nommu Linux could > > > > > have a > > > > > look at this patch. > > > > > > > > 287980e49ffc was three years ago! Has it really been broken > > > > for all > > > > that time? If so, it seems a good source of freed disk > > > > space... > > > > > > Maybe... but I didn't want to rip it out without having one of > > > the > > > maintainers confirm that this really isn't likely to be used > > > anymore. > > > > I have not used shared libraries on m68k non-mmu setups for > > a very long time. At least 10 years I would think. > > I think Emcraft have a significant customer base running ARM NOMMU > Linux, I wonder whether they would have run into this (adding > Sergei to Cc). > My suspicion is that they use only binfmt-elf-fdpic, not binfmt-flat. > We use both, acutally, but all-static. We don't support shared libraries with bFLT or ELF FDPIC. Kind regards, Sergei > The only architectures I see that enable binfmt-flat are sh, xtensa > and h8300, but only arch/sh uses CONFIG_BINFMT_SHARED_FLAT > for a few machine specific configurations, and I'm in turn fairly > sure > those machines have not run a recent kernel in many years. > > The one SH nommu platform likely to have users is j2, and that is > probably always used with musl-libc with elf-fdpic (given that > Rich Felker maintains both the kernel port and the library). > > Arnd >