Received: by 2002:a05:7412:a9a2:b0:e2:908c:2ebd with SMTP id o34csp2434517rdh; Sun, 29 Oct 2023 16:33:49 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHwnWiJGyf76+7OdOth4aoTbi5MecjXq6d8glkkICFq6DiJ73mkg1tFj2hsdtkgoegoanKm X-Received: by 2002:a05:6e02:1b05:b0:34f:7e1b:a7a2 with SMTP id i5-20020a056e021b0500b0034f7e1ba7a2mr11815624ilv.13.1698622428851; Sun, 29 Oct 2023 16:33:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698622428; cv=none; d=google.com; s=arc-20160816; b=UjgWEYa0X7bsdaN+A4/uWTbFWLVz77Lk4TsHiZ8uZXO6K8swLJUJjdv1iyNKqPCzaI HoJBEXyNw98LSGW2C0kkKOQwD19txlfjbSrHhtJ5ACxlOJ4BbPagYGdnj7kj3I5iEiDk wl+vG0epzOfJ5nuZeIr2Ld8gkJ4whOZcAu8HLyfBMCFqDa+2lVPGbbT/uy709XkKxPgD yVwlTfVDhv35pdFzs9/0wBa1zs8TpK2TO+usgDg8niOLgwpMNOGm5HPr7vF9y2UkaiXH FvkVL71I5xfXYx+iWRGOtnMezB1xvoHS/NSuP+UuFmzeyqKeFcM218QkNW1Xbsn8mMON Tvsw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Qfy0F5j76OvI0zHcfl7i3dTzNhh6bkgjVJ/OAZZJS30=; fh=0WlGvkMHQEbTqGXtBn9WIE5iCPJ2kCL3UYV6HGZPkO0=; b=EYmIQEBaPSx3f+ni64ZmAEB7Gnow9EC7Cu3h/K3ul11ROHIqEW226OWT11Q1QKN+fP mnW0o0izDvRKHeXKpKhMwFE5X3LUoenCO7g1SYZP37UiEKEgaoAYMiwVFavrtQmMx9bz 0nMvO4xP88u5r43korwLGNTbKdiAFP98tkHri2OuFFD2rerIviJ1/Iu9THMko09ZNbkL A/ZsQvOIJ3yLDuiRU9x61PHeMLAKwQcmVQ2cJB0rm7+SpncHzKOZ1KFlEEFJJQzUmbnw 1kmv0AR8/ouVD9Tlzz9HZuKWrLTLh9BxUYc+6wOUWONeA8y633fNSuEZ5YM/ecqxCp1G fW3g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=EClnxfQa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id ka27-20020a056a00939b00b006be1d2ee8f9si4222819pfb.224.2023.10.29.16.33.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 29 Oct 2023 16:33:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=EClnxfQa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id A3BE180B81EA; Sun, 29 Oct 2023 16:33:47 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232701AbjJ2Xdi (ORCPT + 99 others); Sun, 29 Oct 2023 19:33:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42330 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231887AbjJ2XdS (ORCPT ); Sun, 29 Oct 2023 19:33:18 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8CD151FE7; Sun, 29 Oct 2023 15:55:37 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F3A2CC43391; Sun, 29 Oct 2023 22:55:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1698620137; bh=b6kCZ/VuTqfdqRtkQc9f6g0UaXs3C8pEWBckCzBd+Nc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EClnxfQaXYm+cJT43BKvI1JeQoyQeVEeYexFPKhLPIYhCTgu2Spqo0km5PO5vX9+T MSGfNB1FQ3kK0yPfzu3tIwjDlWcVt3rl/j3brYMVAl1DUi46Hf4j8CHWBf2chGMnBr evX/DqgcMo10Ggc67QFU4dgHQuQPJygDTqhy0CRxLwLViWsS/0nTVoDRjiK0da9q2p fIkM06kFAKPiOFFt9DmqIWFvnXuMsoH5Mp51XwJ1G8zVN2W+8z2tQOrdVX599u9MYx MvMFsyDxrInO65HxnDH1K9uxBB01Ve2fUexbj69YfKVFBU24Ka0U5kTtAtMpm4D/3c M9xjyY0jWptag== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Kuan-Wei Chiu , Ard Biesheuvel , Sasha Levin , linux-efi@vger.kernel.org Subject: [PATCH AUTOSEL 6.5 27/52] efi: fix memory leak in krealloc failure handling Date: Sun, 29 Oct 2023 18:53:14 -0400 Message-ID: <20231029225441.789781-27-sashal@kernel.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231029225441.789781-1-sashal@kernel.org> References: <20231029225441.789781-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 6.5.9 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Sun, 29 Oct 2023 16:33:47 -0700 (PDT) From: Kuan-Wei Chiu [ Upstream commit 0d3ad1917996839a5042d18f04e41915cfa1b74a ] In the previous code, there was a memory leak issue where the previously allocated memory was not freed upon a failed krealloc operation. This patch addresses the problem by releasing the old memory before setting the pointer to NULL in case of a krealloc failure. This ensures that memory is properly managed and avoids potential memory leaks. Signed-off-by: Kuan-Wei Chiu Signed-off-by: Ard Biesheuvel Signed-off-by: Sasha Levin --- drivers/firmware/efi/efi.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c index 1599f11768426..9cfac61812f68 100644 --- a/drivers/firmware/efi/efi.c +++ b/drivers/firmware/efi/efi.c @@ -273,9 +273,13 @@ static __init int efivar_ssdt_load(void) if (status == EFI_NOT_FOUND) { break; } else if (status == EFI_BUFFER_TOO_SMALL) { - name = krealloc(name, name_size, GFP_KERNEL); - if (!name) + efi_char16_t *name_tmp = + krealloc(name, name_size, GFP_KERNEL); + if (!name_tmp) { + kfree(name); return -ENOMEM; + } + name = name_tmp; continue; } -- 2.42.0