Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2660672pxa; Mon, 17 Aug 2020 15:49:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwP7n9KYe6Os2JF4E9EOwX5nEPLjxgzNWADJa6EAlJMdvUpJKcvHxJFMfyOODzw7o2GYFWZ X-Received: by 2002:a50:de04:: with SMTP id z4mr17433984edk.10.1597704583421; Mon, 17 Aug 2020 15:49:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597704583; cv=none; d=google.com; s=arc-20160816; b=OyB45N0B6kTaPiydUbv1G3ghUw3olhei+JiisGQ52aw/sP2uWE5iJdijBxhm+awMAR fDjKT/avu60KfHbWZYhUnCnHQffQsvFsG98wS/D7/vWWBVGGn7MpK4E5XCY/pGAMNKTo YLH2RXFdaFL/fT5a7yaplq6LfZAj2winMcqr/6tEAr63sznl5IkxCiRmjD+Yf7AmP9E9 R9p/xcZ5iBL6KngqRkJ/9qXLSSm8Mkk09cAt/QinSA7ea4bjcm1M0jf+6cit7ekgWct9 lKq+boAECnOURnrl68E8LW0hFaeTnGVjZBID+WPMZUSJ/vELtV5SfWnh7wY1OXt1C27q o0mw== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=QDTbek8e5U4Cus4YxfC8O3Vg4Nfb5tbO1sybvlqtopc=; b=jXDWelxmKSQ3Zgo5tPLsvp/h9NwPRXnUIylC3YlOBmWDtxlnK1z/2kbAuWl0Gu4zbk R7GMp4NkjVzSs+PIp7Ea9DxBSpfwLRB7PW47b5zEckg7ffdq5vvEtMAz9QLexK+nfGJP AhFCV/BlxTrnklUUUcqTJE1qy777lQQj2MZbq5P389qPfzo6/QmXiUUhYLsUZjaUp93v kpNFoYEdlyh7jmb52hEhuNEk3OlbgygwG3CKnyQQ5VryvQ0HuitT5XImEbWabNSv4aq6 n/a0ElJduN2dlcBSxQOU9t0RVguw7a+3lB1FogZ5Y4+HQmVptSa+rAin/8LJTDTijU18 FhJg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=MGWQKNdz; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p16si11909774ejx.540.2020.08.17.15.49.20; Mon, 17 Aug 2020 15:49:43 -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=@kernel.org header.s=default header.b=MGWQKNdz; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731884AbgHQTNV (ORCPT + 99 others); Mon, 17 Aug 2020 15:13:21 -0400 Received: from mail.kernel.org ([198.145.29.99]:49112 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730666AbgHQPkW (ORCPT ); Mon, 17 Aug 2020 11:40:22 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 18B862336F; Mon, 17 Aug 2020 15:40:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597678821; bh=5QAZABmxmAr8UBXRYsJfzTUAG8IuMU8x+DTk2b2D7dY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MGWQKNdz+qcMD+rLv87syOU5G/Y3b2uRq+JepKx3kAEQcEOM5tUe80ItPEAAURnc9 HrgMomtfb9SEFgopkKQyKp6I7MW5fz/5cmqd6N5ZK42xn7dPuXya9dejAMEikdp+EB exdIHzAtOBOAXUc5KSoTjMd8/66A9M9+p5ShoPmI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Scott Branden , Kees Cook Subject: [PATCH 5.8 452/464] firmware_loader: EFI firmware loader must handle pre-allocated buffer Date: Mon, 17 Aug 2020 17:16:45 +0200 Message-Id: <20200817143855.425787694@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200817143833.737102804@linuxfoundation.org> References: <20200817143833.737102804@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Kees Cook commit 4fb60b158afd3ac9e0fe9975aa476213f5cc0a4d upstream. 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 firmware_request_platform()") Cc: stable@vger.kernel.org Acked-by: Scott Branden Signed-off-by: Kees Cook Link: https://lore.kernel.org/r/20200724213640.389191-4-keescook@chromium.org Signed-off-by: Greg Kroah-Hartman --- drivers/base/firmware_loader/fallback_platform.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) --- 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 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;