From patchwork Fri Jul 24 21:36:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 11684437 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 86433138A for ; Fri, 24 Jul 2020 21:36:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6DA5E20714 for ; Fri, 24 Jul 2020 21:36:46 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="G+1xDfQL" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726764AbgGXVgp (ORCPT ); Fri, 24 Jul 2020 17:36:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57744 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726592AbgGXVgp (ORCPT ); Fri, 24 Jul 2020 17:36:45 -0400 Received: from mail-pl1-x642.google.com (mail-pl1-x642.google.com [IPv6:2607:f8b0:4864:20::642]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1CAAAC0619D3 for ; Fri, 24 Jul 2020 14:36:45 -0700 (PDT) Received: by mail-pl1-x642.google.com with SMTP id f7so405863pln.13 for ; Fri, 24 Jul 2020 14:36:45 -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=/04RayDpwyA5vDbPSxe5f4ljhOo+lc314fSygLzjhJk=; b=G+1xDfQLQfOkEGi9h7UsWjc1zUgJyBvo+3+m4LgnDSzN055MEqcuXAaGGInXmvkUMH EZ1BL/XKDtMU3+a3prtBrk26Lv4UGOX3WcTbeAmSuqW9pTN4Ly2HnxPi07LW2r6P7GxJ 2Zk56Knz9bfkGixCGqcYL5FsOmA1yCLQYZMiA= 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=/04RayDpwyA5vDbPSxe5f4ljhOo+lc314fSygLzjhJk=; b=DZTBI8h0kHnm/uonD3Gyzx7Ayw2ufR2DSxIH1A5A9Fxkey86600LyIIaxHoD5iI7Ar yPnfLuk0QOZc3fMljytykBvXVHpc8+iWrfdU8LdL5Aj8e8l0ZtjDDxjks4+TkUy6zHCI OAnXkV4KCZ1S0w+HOaO5PIGMjM+9JLakoVFQyUkjmAIMGQ90nq4y3d1EEGnXTCV4mHtZ +PIPJMfxi+qlc1IZblYdqtI80Uz36dafyRELJEraidr3zwWAWoEB28OP9JeBnCRBuiV9 agQv7zsLwjIN15nOg15iCCDI0P7CHaNRmKuW623qxt4J/bk7AwV4ijx/pf7DmfaXqrx7 887w== X-Gm-Message-State: AOAM5330XqZmHx3Micen4tp8lxiboAyjLbIdpbd9nC1V0UrgxuwEd88a ytBgoPhMX4igzcoqSPpTBi3jNg== X-Google-Smtp-Source: ABdhPJybX0hse+un0+9u1VVNDSN/bl2TKboJFPcM9i6sjtO8vm74oKTwOn3TjA+5wrO11RoKgfqx1g== X-Received: by 2002:a17:902:7c0c:: with SMTP id x12mr10020502pll.103.1595626604507; Fri, 24 Jul 2020 14:36:44 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id w2sm6759688pjt.19.2020.07.24.14.36.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jul 2020 14:36:43 -0700 (PDT) From: Kees Cook To: Greg Kroah-Hartman Cc: Kees Cook , stable@vger.kernel.org, Scott Branden , Mimi Zohar , Luis Chamberlain , Jessica Yu , SeongJae Park , KP Singh , linux-efi@vger.kernel.org, linux-security-module@vger.kernel.org, linux-integrity@vger.kernel.org, selinux@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 03/19] firmware_loader: EFI firmware loader must handle pre-allocated buffer Date: Fri, 24 Jul 2020 14:36:24 -0700 Message-Id: <20200724213640.389191-4-keescook@chromium.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200724213640.389191-1-keescook@chromium.org> References: <20200724213640.389191-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 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;