From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.0 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EE054C282DC for ; Sun, 2 Jun 2019 08:36:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B90F12788C for ; Sun, 2 Jun 2019 08:36:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726410AbfFBIgw (ORCPT ); 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 >