From: Andrew Morton <akpm@osdl.org>
To: James Cross <james_cross@symantec.com>
Cc: Jens Axboe <axboe@suse.de>,
Andries Brouwer <Andries.Brouwer@cwi.nl>,
linux-kernel@vger.kernel.org, Al Viro <viro@zeniv.linux.org.uk>,
Christoph Hellwig <hch@lst.de>
Subject: Re: [PATCH] fix /proc/partitions oops
Date: Thu, 7 Sep 2006 14:35:13 -0700 [thread overview]
Message-ID: <20060907143513.7024c15c.akpm@osdl.org> (raw)
In-Reply-To: <Pine.LNX.4.62.0609071703420.28780@boogie.wat.veritas.com>
On Thu, 7 Sep 2006 17:04:20 +0100 (BST)
James Cross <james_cross@symantec.com> wrote:
> If show_partition happens to race with re-reading a partition table
> (rescan_partitions), sgp->part[n] can become NULL just after it's been
> tested, and so cause an oops: read it once (and read nr_sects just the
> once too, to avoid a chance of showing 0).
>
OK.
>
> block/genhd.c | 12 ++++++++----
> 1 file changed, 8 insertions(+), 4 deletions(-)
>
> --- 2.6.18-rc6/block/genhd.c.orig 2006-09-07 12:14:32.183218000 +0100
> +++ 2.6.18-rc6/block/genhd.c 2006-09-07 12:15:16.134498000 +0100
> @@ -261,14 +261,18 @@ static int show_partition(struct seq_fil
> (unsigned long long)get_capacity(sgp) >> 1,
> disk_name(sgp, 0, buf));
> for (n = 0; n < sgp->minors - 1; n++) {
> - if (!sgp->part[n])
> + struct hd_struct *partn;
> + unsigned long long nr_sects;
> +
> + partn = sgp->part[n];
> + if (!partn)
> continue;
> - if (sgp->part[n]->nr_sects == 0)
> + nr_sects = partn->nr_sects;
> + if (nr_sects == 0)
> continue;
> seq_printf(part, "%4d %4d %10llu %s\n",
> sgp->major, n + 1 + sgp->first_minor,
> - (unsigned long long)sgp->part[n]->nr_sects >> 1 ,
> - disk_name(sgp, n + 1, buf));
> + nr_sects >> 1, disk_name(sgp, n + 1, buf));
> }
>
> return 0;
But that'll leave us reading possibly-freed memory.
I expect the correct way to fix this is with locking: the /proc/partitions
reading code needs to lock down the partition information while it's
reading it.
AFAICT the appropriate lock to take is the bdev->bd_mutex on the blockdev
which represents the "whole" disk. But I'm not sure whether that's
correct, nor what the official way is of hunting down that block_device*,
nor whether the code in do_open() is managing to take the correct lock.
Cc's hopefully added.
prev parent reply other threads:[~2006-09-07 21:35 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-09-07 16:04 James Cross
2006-09-07 21:35 ` Andrew Morton [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=20060907143513.7024c15c.akpm@osdl.org \
--to=akpm@osdl.org \
--cc=Andries.Brouwer@cwi.nl \
--cc=axboe@suse.de \
--cc=hch@lst.de \
--cc=james_cross@symantec.com \
--cc=linux-kernel@vger.kernel.org \
--cc=viro@zeniv.linux.org.uk \
/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
all inboxes | Powered by JetHome®