Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp2052559ybi; Sat, 25 May 2019 14:47:03 -0700 (PDT) X-Google-Smtp-Source: APXvYqy5fty4uCiUCBm/8jk0SMzClU8SrCNfQBq1orSkkNW11sOvBlLAl4+jGy1oqRDKmuzenAvf X-Received: by 2002:a63:fa16:: with SMTP id y22mr75374776pgh.15.1558820823712; Sat, 25 May 2019 14:47:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558820823; cv=none; d=google.com; s=arc-20160816; b=qxG8UHxXOMj83D84Pk9mDNOfNUBCxXMQPebHI8j1ODnBQQGxoXZSPp4ZwiDmLItF39 +Ok2YgpEHvoBMyFhIcVrus970KZZaVVteq5I8cmJCxZeXKNHMNiU1fOyJ4sj5Vyy213n OT1DxL1Bfq9vMbLwWUd4/hJEe+nA2V4jVtncvWJkqsI5VJzGQhC8604VonBhkZVVmLjx MjAKTyrUwuKIZuREzsiw0q5451NkKCkrjfrY/HcFIulxTEM7M4GWR9NhQ47wlMvVu7QX /878V0wYMsWcOlXCUw+1HjvTJdjCOO5crGugLfHlWpOmEzOjLcSAYmwH0zrH9Lbrf/oX 6+tg== 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 :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=aTZDEAHYtrUstGQ/WB2rLYYPd/A5nOwfF5fLxXeDOCE=; b=tViVtpnEBk4MCTkZIKY69/E0Ym1eJaHzVTDK/VKJLwtvLWc3GROwd8cNYNFQVDhqUe qyzx5Ys7fwxz47AL+sk/y7APTNRBqk/jCtHzqHIiX9wQMBuoDloffvlLjGJQOO3rzPZz Y6C4diQw0P+Gs1WMF6+yK4DjtubaIOVpx3C9bqGlEyVZBR5i71ezd7MFm71/HsmxLITj 5QpCE5e8HM6C8pp5t4sGbc48bTLCBvVfFxNiUsiAL/z1xl2QHGtnvSd2nRmL1r1B922n 5zqcFq0SQv28GEqrBTSMXiBpy7nZnWId7q0KikCoikzwja9AQq9EptOkKVXoJgMJhBE5 O7/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=qcH5klgZ; 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 k184si9666699pge.82.2019.05.25.14.46.20; Sat, 25 May 2019 14:47:03 -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; dkim=pass header.i=@kernel.org header.s=default header.b=qcH5klgZ; 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 S1727527AbfEYVnH (ORCPT + 99 others); Sat, 25 May 2019 17:43:07 -0400 Received: from mail.kernel.org ([198.145.29.99]:59734 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727431AbfEYVnH (ORCPT ); Sat, 25 May 2019 17:43:07 -0400 Received: from localhost.localdomain (c-73-223-200-170.hsd1.ca.comcast.net [73.223.200.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id C17D920717; Sat, 25 May 2019 21:43:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1558820586; bh=RSkWc9M4HXsc7P5xgZgm2GYbuJuLKG99DNM5QI2xszs=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=qcH5klgZXiIVY3yzZ3y1eFDh75WpT2Eo69UkgFOvGL+a9UoXR4VQGx/af580/7q6s 82dNlsR9lOhsJucrwvrRl7Ily/sxnI/ahZxXajfHcLo2nxsEj+6tuTMw66DZmfXIM3 BVS4WSXi3EAYM3JAmPvesPTE7wof+WW4rJKojdm4= Date: Sat, 25 May 2019 14:43:04 -0700 From: Andrew Morton To: Jann Horn Cc: Alexander Viro , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Kees Cook , Nicolas Pitre , Arnd Bergmann , Geert Uytterhoeven , linux-m68k@vger.kernel.org, Russell King , linux-arm-kernel@lists.infradead.org Subject: Re: [PATCH] binfmt_flat: make load_flat_shared_library() work Message-Id: <20190525144304.e2b9475a18a1f78a964c5640@linux-foundation.org> In-Reply-To: <20190524201817.16509-1-jannh@google.com> References: <20190524201817.16509-1-jannh@google.com> X-Mailer: Sylpheed 3.5.1 (GTK+ 2.24.31; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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...