From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.71) id 1b6ZHs-0004n0-BI for mharc-grub-devel@gnu.org; Sat, 28 May 2016 04:08:00 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56053) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b6ZHp-0004mp-Vp for grub-devel@gnu.org; Sat, 28 May 2016 04:07:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b6ZHj-0000nc-MO for grub-devel@gnu.org; Sat, 28 May 2016 04:07:56 -0400 Received: from mail-lb0-x244.google.com ([2a00:1450:4010:c04::244]:36754) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b6ZHj-0000nY-Dw for grub-devel@gnu.org; Sat, 28 May 2016 04:07:51 -0400 Received: by mail-lb0-x244.google.com with SMTP id r5so6735445lbj.3 for ; Sat, 28 May 2016 01:07:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding; bh=WcsCIiz+4TjbQ2/wXod/29mHsyNKJ17YDqExPu29xQg=; b=aOIURxvQ1xVJ3XFDxCTUfAhwnZo0OCacLrYI0EtyQoUuaS3tRdm4dkjKvDlHa5WKI3 MsZPxYm1KA9zrPJEkjFr7g0x5IaxZCewPrCsXn7NRJZnlEsMhz55ZqN7DRnNAw7d6Qiu JCdKeRgjckdibg529zFLfSecPcL6Dh7ial5Dh/vuEN0xyQAGks0XlCmkk2RamDnI1l/K /rRj8A6kLlXiYmhKkOYD35wYFTj18tV0dCROJS4zYN9G53rdlhnJVQ7EyI3ny0fhM6qb vABKzK5Z/LbHaJl68yV+Mfi+TdiIGlgX+a3ywQS4CmxscsuOSGd3l16myfutrLMEVyMs jAHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=WcsCIiz+4TjbQ2/wXod/29mHsyNKJ17YDqExPu29xQg=; b=b2LUteW1Muj+INm2vqaNV87XkGOReVY1Z1RWOHPd4ztBCVtDWzFsRfuY4vDeB/qSVu 3fI5kHRzq+XsdAX2ofnniUvFvXGo2Y1RpzNSUVkDOwx4GDVSCwmtIBS9eTeRcExIrna7 Fl63ybZNSaJvFMNSF6ymE36nC7p/HYTat66MiiMYc2koMuOXIL2airMPVLukV+ZOz0n0 Pu5IiIvSwkBTNpmihfnytHPsOYYhhk4cQER8jz/o+UDNB5Oev6nDTa/edo7iTa10vUde jSyusgbjgdQvfCnOSbA1WUm3UGHba3QZQZcsKVKiPbRB5Tq4YO60kmIyp4rxk5AIcLIM Wg5g== X-Gm-Message-State: ALyK8tJPt4tmwTLVukRat0BV4tNQYlDO+Odmv1qltqo53TgN3khTtKtczUMssyfSQwQp7w== X-Received: by 10.112.25.2 with SMTP id y2mr5826517lbf.104.1464422870674; Sat, 28 May 2016 01:07:50 -0700 (PDT) Received: from [192.168.1.42] (ppp109-252-90-46.pppoe.spdop.ru. [109.252.90.46]) by smtp.gmail.com with ESMTPSA id h16sm3391766lfb.7.2016.05.28.01.07.49 for (version=TLSv1/SSLv3 cipher=OTHER); Sat, 28 May 2016 01:07:49 -0700 (PDT) Subject: Re: [PATCH] efi: Free malloc regions on exit To: The development of GNU GRUB References: <1463665072-32385-1-git-send-email-agraf@suse.de> <573E8AE5.2060207@gmail.com> <20160520043410.GC22923@linux-9gqx.suse> From: Andrei Borzenkov X-Enigmail-Draft-Status: N1110 Message-ID: <574951D5.6000105@gmail.com> Date: Sat, 28 May 2016 11:07:49 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.8.0 MIME-Version: 1.0 In-Reply-To: <20160520043410.GC22923@linux-9gqx.suse> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:4010:c04::244 X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 28 May 2016 08:07:59 -0000 20.05.2016 07:34, Michael Chang пишет: > On Fri, May 20, 2016 at 06:56:21AM +0300, Andrei Borzenkov wrote: >> 19.05.2016 16:37, Alexander Graf пишет: >>> When we exit grub, we don't free all the memory that we allocated earlier >>> for our heap region. This can cause problems with setups where you try >>> to descend the boot order using "exit" entries, such as PXE -> HD boot >>> scenarios. >>> >>> Signed-off-by: Alexander Graf >>> --- >>> grub-core/kern/efi/init.c | 1 + >>> grub-core/kern/efi/mm.c | 24 ++++++++++++++++++++++++ >>> include/grub/efi/efi.h | 1 + >>> 3 files changed, 26 insertions(+) >>> >>> diff --git a/grub-core/kern/efi/init.c b/grub-core/kern/efi/init.c >>> index e9c85de..b848014 100644 >>> --- a/grub-core/kern/efi/init.c >>> +++ b/grub-core/kern/efi/init.c >>> @@ -77,4 +77,5 @@ grub_efi_fini (void) >>> { >>> grub_efidisk_fini (); >>> grub_console_fini (); >>> + grub_efi_memory_fini (); >>> } >> >> Note that grub_efi_fini() is called not only during exit, but also by >> grub_loader_boot (grub_machine_fini); and - at least, theoretically - >> grub_loader_boot_func can fail and we return back to GRUB. Which leaves >> us with heap pointing to already freed area. We probably cannot do >> anything useful at this point anyway, but this may lead to corruption of >> memory allocated by other EFI drivers. > > I think grub_machine_fini is called without GRUB_LOADER_FLAG_NORETURN flag set > in above-mentioned case so that it should be fine. > Well, there are calls both with and without GRUB_LOADER_FLAG_NORETURN. It is true that for EFI platform all *existing* calls are without, but nothing really forces it. I am a bit uneasy about it. Ideally I'd prefer clean code path that frees memory immediately before existing GRUB. > Thanks, > Michael > >> >> May be it should be called explicitly only in exit path. >> >> Also it is not called during chainload at all, which should have the >> same problem (i.e. conceptually it does not matter whether we exit grub >> and select next binary from EFI menu or simply try to chainload it from >> grub). >> No comments?