All of lore.kernel.org
 help / color / mirror / Atom feed
From: Pavel Roskin <proski@gnu.org>
To: The development of GRUB 2 <grub-devel@gnu.org>
Subject: Re: [PATCH]: grub: Fix ofdisk disk cache corruption.
Date: Sun, 12 Apr 2009 02:29:15 -0400	[thread overview]
Message-ID: <1239517755.3887.24.camel@mj> (raw)
In-Reply-To: <20090411.010833.154152360.davem@davemloft.net>

On Sat, 2009-04-11 at 01:08 -0700, David Miller wrote:
> The ieee1275 ofdisk driver doesn't use a unique value for
> disk->id so it's really easy to get disk corruption.  I was
> able to see such corruption by simply booting grub from one
> disk and booting a Linux kernel from another, both of which
> were on the same disk controller.

I hope you mean disk cache corruption, as in the subject, not disk
corruption.  GRUB only writes to disks to save environment variables,
and it's done very carefully.  

> +#define OFDISK_HASH_SZ	8
> +static struct ofdisk_hash_ent *ofdisk_hash[OFDISK_HASH_SZ];
> +
> +static int
> +ofdisk_hash_fn (const char *devpath)
> +{
> +  int hash = 0;
> +  while (*devpath)
> +    hash ^= *devpath++;
> +  return (hash & (OFDISK_HASH_SZ - 1));
> +}

That's a 3 bit hash.  The risk of collisions is very high.  I would
understand if you had 8 entries for the hash values, but the hash values
themselves should be reasonably unique.

> +static struct ofdisk_hash_ent *
> +ofdisk_hash_add (char *devpath)
> +{
> +  struct ofdisk_hash_ent **head = &ofdisk_hash[ofdisk_hash_fn(devpath)];
> +  struct ofdisk_hash_ent *p = grub_malloc(sizeof (*p));
> +
> +  if (p)
> +    {
> +      p->devpath = devpath;

If you can save the device names, then there is no point in using
hashes.  You can use (long)devpath.

> +  if (!op)
> +    op = ofdisk_hash_add (devpath);
>  
> -  grub_ieee1275_open (devpath, &dev_ihandle);
> +  grub_free (devpath);

But if you free the device names, then they are bad IDs.  The
probability of the same memory being reused for another name is high.

Perhaps I misunderstand something.

-- 
Regards,
Pavel Roskin



  reply	other threads:[~2009-04-12  6:29 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-04-11  8:08 [PATCH]: grub: Fix ofdisk disk cache corruption David Miller
2009-04-12  6:29 ` Pavel Roskin [this message]
2009-04-12  8:01   ` David Miller
2009-04-12 10:44     ` phcoder
2009-04-13  1:02       ` David Miller
2009-04-13  1:09         ` phcoder
2009-04-13  6:42           ` David Miller
2009-04-12 21:01     ` Pavel Roskin
2009-04-13  1:04       ` David Miller

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=1239517755.3887.24.camel@mj \
    --to=proski@gnu.org \
    --cc=grub-devel@gnu.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 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.