linux-raid.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
To: Wu Guanghao <wuguanghao3@huawei.com>
Cc: <jes@trained-monkey.org>, <linux-raid@vger.kernel.org>,
	<linfeilong@huawei.com>, <lixiaokeng@huawei.com>
Subject: Re: [PATCH 3/5] load_imsm_mpb: fix double free
Date: Tue, 31 May 2022 09:54:53 +0200	[thread overview]
Message-ID: <20220531095453.00001a7a@linux.intel.com> (raw)
In-Reply-To: <4ded262a-9313-d328-a3e1-fca56210bf62@huawei.com>

On Tue, 31 May 2022 14:50:19 +0800
Wu Guanghao <wuguanghao3@huawei.com> wrote:

> When free(super->buf) but not set super->buf = NULL, will be double free
> 
> get_super_block
> 	err = load_and_parse_mpb
> 		load_imsm_mpb(.., s, ..)
> 			if (posix_memalign(&super->buf, MAX_SECTOR_SIZE,
> super->len) != 0) // true, super->buf != NULL if
> (posix_memalign(&super->migr_rec_buf, MAX_SECTOR_SIZE,); // false
> free(super->buf); //but super->buf not set NULL return 2;
> 
> 	if err ! = 0
> 		if (s)
> 			free_imsm(s)
> 				 __free_imsm(s)
> 					if (s)
> 						free(s->buf); //double free
> 
> Signed-off-by: Wu Guanghao <wuguanghao3@huawei.com>
> ---
>  super-intel.c | 1 -
>  1 file changed, 1 deletion(-)
> 
> diff --git a/super-intel.c b/super-intel.c
> index ba3bd41f..ef21ffba 100644
> --- a/super-intel.c
> +++ b/super-intel.c
> @@ -4452,7 +4452,6 @@ static int load_imsm_mpb(int fd, struct intel_super
> *super, char *devname) if (posix_memalign(&super->migr_rec_buf,
> MAX_SECTOR_SIZE, MIGR_REC_BUF_SECTORS*MAX_SECTOR_SIZE) != 0) {
>  		pr_err("could not allocate migr_rec buffer\n");
> -		free(super->buf);
>  		return 2;
>  	}
>  	super->clean_migration_record_by_mdmon = 0;

On error, we should possibly clean-up ourselves so I would expect from 
load_imsm_mpb() to free super->buf in case when error occurs and set it
to NULL, especially that __free_imsm handles it.

Thanks,
Mariusz

  reply	other threads:[~2022-05-31  7:55 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-31  6:48 [PATCH 0/5] mdadm: fix memory leak and double free Wu Guanghao
2022-05-31  6:49 ` [PATCH 1/5] parse_layout_faulty: fix memleak Wu Guanghao
2022-05-31  7:36   ` Mariusz Tkaczyk
2022-06-07  7:24     ` Wu Guanghao
2022-05-31  6:49 ` [PATCH 2/5] Detail: " Wu Guanghao
2022-05-31  7:42   ` Mariusz Tkaczyk
2022-05-31  6:50 ` [PATCH 3/5] load_imsm_mpb: fix double free Wu Guanghao
2022-05-31  7:54   ` Mariusz Tkaczyk [this message]
2022-05-31  6:50 ` [PATCH 4/5] find_disk_attached_hba: fix memleak Wu Guanghao
2022-05-31  8:04   ` Mariusz Tkaczyk
2022-06-07  7:36     ` Wu Guanghao
2022-05-31  6:51 ` [PATCH 5/5] get_vd_num_of_subarray: " Wu Guanghao
2022-05-31  8:11   ` Mariusz Tkaczyk
2022-05-31  8:25     ` Paul Menzel
2022-06-07  6:32       ` Mariusz Tkaczyk
2022-05-31  6:57 ` [PATCH 0/5] mdadm: fix memory leak and double free Paul Menzel
2022-06-07  7:39   ` Wu Guanghao

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=20220531095453.00001a7a@linux.intel.com \
    --to=mariusz.tkaczyk@linux.intel.com \
    --cc=jes@trained-monkey.org \
    --cc=linfeilong@huawei.com \
    --cc=linux-raid@vger.kernel.org \
    --cc=lixiaokeng@huawei.com \
    --cc=wuguanghao3@huawei.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).