Return-path: Received: from mail-pg1-x543.google.com ([2607:f8b0:4864:20::543]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jyKRh-0001XF-WD for kexec@lists.infradead.org; Wed, 22 Jul 2020 19:30:34 +0000 Received: by mail-pg1-x543.google.com with SMTP id g67so1822893pgc.8 for ; Wed, 22 Jul 2020 12:30:29 -0700 (PDT) From: Kees Cook Subject: [PATCH v2 03/18] firmware_loader: EFI firmware loader must handle pre-allocated buffer Date: Wed, 22 Jul 2020 12:30:05 -0700 Message-Id: <20200722193020.2676422-4-keescook@chromium.org> In-Reply-To: <20200722193020.2676422-1-keescook@chromium.org> References: <20200722193020.2676422-1-keescook@chromium.org> MIME-Version: 1.0 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "kexec" Errors-To: kexec-bounces+dwmw2=infradead.org@lists.infradead.org To: Greg Kroah-Hartman Cc: linux-efi@vger.kernel.org, "Rafael J. Wysocki" , Peter Zijlstra , linux-fsdevel@vger.kernel.org, Stephen Boyd , SeongJae Park , Mimi Zohar , David Howells , Tushar Sugandhi , Peter Jones , linux-kselftest@vger.kernel.org, "Joel Fernandes (Google)" , Shuah Khan , Ard Biesheuvel , Thomas Cedeno , linux-security-module@vger.kernel.org, Anders Roxell , Paul Moore , Mauro Carvalho Chehab , Michael Ellerman , Nayna Jain , Matthew Garrett , James Morris , Lakshmi Ramasubramanian , Aaron Goidel , "Serge E. Hallyn" , Wenwen Wang , Kees Cook , Scott Branden , selinux@vger.kernel.org, Hans de Goede , Alexander Viro , Matthieu Baerts , KP Singh , Eric Paris , linux-integrity@vger.kernel.org, Florent Revest , Andrea Righi , Dmitry Kasatkin , Stephen Smalley , Randy Dunlap , kexec@lists.infradead.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org, Luis Chamberlain , Eric Biederman , Dave Olsthoorn , Jessica Yu , Casey Schaufler , Joe Perches , Andrew Morton , Thiago Jung Bauermann The EFI platform firmware fallback would clobber any pre-allocated buffers. Instead, correctly refuse to reallocate when too small (as already done in the sysfs fallback), or perform allocation normally when needed. Fixes: e4c2c0ff00ec ("firmware: Add new platform fallback mechanism and firm ware_request_platform()") Cc: stable@vger.kernel.org Acked-by: Scott Branden Signed-off-by: Kees Cook --- To aid in backporting, this change is made before moving kernel_read_file() to separate header/source files. --- drivers/base/firmware_loader/fallback_platform.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/base/firmware_loader/fallback_platform.c b/drivers/base/firmware_loader/fallback_platform.c index cdd2c9a9f38a..685edb7dd05a 100644 --- a/drivers/base/firmware_loader/fallback_platform.c +++ b/drivers/base/firmware_loader/fallback_platform.c @@ -25,7 +25,10 @@ int firmware_fallback_platform(struct fw_priv *fw_priv, u32 opt_flags) if (rc) return rc; /* rc == -ENOENT when the fw was not found */ - fw_priv->data = vmalloc(size); + if (fw_priv->data && size > fw_priv->allocated_size) + return -ENOMEM; + if (!fw_priv->data) + fw_priv->data = vmalloc(size); if (!fw_priv->data) return -ENOMEM; -- 2.25.1 _______________________________________________ kexec mailing list kexec@lists.infradead.org http://lists.infradead.org/mailman/listinfo/kexec