From patchwork Fri Jul 17 17:42:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 11670999 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8164E13A4 for ; Fri, 17 Jul 2020 17:44:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6A14F207EA for ; Fri, 17 Jul 2020 17:44:43 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="Vmebw9xz" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728259AbgGQRoj (ORCPT ); Fri, 17 Jul 2020 13:44:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45886 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727040AbgGQRnP (ORCPT ); Fri, 17 Jul 2020 13:43:15 -0400 Received: from mail-pj1-x1042.google.com (mail-pj1-x1042.google.com [IPv6:2607:f8b0:4864:20::1042]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 65A6DC0619D7 for ; Fri, 17 Jul 2020 10:43:15 -0700 (PDT) Received: by mail-pj1-x1042.google.com with SMTP id f16so6751118pjt.0 for ; Fri, 17 Jul 2020 10:43:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=wrxYLXP2oheEEaGsKNp0stRrknyVueRaJu8i8kSptew=; b=Vmebw9xzyFrFLgnwLQyPbu9sUxIvT3iz/LZhlggPZzdK8yi/sNJp1ISZhzAODP/aQq DA1aJsmMOF5WM3+KxOc/jJOdCUMwDEegiUHYTk5QHuuuSDkU5ULxP6uWFu0Zgzte/hrz inlXJ3TzZ7dygl/RRmbqjrIF3idceAZR9MaU4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=wrxYLXP2oheEEaGsKNp0stRrknyVueRaJu8i8kSptew=; b=DIAiBZN3gz8G+r6Y5ecs5XkIuIZDbFKaCnRkHyiw/sfEUTybLLAtNW43YwPGmBT6Mr 7IYGogkwPIvnOjc+tvHVi3a74sGqn3vwfh+rj01c6p7gM4JGwYeJuyJwkv9+e24bdzRw IL3jKyUz1MDxaPHdz3iuaCEx8MG62eXjL7Pu7Te3lwQ5uSVjfvPdnYDf9JhoSxAqUAfa WPdFfMQa7U8uxyS8gsk8qsZmvzSyiO5TeCtmW2zzOiYG1fMKjcZyT4I09oSYT5Vg+XtG 5Ff+DRk4hvBmdVdoKUghuoNlHCW0FSBLkpSCia0Ku/mXD/Qu1Bp2CQRm6GXQ8BMo14oC +Z1g== X-Gm-Message-State: AOAM533VXjb7Zw4KL2JPVFIWkMu2GqBM2vsm6AuE2e4x9ZgSCio3H4Or RssmucBon8Uy5+2P4HqrdqwGJg== X-Google-Smtp-Source: ABdhPJwUg0XMxYDUbRjKGsYc4z6GZTjsdq+bfOADQJjU8WjIWVN4iFhFlTSQL5o2BTwLAVb1iIGijw== X-Received: by 2002:a17:90a:9f4a:: with SMTP id q10mr11275946pjv.139.1595007795012; Fri, 17 Jul 2020 10:43:15 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id d9sm8187840pfd.133.2020.07.17.10.43.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Jul 2020 10:43:13 -0700 (PDT) From: Kees Cook To: Scott Branden Cc: Kees Cook , stable@vger.kernel.org, Mimi Zohar , Matthew Wilcox , James Morris , Luis Chamberlain , Greg Kroah-Hartman , "Rafael J. Wysocki" , Alexander Viro , Jessica Yu , Dmitry Kasatkin , "Serge E. Hallyn" , Casey Schaufler , "Eric W. Biederman" , Peter Zijlstra , Matthew Garrett , David Howells , Mauro Carvalho Chehab , Randy Dunlap , "Joel Fernandes (Google)" , KP Singh , Dave Olsthoorn , Hans de Goede , Peter Jones , Andrew Morton , Stephen Boyd , Paul Moore , Stephen Smalley , linux-security-module@vger.kernel.org, linux-integrity@vger.kernel.org, selinux@vger.kernel.org, linux-fsdevel@vger.kernel.org, kexec@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 01/13] firmware_loader: EFI firmware loader must handle pre-allocated buffer Date: Fri, 17 Jul 2020 10:42:56 -0700 Message-Id: <20200717174309.1164575-2-keescook@chromium.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200717174309.1164575-1-keescook@chromium.org> References: <20200717174309.1164575-1-keescook@chromium.org> MIME-Version: 1.0 Sender: linux-integrity-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-integrity@vger.kernel.org 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 Signed-off-by: Kees Cook Acked-by: Scott Branden --- 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;