From: Naveen Goswamy <naveen.goswamy@polymtl.ca>
To: "'Dave Jones'" <davej@redhat.com>
Cc: Jack Wang <jack_wang@usish.com>, "'Tejun Heo'" <tj@kernel.org>,
"'Jun'ichi Nomura'" <j-nomura@ce.jp.nec.com>,
"'Jens Axboe'" <axboe@kernel.dk>,
linux-kernel@vger.kernel.org,
"'linux-scsi'" <linux-scsi@vger.kernel.org>,
"'James Bottomley'" <James.Bottomley@HansenPartnership.com>,
"'Stefan Richter'" <stefanr@s5r6.in-berlin.de>,
sgruszka@redhat.com, "'Huajun Li'" <huajun.li.lee@gmail.com>
Subject: Re: [PATCH] Fix NULL pointer dereference in sd_revalidate_disk
Date: Wed, 29 Feb 2012 13:46:43 -0500 [thread overview]
Message-ID: <1330541203.4f4e7293d1477@www.imp.polymtl.ca> (raw)
In-Reply-To: <20120222053651.GA7891@redhat.com>
I have tested Dave Jones' 3.2 backport patch in gentoo, against kernel sources
3.2.1-gentoo-r2 and it works as well.
Regards,
Naveen
Quoting 'Dave Jones' <davej@redhat.com>:
> On Wed, Feb 22, 2012 at 12:58:08PM +0800, Jack Wang wrote:
> > Should this need pick up into stable too?
> >
> > Jack
>
> The 3.2 backport seems fairly trivial (just some stuff moved to different
> files)
> Here's the patch I did for Fedora.
>
> Dave
>
> --- linux/fs/partitions/check.c~ 2012-02-20 18:32:55.314253719 -0500
> +++ linux/fs/partitions/check.c 2012-02-20 18:34:46.509859745 -0500
> @@ -539,17 +539,11 @@ static bool disk_unlock_native_capacity(
> }
> }
>
> -int rescan_partitions(struct gendisk *disk, struct block_device *bdev)
> +static int drop_partitions(struct gendisk *disk, struct block_device *bdev)
> {
> - struct parsed_partitions *state = NULL;
> struct disk_part_iter piter;
> struct hd_struct *part;
> - int p, highest, res;
> -rescan:
> - if (state && !IS_ERR(state)) {
> - kfree(state);
> - state = NULL;
> - }
> + int res;
>
> if (bdev->bd_part_count)
> return -EBUSY;
> @@ -562,6 +556,24 @@ rescan:
> delete_partition(disk, part->partno);
> disk_part_iter_exit(&piter);
>
> + return 0;
> +}
> +
> +int rescan_partitions(struct gendisk *disk, struct block_device *bdev)
> +{
> + struct parsed_partitions *state = NULL;
> + struct hd_struct *part;
> + int p, highest, res;
> +rescan:
> + if (state && !IS_ERR(state)) {
> + kfree(state);
> + state = NULL;
> + }
> +
> + res = drop_partitions(disk, bdev);
> + if (res)
> + return res;
> +
> if (disk->fops->revalidate_disk)
> disk->fops->revalidate_disk(disk);
> check_disk_size_change(disk, bdev);
> @@ -665,6 +677,26 @@ rescan:
> return 0;
> }
>
> +int invalidate_partitions(struct gendisk *disk, struct block_device *bdev)
> +{
> + int res;
> +
> + if (!bdev->bd_invalidated)
> + return 0;
> +
> + res = drop_partitions(disk, bdev);
> + if (res)
> + return res;
> +
> + set_capacity(disk, 0);
> + check_disk_size_change(disk, bdev);
> + bdev->bd_invalidated = 0;
> + /* tell userspace that the media / partition table may have changed */
> + kobject_uevent(&disk_to_dev(disk)->kobj, KOBJ_CHANGE);
> +
> + return 0;
> +}
> +
> unsigned char *read_dev_sector(struct block_device *bdev, sector_t n, Sector
> *p)
> {
> struct address_space *mapping = bdev->bd_inode->i_mapping;
> --- linux/include/linux/genhd.h~ 2012-02-20 18:35:02.777802107 -0500
> +++ linux/include/linux/genhd.h 2012-02-20 18:35:13.873762792 -0500
> @@ -596,6 +596,7 @@ extern char *disk_name (struct gendisk *
>
> extern int disk_expand_part_tbl(struct gendisk *disk, int target);
> extern int rescan_partitions(struct gendisk *disk, struct block_device
> *bdev);
> +extern int invalidate_partitions(struct gendisk *disk, struct block_device
> *bdev);
> extern struct hd_struct * __must_check add_partition(struct gendisk *disk,
> int partno, sector_t start,
> sector_t len, int flags,
> --- linux/fs/block_dev.c~ 2012-02-20 18:35:24.890723757 -0500
> +++ linux/fs/block_dev.c 2012-02-20 18:36:25.166510197 -0500
> @@ -1159,8 +1159,12 @@ static int __blkdev_get(struct block_dev
> * The latter is necessary to prevent ghost
> * partitions on a removed medium.
> */
> - if (bdev->bd_invalidated && (!ret || ret == -ENOMEDIUM))
> - rescan_partitions(disk, bdev);
> + if (bdev->bd_invalidated) {
> + if (!ret)
> + rescan_partitions(disk, bdev);
> + else if (ret == -ENOMEDIUM)
> + invalidate_partitions(disk, bdev);
> + }
> if (ret)
> goto out_clear;
> } else {
> @@ -1190,8 +1194,12 @@ static int __blkdev_get(struct block_dev
> if (bdev->bd_disk->fops->open)
> ret = bdev->bd_disk->fops->open(bdev, mode);
> /* the same as first opener case, read comment there */
> - if (bdev->bd_invalidated && (!ret || ret == -ENOMEDIUM))
> - rescan_partitions(bdev->bd_disk, bdev);
> + if (bdev->bd_invalidated) {
> + if (!ret)
> + rescan_partitions(bdev->bd_disk, bdev);
> + else if (ret == -ENOMEDIUM)
> + invalidate_partitions(bdev->bd_disk, bdev);
> + }
> if (ret)
> goto out_unlock_bdev;
> }
>
prev parent reply other threads:[~2012-02-29 18:47 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-02-22 1:01 Jun'ichi Nomura
2012-02-22 1:04 ` Tejun Heo
2012-02-22 4:58 ` Jack Wang
2012-02-22 5:36 ` 'Dave Jones'
2012-02-29 12:57 ` Naveen Goswamy
2012-02-29 18:46 ` Naveen Goswamy [this message]
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=1330541203.4f4e7293d1477@www.imp.polymtl.ca \
--to=naveen.goswamy@polymtl.ca \
--cc=James.Bottomley@HansenPartnership.com \
--cc=axboe@kernel.dk \
--cc=davej@redhat.com \
--cc=huajun.li.lee@gmail.com \
--cc=j-nomura@ce.jp.nec.com \
--cc=jack_wang@usish.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=sgruszka@redhat.com \
--cc=stefanr@s5r6.in-berlin.de \
--cc=tj@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
Powered by JetHome