lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Date:   Fri, 15 Oct 2021 11:43:17 -0700
From:   Luis Chamberlain <mcgrof@...nel.org>
To:     Finn Thain <fthain@...ux-m68k.org>
Cc:     axboe@...nel.dk, hch@....de, efremov@...ux.com, song@...nel.org,
        jejb@...ux.ibm.com, martin.petersen@...cle.com,
        viro@...iv.linux.org.uk, hare@...e.de, jack@...e.cz,
        ming.lei@...hat.com, tj@...nel.org, linux-raid@...r.kernel.org,
        linux-scsi@...r.kernel.org, linux-fsdevel@...r.kernel.org,
        linux-block@...r.kernel.org, linux-kernel@...r.kernel.org,
        Tetsuo Handa <penguin-kernel@...ove.sakura.ne.jp>
Subject: Re: [PATCH v2 1/2] block: make __register_blkdev() return an error

On Tue, Sep 28, 2021 at 10:57:18AM +1000, Finn Thain wrote:
> On Mon, 27 Sep 2021, Luis Chamberlain wrote:
> 
> > diff --git a/drivers/block/ataflop.c b/drivers/block/ataflop.c
> > index 5dc9b3d32415..be0627345b21 100644
> > --- a/drivers/block/ataflop.c
> > +++ b/drivers/block/ataflop.c
> > @@ -1989,24 +1989,34 @@ static int ataflop_alloc_disk(unsigned int drive, unsigned int type)
> >  
> >  static DEFINE_MUTEX(ataflop_probe_lock);
> >  
> > -static void ataflop_probe(dev_t dev)
> > +static int ataflop_probe(dev_t dev)
> >  {
> >  	int drive = MINOR(dev) & 3;
> >  	int type  = MINOR(dev) >> 2;
> > +	int err = 0;
> >  
> >  	if (type)
> >  		type--;
> >  
> > -	if (drive >= FD_MAX_UNITS || type >= NUM_DISK_MINORS)
> > -		return;
> > +	if (drive >= FD_MAX_UNITS || type >= NUM_DISK_MINORS) {
> > +		err = -EINVAL;
> > +		goto out;
> > +	}
> > +
> >  	mutex_lock(&ataflop_probe_lock);
> >  	if (!unit[drive].disk[type]) {
> > -		if (ataflop_alloc_disk(drive, type) == 0) {
> > -			add_disk(unit[drive].disk[type]);
> > +		err = ataflop_alloc_disk(drive, type);
> > +		if (err == 0) {
> > +			err = add_disk(unit[drive].disk[type]);
> > +			if (err)
> > +				blk_cleanup_disk(unit[drive].disk[type]);
> >  			unit[drive].registered[type] = true;
> >  		}
> >  	}
> >  	mutex_unlock(&ataflop_probe_lock);
> > +
> > +out:
> > +	return err;
> >  }
> >  
> >  static void atari_cleanup_floppy_disk(struct atari_floppy_struct *fs)
> 
> I think the change to ataflop_probe() would be more clear without adding 
> an 'out' label, like your change to floppy.c:

Good point! Fixed.

> > diff --git a/drivers/block/floppy.c b/drivers/block/floppy.c
> > index 0434f28742e7..95a1c8ef62f7 100644
> > --- a/drivers/block/floppy.c
> > +++ b/drivers/block/floppy.c
> > @@ -4517,21 +4517,27 @@ static int floppy_alloc_disk(unsigned int drive, unsigned int type)
> >  
> >  static DEFINE_MUTEX(floppy_probe_lock);
> >  
> > -static void floppy_probe(dev_t dev)
> > +static int floppy_probe(dev_t dev)
> >  {
> >  	unsigned int drive = (MINOR(dev) & 3) | ((MINOR(dev) & 0x80) >> 5);
> >  	unsigned int type = (MINOR(dev) >> 2) & 0x1f;
> > +	int err = 0;
> >  
> >  	if (drive >= N_DRIVE || !floppy_available(drive) ||
> >  	    type >= ARRAY_SIZE(floppy_type))
> > -		return;
> > +		return -EINVAL;
> >  
> >  	mutex_lock(&floppy_probe_lock);
> >  	if (!disks[drive][type]) {
> > -		if (floppy_alloc_disk(drive, type) == 0)
> > -			add_disk(disks[drive][type]);
> > +		if (floppy_alloc_disk(drive, type) == 0) {
> > +			err = add_disk(disks[drive][type]);
> > +			if (err)
> > +				blk_cleanup_disk(disks[drive][type]);
> > +		}
> >  	}
> >  	mutex_unlock(&floppy_probe_lock);
> > +
> > +	return err;
> >  }
> >  
> >  static int __init do_floppy_init(void)
> 
> In floppy_probe(), I think you should return the potential error result 
> from floppy_alloc_disk(), like you did in ataflop.c.

Indeed, thanks, fixed.

  Luis

Powered by blists - more mailing lists