From: Miao Xie <miaox@cn.fujitsu.com>
To: Dan Carpenter <dan.carpenter@oracle.com>
Cc: Chris Mason <chris.mason@fusionio.com>,
linux-btrfs@vger.kernel.org, kernel-janitors@vger.kernel.org
Subject: Re: [patch] btrfs/raid56: fix and cleanup some error paths
Date: Mon, 22 Jul 2013 16:47:00 +0800 [thread overview]
Message-ID: <51ECF184.9030305@cn.fujitsu.com> (raw)
In-Reply-To: <20130722065515.GB14617@longonot.mountain>
On mon, 22 Jul 2013 09:55:15 +0300, Dan Carpenter wrote:
> The alloc_rbio() frees "raid_map" and "bbio" on error, so there is a
> potential double free bug in raid56_parity_write(). The
> raid56_parity_write() and raid56_parity_recover() functions should still
> free "raid_map" and "bbio" on error if other errors occur though, so I
> have added some more calls to kfree().
>
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
>From the viewpoint of the readability, it is better to free raid_map and bbio
in the caller, I think. But it is up to you.
Reviewed-by: Miao Xie <miaox@cn.fujitsu.com>
>
> diff --git a/fs/btrfs/raid56.c b/fs/btrfs/raid56.c
> index 0525e13..0db856c 100644
> --- a/fs/btrfs/raid56.c
> +++ b/fs/btrfs/raid56.c
> @@ -1687,11 +1687,8 @@ int raid56_parity_write(struct btrfs_root *root, struct bio *bio,
> struct blk_plug_cb *cb;
>
> rbio = alloc_rbio(root, bbio, raid_map, stripe_len);
> - if (IS_ERR(rbio)) {
> - kfree(raid_map);
> - kfree(bbio);
> + if (IS_ERR(rbio))
> return PTR_ERR(rbio);
> - }
> bio_list_add(&rbio->bio_list, bio);
> rbio->bio_list_bytes = bio->bi_size;
>
> @@ -2041,9 +2038,8 @@ int raid56_parity_recover(struct btrfs_root *root, struct bio *bio,
> int ret;
>
> rbio = alloc_rbio(root, bbio, raid_map, stripe_len);
> - if (IS_ERR(rbio)) {
> + if (IS_ERR(rbio))
> return PTR_ERR(rbio);
> - }
>
> rbio->read_rebuild = 1;
> bio_list_add(&rbio->bio_list, bio);
> @@ -2052,6 +2048,8 @@ int raid56_parity_recover(struct btrfs_root *root, struct bio *bio,
> rbio->faila = find_logical_bio_stripe(rbio, bio);
> if (rbio->faila == -1) {
> BUG();
> + kfree(raid_map);
> + kfree(bbio);
> kfree(rbio);
> return -EIO;
> }
> --
> To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
next prev parent reply other threads:[~2013-07-22 8:46 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-07-22 6:55 [patch] btrfs/raid56: fix and cleanup some error paths Dan Carpenter
2013-07-22 8:47 ` Miao Xie [this message]
2013-07-22 13:02 ` Dan Carpenter
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=51ECF184.9030305@cn.fujitsu.com \
--to=miaox@cn.fujitsu.com \
--cc=chris.mason@fusionio.com \
--cc=dan.carpenter@oracle.com \
--cc=kernel-janitors@vger.kernel.org \
--cc=linux-btrfs@vger.kernel.org \
/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).