Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp860719rdg; Fri, 13 Oct 2023 03:33:13 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF4Un/4SjVSK92VJvSSbE5wr/YR/baosikUdji/OGWOTBO5sJdRbS0ZopEvx5reRW9T1dsq X-Received: by 2002:a05:6e02:1ba4:b0:357:4630:e98d with SMTP id n4-20020a056e021ba400b003574630e98dmr10612845ili.14.1697193193221; Fri, 13 Oct 2023 03:33:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697193193; cv=none; d=google.com; s=arc-20160816; b=PQYqp2BmErukjz0n1oJA88Dx5VB4qeUp0Sn1VJpntQy+2sJEsPrgYFmH29mT9+rvuJ VoqV73Jab2sjhizjwtTrn/HDFiuv6XB1toLk8xeDRVEbjq/7EYp53NFNeVuTP9qZG9jO az69ane+7Em2DCYdolTchVjGhKQztEzDJDNg59qI4l4HgztM0YnsBVx+btFmJUPeMp8r iAhSW6lgkm2W1IaEP/vr78jSchxkmXKM4TkQzU9ojzPx27tEqiWwNW2BaWbA6jKDbsE1 kRmmbCloA2ankZAqUaKRYOERsTScVPlLv3ddx9hwQNos8T4mIwZGmmh8AkpTsCN2MgNP Jynw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=L+4L2vD6cR+xQ/qw6alODWptfNQ4BUcko51gs4JxYNs=; fh=TrRZXvQc3tkmLhq16V0r8I5r0YwT2PC8HLPAbWy3Gu0=; b=uFI1Cx322Uh2y3TYmAB+L9eBqbYug0UzPQt6rm5zAbHErRcrjvSnrZyHuw9V8diH4B dN2bGxr+Iia1/xFmImeCV4qfIKkPXR4/0RBfx0+pQtzhExZ4+DdMa/dQvbHcJ4Uss7uV OknARdf5RG4YTvoqZ45CCvm8juE4HfY+FqXXCRnnEDwrMjig8PyFeHtCHLC2n/9y8n8s 8qFq1kziJRCmd0tJPqlNdom2MlATeO22cCuVdJRGeB4tS5lER1mbbw7IMUGfpHf18xKB 4LMtnvu/De8JFm/7AlK0x2NCuvHHQHLJV8YOUhXUD0kt/5oyj142VAHmCDcnc8bLvbqF 8piQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="Bnd971Q/"; 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 e36-20020a631e24000000b005891f742957si4287910pge.570.2023.10.13.03.33.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 03:33:13 -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="Bnd971Q/"; 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 50CA782F926C; Fri, 13 Oct 2023 03:33:12 -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 S230197AbjJMKdJ (ORCPT + 99 others); Fri, 13 Oct 2023 06:33:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48488 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230051AbjJMKdI (ORCPT ); Fri, 13 Oct 2023 06:33:08 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3700CAD; Fri, 13 Oct 2023 03:33:07 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CB9E1C433C7; Fri, 13 Oct 2023 10:33:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1697193186; bh=BsRRCTgfv4s5mcrfc+WIgfWAClijm+lJdkXG/FXGv/k=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=Bnd971Q/aaYTrHovJzLffi+8pUc0hGYORkTU2UvVIyHJfn+N6QHUmkYF+zGkD+Pwa LRaJ6/fH0ablh8WSd2Gn76oebFaPRTUyvGEuLRicCp2d774vdxJcj7ldTKqgga9wt8 /y00u1nJF/SpZ3VRvdD4ZqRMHE/KskkR6K4AkiwL+PiB/RO+rPamhg3EovostCfDBe nf0NzDOVEbT9exasxpGnz/YiNaVmg8aMShFZC8f5nc/uwn094glhrCAfoERnC7fyd9 s+fEd2nd7Dl5KWEaiuhYJtZSw3lBWW5+PdSV/8bJw3NHe9KQmpZcoal4g7S5+CLZS8 v5e67AnlFx/Fg== Received: by mail-lj1-f176.google.com with SMTP id 38308e7fff4ca-2c186ea81c7so24755651fa.1; Fri, 13 Oct 2023 03:33:06 -0700 (PDT) X-Gm-Message-State: AOJu0YwvRPoh6MzrqHA6oaWIDjZfsi+gNh4vQW/dctM1z0GtSWKFQ9O/ XqsXoGdJF8Ufb1WiiLwxmn+R4Qun8IoOIfBvzBE= X-Received: by 2002:a2e:a98e:0:b0:2c5:1c4:9005 with SMTP id x14-20020a2ea98e000000b002c501c49005mr2236389ljq.32.1697193185025; Fri, 13 Oct 2023 03:33:05 -0700 (PDT) MIME-Version: 1.0 References: <20230924142633.1090000-1-visitorckw@gmail.com> In-Reply-To: <20230924142633.1090000-1-visitorckw@gmail.com> From: Ard Biesheuvel Date: Fri, 13 Oct 2023 12:32:53 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] efi: fix memory leak in krealloc failure handling To: Kuan-Wei Chiu Cc: linux-efi@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.1 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]); Fri, 13 Oct 2023 03:33:12 -0700 (PDT) On Sun, 24 Sept 2023 at 16:26, Kuan-Wei Chiu wrote: > > 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 > --- > drivers/firmware/efi/efi.c | 8 ++++++-- > 1 file changed, 6 insertions(+), 2 deletions(-) > Queued as a fix Thanks, > diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c > index ce20a60676f0..1974f0ad32ba 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.25.1 >