Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp6239670ybi; Wed, 29 May 2019 05:07:26 -0700 (PDT) X-Google-Smtp-Source: APXvYqxqELU+6bCkUCnqxdnp954FB/2SLdPxN0vWd7eB1MPopbYjrrwEaoAUIN2ISTXVTcUIw4In X-Received: by 2002:a65:64d9:: with SMTP id t25mr137525797pgv.130.1559131646422; Wed, 29 May 2019 05:07:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559131646; cv=none; d=google.com; s=arc-20160816; b=C+u4o6iGmGv2iwt6WWLu7C8yYm5nuQYbVb9jt/jrtKfi5C5KMftmYjiVBXY/Eijcxy DpqDMjMjhkfEVMp6OLipPy6VnHZjLxyk0JmxHO5Gr0A0y+5tU2K7SXoCoQ9sO/En8btq 9e7sXBx3ccnZBO/GpSHiLvFTuCJM3jSKq1AzN8fpPwsGICuPKl1PHizfH+uthX5MOuPC iLB5u61D5KbsZgd8k2oh+14NaGvH2VrxGBbTpfymuE2JhpTKH2b1kEBq7D92Z15fcNQg k28iz9FhPWiJT4fjIEDdSbKdANRwJi1wgS+zbGFJzaSJLRbE5spmz/Q44Eoz0GErNGYu 7wMg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version; bh=uptjHgaBaplGgf+wVSZU2eUIoKk2cN8EqiU/ukCqtno=; b=A0OmXe9bTYptYKp5AOBLnUOYSPSQoMkwsEoB7y+rsOGrNNg6MSPW7jKK12XH//8lan 29D7V5HWKa2tj7tZBmYrCJLPmhssLpkhVlwDUONKpUmmIiDuVg0RMIF0x11o1lfGQ4Os lVt8sI7W3vKcBDfcXZ+cShtsS1e0u1rAwO/w+A6QgoHiHthn1hAxNmL2KLYuKTBvOWBW XG9WqVrYcwLAe68gtV33xQbzpiyn7HwJS9vaHKyaTIdMgyAUPwd9t6mlcNtg/OvygSn/ s3qmLctoXtJTCsnGLaw1Cao5k+TraRZl6Bgf0ZvT8vW3j5IKMTU0s8q+GufSvcftIqFC LyXg== 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 i21si2450270pfr.6.2019.05.29.05.07.09; Wed, 29 May 2019 05:07:26 -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 S1726833AbfE2MFj (ORCPT + 99 others); Wed, 29 May 2019 08:05:39 -0400 Received: from mail-qk1-f194.google.com ([209.85.222.194]:41627 "EHLO mail-qk1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725914AbfE2MFi (ORCPT ); Wed, 29 May 2019 08:05:38 -0400 Received: by mail-qk1-f194.google.com with SMTP id m18so1225204qki.8; Wed, 29 May 2019 05:05:38 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=uptjHgaBaplGgf+wVSZU2eUIoKk2cN8EqiU/ukCqtno=; b=bVru2BYig38DgvLxps014WcqhT79gXuca2bK5YYvsZX6/pCoiF7T1M8KG+54g1GgRL hQ0oNIofY0Gbta4HzbzhsdohwMrktKK7svU/HIKpWqDXrof/fWkKZZHI66oi1DqDMQg5 NB8WcqSYg1xcppR+jNWmNVDrEce6do2vQZJ5Nr7KW+wKe3F/AblZPRQzcqFyVwKaSSO2 kTSiq8lbGzIrOUyrYSJkl6zT0uCMGemojqtWR/amdEUbXcf2UgXiFNaVlfh3zTd9SUa5 mXsldNqN8pFQn+pLkwwwY8MA1i1shNTDENVRbNpm6kv0yluRrwi8cWE77677njpdVzkN p+KQ== X-Gm-Message-State: APjAAAWZn+XYGCw+YL5NL9zlPbseU+lCQfI2zoFJclDHvZZmkybNeXbL qFFCFM6UG4tV0waJ2QuQ0t1qvxY7h/2cq94Skuw= X-Received: by 2002:a05:620a:1085:: with SMTP id g5mr80432085qkk.182.1559131537731; Wed, 29 May 2019 05:05:37 -0700 (PDT) MIME-Version: 1.0 References: <20190524201817.16509-1-jannh@google.com> <20190525144304.e2b9475a18a1f78a964c5640@linux-foundation.org> <6956cfe5-90d4-aad4-48e3-66b0ece91fed@linux-m68k.org> In-Reply-To: <6956cfe5-90d4-aad4-48e3-66b0ece91fed@linux-m68k.org> From: Arnd Bergmann Date: Wed, 29 May 2019 14:05:21 +0200 Message-ID: Subject: Re: [PATCH] binfmt_flat: make load_flat_shared_library() work To: Greg Ungerer Cc: Jann Horn , Andrew Morton , Alexander Viro , linux-fsdevel , kernel list , Kees Cook , Nicolas Pitre , Geert Uytterhoeven , "Linux/m68k" , Russell King , Linux ARM , Sergei Poselenov Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. 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