From patchwork Tue Jul 7 08:19:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 11648005 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 78FB4912 for ; Tue, 7 Jul 2020 08:19:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 61237206F6 for ; Tue, 7 Jul 2020 08:19:42 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="d2fuJhBs" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728208AbgGGITi (ORCPT ); Tue, 7 Jul 2020 04:19:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51502 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728150AbgGGITd (ORCPT ); Tue, 7 Jul 2020 04:19:33 -0400 Received: from mail-pg1-x542.google.com (mail-pg1-x542.google.com [IPv6:2607:f8b0:4864:20::542]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C2C26C08C5DB for ; Tue, 7 Jul 2020 01:19:33 -0700 (PDT) Received: by mail-pg1-x542.google.com with SMTP id j19so12793869pgm.11 for ; Tue, 07 Jul 2020 01:19:33 -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=8LzHvhyH79XNraI64aGNs932IW1tYhCTGhfJh2lEVIw=; b=d2fuJhBs1yWbjePYoqvJWYZe1SRSJgbjp553u56FFd31yWYbHWdQauk74RXaM6QK5Z 6wtktQwojSEogkmCtIrko7hYiDkU9vh+r9y+G9YbC23l+ldCh74l7x4YprTb5e1AAhlW wDajPTrKHOXyHe/oURDusoQV86iqeDJZ91LRk= 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=8LzHvhyH79XNraI64aGNs932IW1tYhCTGhfJh2lEVIw=; b=cH3Qf2rw9LKRBYc/RlEXT8XxGYtVEtXPmFoT5GBLxfkJcd5c5ciVt+iz7R0tNjn3VX nYsr5yig+RhKOE3XJ/pjyk4iHoI9rwF6HZY1NAOj1u/2bcf5adYCqAAWGPXf6yslJY0s cO3r8X3KvgIqP5eO5R7rU2J/w+GToPRSqbJDE35uHZzF9PfGb5v8Dbbw1Ue0b8W60QOk avqCVFOY9GlrBVpODo4cGJNYY2EMZC7zRcexXRqn10e3wT0hl0oVt+/R15HNfUGdwf0o vc1WG0WxR3hzRVksHr0iGfhc2fHCJhXoR+In8wYcxzJkOrZceQoJNwRmfnVLqiYQ6S80 kwug== X-Gm-Message-State: AOAM5333qPcyXlES5EXIbVrlFCcv3CV93OVRMEZDdqe8ed0ukxgvfeA4 yzMInURroSFSkodGDhxtSJxCqw== X-Google-Smtp-Source: ABdhPJwlmQnAhT5yC6LPH3rR/m0Ap5gtjZUGRRbIWoOIwPOnnsVXMjkjdE7a5NAxP236CA/vqMmsAw== X-Received: by 2002:a63:2b93:: with SMTP id r141mr43550710pgr.171.1594109973034; Tue, 07 Jul 2020 01:19:33 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id s10sm1821622pjl.41.2020.07.07.01.19.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jul 2020 01:19:30 -0700 (PDT) From: Kees Cook To: James Morris Cc: Kees Cook , stable@vger.kernel.org, Luis Chamberlain , Mimi Zohar , Scott Branden , 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 , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-integrity@vger.kernel.org, linux-security-module@vger.kernel.org Subject: [PATCH 1/4] firmware_loader: EFI firmware loader must handle pre-allocated buffer Date: Tue, 7 Jul 2020 01:19:23 -0700 Message-Id: <20200707081926.3688096-2-keescook@chromium.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200707081926.3688096-1-keescook@chromium.org> References: <20200707081926.3688096-1-keescook@chromium.org> MIME-Version: 1.0 Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: 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 --- 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;