linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* question about blkio_get_stat()
@ 2012-04-02 13:54 Dan Carpenter
  2012-04-07  8:28 ` Jan Kara
  0 siblings, 1 reply; 2+ messages in thread
From: Dan Carpenter @ 2012-04-02 13:54 UTC (permalink / raw)
  To: Divyesh Shah; +Cc: Jens Axboe, linux-kernel

Hi Divyesh,

Smatch complains that we go outside the array in blkio_get_stat().

block/blk-cgroup.c
   731          if (type == BLKIO_STAT_DEQUEUE)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^
BLKIO_STAT_DEQUEUE is 9.

   732                  return blkio_fill_stat(key_str, MAX_KEY_LEN - 1,
   733                                          blkg->stats.dequeue, cb, dev);
   734  #endif
   735  
   736          for (sub_type = BLKIO_STAT_READ; sub_type < BLKIO_STAT_TOTAL;
   737                          sub_type++) {
   738                  blkio_get_key_name(sub_type, dev, key_str, MAX_KEY_LEN, false);
   739                  cb->fill(cb, key_str, blkg->stats.stat_arr[type][sub_type]);
                                                    ^^^^^^^^^^^^^^^^^^^^
This array only has 4 elements and if "type" is 9 we're past the end of
array.

   740          }

It's odd that Smatch only started complaining about this now, but this
code has been there for years.  I'm puzzled by what changed.  Sorry if
there is something obvious I have missed.

regards,
dan carpenter

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

* Re: question about blkio_get_stat()
  2012-04-02 13:54 question about blkio_get_stat() Dan Carpenter
@ 2012-04-07  8:28 ` Jan Kara
  0 siblings, 0 replies; 2+ messages in thread
From: Jan Kara @ 2012-04-07  8:28 UTC (permalink / raw)
  To: Dan Carpenter; +Cc: Divyesh Shah, Jens Axboe, linux-kernel

  Hi,

On Mon 02-04-12 16:54:56, Dan Carpenter wrote:
> Smatch complains that we go outside the array in blkio_get_stat().
> 
> block/blk-cgroup.c
>    731          if (type == BLKIO_STAT_DEQUEUE)
>                     ^^^^^^^^^^^^^^^^^^^^^^^^^^
> BLKIO_STAT_DEQUEUE is 9.
> 
>    732                  return blkio_fill_stat(key_str, MAX_KEY_LEN - 1,
>    733                                          blkg->stats.dequeue, cb, dev);
>    734  #endif
>    735  
>    736          for (sub_type = BLKIO_STAT_READ; sub_type < BLKIO_STAT_TOTAL;
>    737                          sub_type++) {
>    738                  blkio_get_key_name(sub_type, dev, key_str, MAX_KEY_LEN, false);
>    739                  cb->fill(cb, key_str, blkg->stats.stat_arr[type][sub_type]);
>                                                     ^^^^^^^^^^^^^^^^^^^^
> This array only has 4 elements and if "type" is 9 we're past the end of
> array.
> 
>    740          }
> 
> It's odd that Smatch only started complaining about this now, but this
> code has been there for years.  I'm puzzled by what changed.  Sorry if
> there is something obvious I have missed.
  It seems that BLKIO_STAT_... values larger than BLK_IO_STAT_QUEUE are
defined only if CONFIG_DEBUG_BLK_CGROUP is defined. And in that case they
are also handled by blkio_get_stat() in a special way so we never get to
computing blkg->stats.stat_arr[type][sub_type]. So everything seems fine.

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

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

end of thread, other threads:[~2012-04-10 15:09 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-04-02 13:54 question about blkio_get_stat() Dan Carpenter
2012-04-07  8:28 ` Jan Kara

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).