From patchwork Mon Jan 29 02:51:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 767384 Delivered-To: patch@linaro.org Received: by 2002:adf:ee41:0:b0:33a:e5bd:fedd with SMTP id w1csp692522wro; Sun, 28 Jan 2024 18:53:36 -0800 (PST) X-Google-Smtp-Source: AGHT+IGzS4NlRvnxpkW3plcJXILOoH+SNxfudWa0eVZzK+ar6yvNuvDOnHX7gDY4dscc5kP6y/0v X-Received: by 2002:a5d:458d:0:b0:337:bcaa:9950 with SMTP id p13-20020a5d458d000000b00337bcaa9950mr3291978wrq.36.1706496816027; Sun, 28 Jan 2024 18:53:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1706496816; cv=none; d=google.com; s=arc-20160816; b=uSrcGD4e0PpbLhx0mOquqtcYZI2LGAi61DSCDwFcvyZjGI/x9dnt/0Vv+XaaSOMFgw Wucxj/EBBM+6GhLoKpKaQ6GHLGmQOVj2nQ81Kyw4ErWXHE6YX8gKU7tM3CZwMqYaw66b oM3yUIzkDWYVyCHbwAMU9Q1y3Vw0tfUFNgKnYyDyu9MdB5ONWzh1Bd8ctHS6PLMfs5BN Pg85PQp392fMTpBQYAmTmreTBiTWszwAxyR5WKur8HuLC3W3Gw5Ph0OZ4czeEaJtBbPX WvYPAMRotemLADFp/3QSgDH/XQKRyw3z+LiR8TsZpanRHqZ2bUKR7d1LkA9k+FkNm1Fg KSaw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature; bh=yxSVKAAbYmuUECgEQFX963vgXjFrGbYtCeA84cx7gqw=; fh=YtnCJplQ1DA0Rz8c1dg8CfrVxTgSI4BIXB9JUZxV1zk=; b=jHK2sGKTGt/uWKsAnIKgyX7mnX5cYasYoUy2KVDZGVrRqxw6DvPORQBRlYhxnOvXjB 6N5q0EMpGbtjaeBKk4Tjo9xXAYl7ABWE2SlBeZGihHqa6nVZ/6c0HZ/yphNupeOAnb9V loDBZ4oxIBY4ABwgkEvlv0mD//Mu7d6McQMGQe6h+wvAJdOZSyEGZU4/bkQvqaEzX/fT WZ0gFNLd6Q1txOibFt3jVs20fzVGMImMeqTlMi4/8779pUv7Y90O2qNBzl0r7vhzWPRj yP03VNUlPVjTy+1FxRUSUrXshHlgs93meTjGb/A1L/fFutnl5wYYt44S4NdT4Dwrxa6i h0zw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=lNhfbyEO; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id k4-20020a5d5244000000b00337c17666cfsi3414594wrc.572.2024.01.28.18.53.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 28 Jan 2024 18:53:36 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=lNhfbyEO; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 51BAC87CAB; Mon, 29 Jan 2024 03:53:35 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="lNhfbyEO"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 0924087CAC; Mon, 29 Jan 2024 03:53:34 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-yb1-xb30.google.com (mail-yb1-xb30.google.com [IPv6:2607:f8b0:4864:20::b30]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id D1AE7879CC for ; Mon, 29 Jan 2024 03:53:31 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=masahisa.kojima@linaro.org Received: by mail-yb1-xb30.google.com with SMTP id 3f1490d57ef6-dc22ae44595so2375535276.1 for ; Sun, 28 Jan 2024 18:53:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1706496810; x=1707101610; darn=lists.denx.de; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=yxSVKAAbYmuUECgEQFX963vgXjFrGbYtCeA84cx7gqw=; b=lNhfbyEORyAVNppBn+blhWjTy1MqQiKMBbb58S3V9NZ9GtjIoiZiYaX5DG9yyBf5ul RYsTfzObZY1LGHm35MSFQ9ZyxqqeQ4eZoYa57q21xP8P9bXNLUrboXLSQ7+ZVDeHvMK7 O3sE53nIel/QT14T2fluSHV8JfdnSl8y3/fGEkE/pgS7uPHJjaMgYz5iakGk4kIK+OqV bE6c44cecxaQvfpclltIayOHGfIjneNEZv4TCXpy/20yJBsb6WP+LsdtD8UsODcfZhVl romvm9pFXlH0yxxav4i7orhi0Zh9ZX7uCuDLW0AEJd9FG4DABN9lM+p4E/2+kX9WJCot 6X4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706496810; x=1707101610; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=yxSVKAAbYmuUECgEQFX963vgXjFrGbYtCeA84cx7gqw=; b=AoWbx25iYsD/FnlHU8LR1c9uaA6b/rU9u84CZ14EE7hHKbXuV5UBkQTOXr54WMI3rt A+z1OYJk3eqU7V7wePI6DG+X8B/S0e74RvOQd9qc4cbemO4amV6jGU90Dvu+u25GQgxx BlGhODxzBVBcKs95zjcdQdgweBxT18iMzcAAQf0gS7FLI/pOGEDTGTB1MHc39IyLUWGP Gh7n90Z6CDCzmWI4GBifDakIJPYY2kE6rKwO6GyfT8Kg53nQlT9h5MLgRLCIiKdi5EkB vM7Tc70qmLMCgjjEQ9lyvtqGKsESwFIvCm7xdrf/Hx7Y50FiT5wkxo0JGD8TaqJrbULb A97g== X-Gm-Message-State: AOJu0Yxbtol/t/UJYcJ1grJGYM6ED3UwZ/8D+ePKJcEfWx0kpHqgVOwB 2cpZ2z67qtaRp6X76DwhGwZurWeIAXCCv4ELM7t6qIlPjry4NpZQvT8bGLuUK7msOS1U4/SVqqv Y X-Received: by 2002:a05:6902:248d:b0:dc2:5553:ca12 with SMTP id ds13-20020a056902248d00b00dc25553ca12mr2306630ybb.14.1706496809803; Sun, 28 Jan 2024 18:53:29 -0800 (PST) Received: from localhost ([164.70.16.189]) by smtp.gmail.com with ESMTPSA id y9-20020a634b09000000b005d8c07588b9sm1924365pga.10.2024.01.28.18.53.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 28 Jan 2024 18:53:29 -0800 (PST) From: Masahisa Kojima To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Masahisa Kojima Subject: [PATCH v2] efi_loader: check efi_get_variable_int return value Date: Mon, 29 Jan 2024 11:51:14 +0900 Message-Id: <20240129025114.1294749-1-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean efi_get_variable_int() may fail, the buffer should be cleared before using it. Signed-off-by: Masahisa Kojima Addresses-Coverity-ID: 478333 ("Error handling issues") --- Changes in v2: - use malloc instead of calloc lib/efi_loader/efi_firmware.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/efi_loader/efi_firmware.c b/lib/efi_loader/efi_firmware.c index 9fd13297a6..ba5aba098c 100644 --- a/lib/efi_loader/efi_firmware.c +++ b/lib/efi_loader/efi_firmware.c @@ -400,18 +400,18 @@ efi_status_t efi_firmware_set_fmp_state_var(struct fmp_state *state, u8 image_in } size = num_banks * sizeof(*var_state); - var_state = calloc(1, size); + var_state = malloc(size); if (!var_state) return EFI_OUT_OF_RESOURCES; /* * GetVariable may fail, EFI_NOT_FOUND is returned if FmpState * variable has not been set yet. - * Ignore the error here since the correct FmpState variable - * is set later. */ - efi_get_variable_int(varname, image_type_id, NULL, &size, var_state, - NULL); + ret = efi_get_variable_int(varname, image_type_id, NULL, &size, + var_state, NULL); + if (ret != EFI_SUCCESS) + memset(var_state, 0, num_banks * sizeof(*var_state)); /* * Only the fw_version is set here.