public inbox for linux-scsi@vger.kernel.org
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@osdl.org>
To: Nagendra Singh Tomar <nagendra_tomar@adaptec.com>
Cc: linux-kernel@vger.kernel.org, linux-scsi@vger.kernel.org,
	Greg KH <greg@kroah.com>,
	James Bottomley <James.Bottomley@steeleye.com>
Subject: Re: [PATCH 2.6.19.2] SCSI sd:  udev accessing an uninitialized scsi_disk results in a crash
Date: Fri, 2 Feb 2007 17:19:24 -0800	[thread overview]
Message-ID: <20070202171924.a225cff7.akpm@linux-foundation.org> (raw)
In-Reply-To: <200702021734.57161.nagendra_tomar@adaptec.com>

On Fri, 2 Feb 2007 17:34:56 +0530
Nagendra Singh Tomar <nagendra_tomar@adaptec.com> wrote:

> Hi,
> 	sd_probe() calls class_device_add() even before initializing the 
> sdkp->device variable. class_device_add() eventually results in the user mode 
> udev program to be called. udev program can read the the allow_restart 
> attribute of the newly created scsi device. This is resulting in a crash as 
> the show function for allow_restart (i.e sd_show_allow_restart) returns the 
> attribute value by reading the sdkp->device->allow_restart variable. As the 
> sdkp->device is not initialized before calling the user mode hotplug helper, 
> this results in a crash.
> 	The patch below solves it by calling class_device_add() only after the 
> necessary fields in the scsi_disk structure are initialized properly.
> 
> 
> 
> --- linux-2.6.19.2/drivers/scsi/sd.c.orig	2007-02-02 17:03:03.000000000 +0530
> +++ linux-2.6.19.2/drivers/scsi/sd.c	2007-02-02 17:04:04.000000000 +0530
> @@ -1646,16 +1646,6 @@ static int sd_probe(struct device *dev)
>  	if (error)
>  		goto out_put;
>  
> -	class_device_initialize(&sdkp->cdev);
> -	sdkp->cdev.dev = &sdp->sdev_gendev;
> -	sdkp->cdev.class = &sd_disk_class;
> -	strncpy(sdkp->cdev.class_id, sdp->sdev_gendev.bus_id, BUS_ID_SIZE);
> -
> -	if (class_device_add(&sdkp->cdev))
> -		goto out_put;
> -
> -	get_device(&sdp->sdev_gendev);
> -
>  	sdkp->device = sdp;
>  	sdkp->driver = &sd_template;
>  	sdkp->disk = gd;
> @@ -1669,6 +1659,16 @@ static int sd_probe(struct device *dev)
>  			sdp->timeout = SD_MOD_TIMEOUT;
>  	}
>  
> +	class_device_initialize(&sdkp->cdev);
> +	sdkp->cdev.dev = &sdp->sdev_gendev;
> +	sdkp->cdev.class = &sd_disk_class;
> +	strncpy(sdkp->cdev.class_id, sdp->sdev_gendev.bus_id, BUS_ID_SIZE);
> +
> +	if (class_device_add(&sdkp->cdev))
> +		goto out_put;
> +
> +	get_device(&sdp->sdev_gendev);
> +
>  	gd->major = sd_major((index & 0xf0) >> 4);
>  	gd->first_minor = ((index & 0xf) << 4) | (index & 0xfff00);
>  	gd->minors = 16;

Thanks - I'll queue this up for 2.6.20 also.

  reply	other threads:[~2007-02-03  1:19 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-02-02 12:04 [PATCH 2.6.19.2] SCSI sd: udev accessing an uninitialized scsi_disk results in a crash Nagendra Singh Tomar
2007-02-03  1:19 ` Andrew Morton [this message]
2007-02-03  1:56   ` Greg KH
2007-02-03  3:14     ` James Bottomley

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=20070202171924.a225cff7.akpm@linux-foundation.org \
    --to=akpm@osdl.org \
    --cc=James.Bottomley@steeleye.com \
    --cc=greg@kroah.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=nagendra_tomar@adaptec.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