All of lore.kernel.org
 help / color / mirror / Atom feed
* [bug report] block: Move bdi_unregister() to del_gendisk()
@ 2017-03-07  0:13 Dan Carpenter
  2017-03-07 10:24 ` Dan Carpenter
  2017-03-07 10:44 ` Jan Kara
  0 siblings, 2 replies; 4+ messages in thread
From: Dan Carpenter @ 2017-03-07  0:13 UTC (permalink / raw)
  To: jack; +Cc: ceph-devel

Hello Jan Kara,

The patch 165a5e22fafb: "block: Move bdi_unregister() to
del_gendisk()" from Feb 8, 2017, leads to the following static
checker warning:

	drivers/block/rbd.c:4117 rbd_free_disk()
	warn: variable dereferenced before check 'disk->queue' (see line 4116)

drivers/block/rbd.c
  4107  static void rbd_free_disk(struct rbd_device *rbd_dev)
  4108  {
  4109          struct gendisk *disk = rbd_dev->disk;
  4110  
  4111          if (!disk)
  4112                  return;
  4113  
  4114          rbd_dev->disk = NULL;
  4115          if (disk->flags & GENHD_FL_UP) {
  4116                  del_gendisk(disk);
                        ^^^^^^^^^^^^^^^^^
The patch introduces a new dereference inside this function call.

  4117                  if (disk->queue)
                            ^^^^^^^^^^^
Check is too late.

  4118                          blk_cleanup_queue(disk->queue);
  4119                  blk_mq_free_tag_set(&rbd_dev->tag_set);
  4120          }
  4121          put_disk(disk);
  4122  }

regards,
dan carpenter

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [bug report] block: Move bdi_unregister() to del_gendisk()
  2017-03-07  0:13 [bug report] block: Move bdi_unregister() to del_gendisk() Dan Carpenter
@ 2017-03-07 10:24 ` Dan Carpenter
  2017-03-07 10:54   ` Jan Kara
  2017-03-07 10:44 ` Jan Kara
  1 sibling, 1 reply; 4+ messages in thread
From: Dan Carpenter @ 2017-03-07 10:24 UTC (permalink / raw)
  To: jack; +Cc: ceph-devel

Also:

    arch/powerpc/sysdev/axonram.c:277 axon_ram_probe()
    error: we previously assumed 'bank->disk->queue' could be null (see line 231)

regards,
dan carpenter

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [bug report] block: Move bdi_unregister() to del_gendisk()
  2017-03-07  0:13 [bug report] block: Move bdi_unregister() to del_gendisk() Dan Carpenter
  2017-03-07 10:24 ` Dan Carpenter
@ 2017-03-07 10:44 ` Jan Kara
  1 sibling, 0 replies; 4+ messages in thread
From: Jan Kara @ 2017-03-07 10:44 UTC (permalink / raw)
  To: Dan Carpenter; +Cc: jack, ceph-devel

Hi,

thanks for report! So don't see a way how rbd could pass gendisk with NULL
disk->queue to del_gendisk(). Also blk_unregister_queue() just after the
dereference I've added does WARN_ON(!disk->queue) so we would know about
such case if it could happen for whatever caller of del_gendisk(). However
for future safety, I could add a check for disk->queue being non-NULL to
del_gendisk().

								Honza

On Tue 07-03-17 03:13:22, Dan Carpenter wrote:
> Hello Jan Kara,
> 
> The patch 165a5e22fafb: "block: Move bdi_unregister() to
> del_gendisk()" from Feb 8, 2017, leads to the following static
> checker warning:
> 
> 	drivers/block/rbd.c:4117 rbd_free_disk()
> 	warn: variable dereferenced before check 'disk->queue' (see line 4116)
> 
> drivers/block/rbd.c
>   4107  static void rbd_free_disk(struct rbd_device *rbd_dev)
>   4108  {
>   4109          struct gendisk *disk = rbd_dev->disk;
>   4110  
>   4111          if (!disk)
>   4112                  return;
>   4113  
>   4114          rbd_dev->disk = NULL;
>   4115          if (disk->flags & GENHD_FL_UP) {
>   4116                  del_gendisk(disk);
>                         ^^^^^^^^^^^^^^^^^
> The patch introduces a new dereference inside this function call.
> 
>   4117                  if (disk->queue)
>                             ^^^^^^^^^^^
> Check is too late.
> 
>   4118                          blk_cleanup_queue(disk->queue);
>   4119                  blk_mq_free_tag_set(&rbd_dev->tag_set);
>   4120          }
>   4121          put_disk(disk);
>   4122  }
> 
> regards,
> dan carpenter
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [bug report] block: Move bdi_unregister() to del_gendisk()
  2017-03-07 10:24 ` Dan Carpenter
@ 2017-03-07 10:54   ` Jan Kara
  0 siblings, 0 replies; 4+ messages in thread
From: Jan Kara @ 2017-03-07 10:54 UTC (permalink / raw)
  To: Dan Carpenter; +Cc: jack, ceph-devel

On Tue 07-03-17 13:24:55, Dan Carpenter wrote:
> Also:
> 
>     arch/powerpc/sysdev/axonram.c:277 axon_ram_probe()
>     error: we previously assumed 'bank->disk->queue' could be null (see line 231)

So this is real however the error path of axon_ram_probe() looks hosed. You
are not supposed to call del_gendisk() if you did not call
device_add_disk() before and axon_ram_probe() leaks the gendisk structure
because it forgets to call put_disk(). I'll look into fixing this.

								Honza
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2017-03-07 14:43 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-03-07  0:13 [bug report] block: Move bdi_unregister() to del_gendisk() Dan Carpenter
2017-03-07 10:24 ` Dan Carpenter
2017-03-07 10:54   ` Jan Kara
2017-03-07 10:44 ` Jan Kara

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.