Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp2164037ybh; Fri, 17 Jul 2020 10:48:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwJlMFgiTgRBEh/s3tXnlNdmuuLDBt9GYpHR3xyR4/A3oZoRun2l3lbBvj41S8aGrbYATZ5 X-Received: by 2002:a50:f392:: with SMTP id g18mr10162824edm.151.1595008089712; Fri, 17 Jul 2020 10:48:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595008089; cv=none; d=google.com; s=arc-20160816; b=ZlBGIa3JYsObvYYFX+v9Qd1go60/yhMQOwjuoW413V0i6TJoRWwQXkwW4RQYJHFPVB NdRpUPjApcO54GgzQJ7DdwR41nCxS9WFHRYsz0VfXPrKWBOzuZWV8YmATViebuVIrofJ o9npZSm1GKatyGmrQawy3JuIg6qqRHoRPSpGmuvNgkxKTRO7FqTQ22+mVkob9iBVgMx6 TxshVvYGDRIbMEmRx2He0tygWlx2k9EkCGrPBoqy4r4L9aQvcZt/F5L9u0DCjcnMZ/1S cDRlDCAtdTASTM2KCnxyGGPgmnuuz+u/EUT8NmDFWR/yV9g0snrIAx/OdyZsb/oFXpsM dpHA== 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:date:subject:cc:to:from :dkim-signature; bh=wrxYLXP2oheEEaGsKNp0stRrknyVueRaJu8i8kSptew=; b=0cIOFRxw6Y2ZcZZCpQoecDV1NixVhP2gJhCrfQLCRFFyfEcE3AWuA7Dk9VjF/zavTD FNNQfaiKfuAGcBWsW6k/fGnIrKwZQtP03W2/Uq+md4Igix5FMSt4Pa9BO/DichyzuV+p a+kLGuoJDsnP3ypNdM2WDMdzOJEyJ4xV9TpQEKPmocPLU8uDBI5fQGzO4RZl35/z+xIC E0m1R3Mab1lQbkvKkD/Nmdc+eya5Rxx27xzi3MFS9Y8Ew2/jdkKmY5eUpoVIpue3Ytmf swIoBtFT9B/14r8pzp81oEf2nfZxhme5J8maH0WyMNt5QLrwQqTRNtpJjnyFeg4WCDjG bAEw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Vmebw9xz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id lz22si5319738ejb.742.2020.07.17.10.47.46; Fri, 17 Jul 2020 10:48:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Vmebw9xz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727821AbgGQRok (ORCPT + 99 others); Fri, 17 Jul 2020 13:44:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45888 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727837AbgGQRnP (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 670F9C0619D9 for ; Fri, 17 Jul 2020 10:43:15 -0700 (PDT) Received: by mail-pj1-x1042.google.com with SMTP id t15so6754773pjq.5 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=hJS2djZMvAiQY3ePnqqCbmgq+HGhJLGK4xd7Ocx1pfPlCD5KUsldVbLpgjkouNJyW4 omzPtWZRpzIT2Jm7SZNsW3YN9JPqLeGrBo+ojMo5QLwb5RLZWVUmh/KGsm3QEAQWImVg T79aRl7AdiOy0qQhM0FxkwFVxLtXugPd2Z+9bTHWiiZWwY3DRUZkWHp7EfDL5clE1KKu ZykfRllXV4e911NMKGyiR86Qe8+P17lALib4+vpIZW/1WxTBrDLpHlf8LtBRnBGO/vEI epb7WIYsluGt2eRAC3N4ryF9scLligftfNwJ5Nzvx8RlB4K3+5WYu+MsFDNQVUKbc1xE ZwCw== X-Gm-Message-State: AOAM532ESTZLweNOfB7ZiNCoZaQ2So9lGZsNhKm2yrxoDKdmOoNkV1UD DmPjVdH6bfOQhX1FetNoYLYcpQ== 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 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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 --- 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