All of lore.kernel.org
 help / color / mirror / Atom feed
From: Lukasz Majewski <lukma@denx.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v2 2/4] disk: efi: Fix memory leak on 'gpt verify'
Date: Tue, 7 May 2019 09:02:52 +0200	[thread overview]
Message-ID: <20190507090252.366346f9@jawa> (raw)
In-Reply-To: <20190502122706.27592-3-erosca@de.adit-jv.com>

On Thu, 2 May 2019 14:27:04 +0200
Eugeniu Rosca <erosca@de.adit-jv.com> wrote:

> Below is what happens on R-Car H3ULCB-KF using clean U-Boot
> v2019.04-00810-g6aebc0d11a10 and r8a7795_ulcb_defconfig:
> 
>  => ### interrupt autoboot
>  => gpt verify mmc 1  
>  No partition list provided - only basic check
>  Verify GPT: success!
>  => ### keep calling 'gpt verify mmc 1'
>  => ### on 58th call, we are out of memory:
>  => gpt verify mmc 1  
>  alloc_read_gpt_entries: ERROR: Can't allocate 0X4000 bytes for GPT
> Entries GPT: Failed to allocate memory for PTE
>  gpt_verify_headers: *** ERROR: Invalid Backup GPT ***
>  Verify GPT: error!
> 
> This is caused by calling is_gpt_valid() twice (hence allocating pte
> also twice via alloc_read_gpt_entries()) while freeing pte only _once_
> in the caller of gpt_verify_headers(). Fix that by freeing the pte
> allocated and populated for primary GPT _before_ allocating and
> populating the pte for backup GPT. The latter will be freed by the
> caller of gpt_verify_headers().
> 
> With the fix applied, the reproduction scenario [1-2] has been run
> hundreds of times in a loop w/o running into OOM.
> 
> [1] gpt verify mmc 1
> [2] gpt verify mmc 1 $partitions
> 
> Fixes: cef68bf9042dda ("gpt: part: Definition and declaration of GPT
> verification functions") Signed-off-by: Eugeniu Rosca
> <erosca@de.adit-jv.com> Reviewed-by: Heinrich Schuchardt
> <xypron.glpk@gmx.de> --
> v2:
>  - Added Reviewed-by: Heinrich Schuchardt
> v1:
>  - https://patchwork.ozlabs.org/patch/1092943/
> ---
>  disk/part_efi.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/disk/part_efi.c b/disk/part_efi.c
> index 812d14cdd871..c0fa753339c8 100644
> --- a/disk/part_efi.c
> +++ b/disk/part_efi.c
> @@ -698,6 +698,10 @@ int gpt_verify_headers(struct blk_desc
> *dev_desc, gpt_header *gpt_head, __func__);
>  		return -1;
>  	}
> +
> +	/* Free pte before allocating again */
> +	free(*gpt_pte);
> +
>  	if (is_gpt_valid(dev_desc, (dev_desc->lba - 1),
>  			 gpt_head, gpt_pte) != 1) {
>  		printf("%s: *** ERROR: Invalid Backup GPT ***\n",

Reviewed-by: Lukasz Majewski <lukma@denx.de>


Best regards,

Lukasz Majewski

--

DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email: lukma at denx.de
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 488 bytes
Desc: OpenPGP digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20190507/61711568/attachment.sig>

  reply	other threads:[~2019-05-07  7:02 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-02 12:27 [U-Boot] [PATCH v2 0/4] Misc EFI/GPT/UUID fixes Eugeniu Rosca
2019-05-02 12:27 ` [U-Boot] [PATCH v2 1/4] disk: efi: Fix memory leak on 'gpt guid' Eugeniu Rosca
2019-05-07  7:03   ` Lukasz Majewski
2019-05-07  7:10     ` Eugeniu Rosca
2019-05-07  8:11       ` Lukasz Majewski
2019-05-07 12:08         ` Eugeniu Rosca
2019-05-02 12:27 ` [U-Boot] [PATCH v2 2/4] disk: efi: Fix memory leak on 'gpt verify' Eugeniu Rosca
2019-05-07  7:02   ` Lukasz Majewski [this message]
2019-05-02 12:27 ` [U-Boot] [PATCH v2 3/4] cmd: gpt: fix and tidy up help message Eugeniu Rosca
2019-05-07  7:01   ` Lukasz Majewski
2019-05-02 12:27 ` [U-Boot] [PATCH v2 4/4] lib: uuid: Fix unseeded PRNG on RANDOM_UUID=y Eugeniu Rosca
2019-05-02 16:19   ` Heinrich Schuchardt
2019-05-07  7:04   ` Lukasz Majewski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190507090252.366346f9@jawa \
    --to=lukma@denx.de \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.