linux-next.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Coverity: zblock_alloc(): Memory - illegal accesses
@ 2022-11-17 22:20 coverity-bot
  2022-11-18 13:05 ` Ananda Badmaev
  0 siblings, 1 reply; 4+ messages in thread
From: coverity-bot @ 2022-11-17 22:20 UTC (permalink / raw)
  To: Ananda
  Cc: Jonathan Corbet, linux-kernel, Minchan Kim, Ananda Badmaev,
	Andrew Morton, Sergey Senozhatsky, linux-mm, linux-doc,
	Vitaly Wool, Gustavo A. R. Silva, linux-next, linux-hardening

Hello!

This is an experimental semi-automated report about issues detected by
Coverity from a scan of next-20221117 as part of the linux-next scan project:
https://scan.coverity.com/projects/linux-next-weekly-scan

You're getting this email because you were associated with the identified
lines of code (noted below) that were touched by commits:

  Wed Nov 16 16:19:12 2022 -0800
    9097e28c25c8 ("mm: add zblock - new allocator for use via zpool API")

Coverity reported the following:

*** CID 1527352:  Memory - illegal accesses  (OVERRUN)
mm/zblock.c:320 in zblock_alloc()
314     	}
315     	list = &(pool->block_lists[block_type]);
316
317     check:
318     	spin_lock(&list->lock);
319     	/* check if there are free slots in cache */
vvv     CID 1527352:  Memory - illegal accesses  (OVERRUN)
vvv     Overrunning array of 10208 bytes at byte offset 10208 by dereferencing pointer "list".
320     	block = cache_find_block(list);
321     	if (block)
322     		goto found;
323     	spin_unlock(&list->lock);
324
325     	/* not found block with free slots try to allocate new empty block */

If this is a false positive, please let us know so we can mark it as
such, or teach the Coverity rules to be smarter. If not, please make
sure fixes get into linux-next. :) For patches fixing this, please
include these lines (but double-check the "Fixes" first):

Reported-by: coverity-bot <keescook+coverity-bot@chromium.org>
Addresses-Coverity-ID: 1527352 ("Memory - illegal accesses")
Fixes: 9097e28c25c8 ("mm: add zblock - new allocator for use via zpool API")

It looks like block_type is not checked to be < ARRAY_SIZE(block_desc)
after exiting the earlier loop, so the access through "list" may be past
the end of pool->block_lists.

Thanks for your attention!

-- 
Coverity-bot

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

* Re: Coverity: zblock_alloc(): Memory - illegal accesses
  2022-11-17 22:20 Coverity: zblock_alloc(): Memory - illegal accesses coverity-bot
@ 2022-11-18 13:05 ` Ananda Badmaev
  2022-11-18 16:43   ` Kees Cook
  0 siblings, 1 reply; 4+ messages in thread
From: Ananda Badmaev @ 2022-11-18 13:05 UTC (permalink / raw)
  To: coverity-bot
  Cc: Jonathan Corbet, linux-kernel, Minchan Kim, Andrew Morton,
	Sergey Senozhatsky, linux-mm, linux-doc, Vitaly Wool,
	Gustavo A. R. Silva, linux-next, linux-hardening

18.11.2022 01:20, coverity-bot пишет:
> Coverity reported the following:
> 
> *** CID 1527352:  Memory - illegal accesses  (OVERRUN)
> mm/zblock.c:320 in zblock_alloc()
> 314     	}
> 315     	list = &(pool->block_lists[block_type]);
> 316
> 317     check:
> 318     	spin_lock(&list->lock);
> 319     	/* check if there are free slots in cache */
> vvv     CID 1527352:  Memory - illegal accesses  (OVERRUN)
> vvv     Overrunning array of 10208 bytes at byte offset 10208 by dereferencing pointer "list".
> 320     	block = cache_find_block(list);
> 321     	if (block)
> 322     		goto found;
> 323     	spin_unlock(&list->lock);
> 324
> 325     	/* not found block with free slots try to allocate new empty block */
> 
> If this is a false positive, please let us know so we can mark it as
> such, or teach the Coverity rules to be smarter. If not, please make
> sure fixes get into linux-next. :) For patches fixing this, please
> include these lines (but double-check the "Fixes" first):
> 
> Reported-by: coverity-bot <keescook+coverity-bot@chromium.org>
> Addresses-Coverity-ID: 1527352 ("Memory - illegal accesses")
> Fixes: 9097e28c25c8 ("mm: add zblock - new allocator for use via zpool API")
> 
> It looks like block_type is not checked to be < ARRAY_SIZE(block_desc)
> after exiting the earlier loop, so the access through "list" may be past
> the end of pool->block_lists.
>

There is no need for this check because it is guaranteed that this code 
will be executed only if size <= PAGE_SIZE. Since slot_size for the last 
list even exceeds PAGE_SIZE, block_type will be always valid.





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

* Re: Coverity: zblock_alloc(): Memory - illegal accesses
  2022-11-18 13:05 ` Ananda Badmaev
@ 2022-11-18 16:43   ` Kees Cook
  2022-11-18 19:44     ` Ananda Badmaev
  0 siblings, 1 reply; 4+ messages in thread
From: Kees Cook @ 2022-11-18 16:43 UTC (permalink / raw)
  To: Ananda Badmaev
  Cc: Jonathan Corbet, linux-kernel, Minchan Kim, Andrew Morton,
	Sergey Senozhatsky, linux-mm, linux-doc, Vitaly Wool,
	Gustavo A. R. Silva, linux-next, linux-hardening

On Fri, Nov 18, 2022 at 04:05:36PM +0300, Ananda Badmaev wrote:
> 18.11.2022 01:20, coverity-bot пишет:
> > Coverity reported the following:
> > 
> > *** CID 1527352:  Memory - illegal accesses  (OVERRUN)
> > mm/zblock.c:320 in zblock_alloc()
> > 314     	}
> > 315     	list = &(pool->block_lists[block_type]);
> > 316
> > 317     check:
> > 318     	spin_lock(&list->lock);
> > 319     	/* check if there are free slots in cache */
> > vvv     CID 1527352:  Memory - illegal accesses  (OVERRUN)
> > vvv     Overrunning array of 10208 bytes at byte offset 10208 by dereferencing pointer "list".
> > 320     	block = cache_find_block(list);
> > 321     	if (block)
> > 322     		goto found;
> > 323     	spin_unlock(&list->lock);
> > 324
> > 325     	/* not found block with free slots try to allocate new empty block */
> > 
> > If this is a false positive, please let us know so we can mark it as
> > such, or teach the Coverity rules to be smarter. If not, please make
> > sure fixes get into linux-next. :) For patches fixing this, please
> > include these lines (but double-check the "Fixes" first):
> > 
> > Reported-by: coverity-bot <keescook+coverity-bot@chromium.org>
> > Addresses-Coverity-ID: 1527352 ("Memory - illegal accesses")
> > Fixes: 9097e28c25c8 ("mm: add zblock - new allocator for use via zpool API")
> > 
> > It looks like block_type is not checked to be < ARRAY_SIZE(block_desc)
> > after exiting the earlier loop, so the access through "list" may be past
> > the end of pool->block_lists.
> > 
> 
> There is no need for this check because it is guaranteed that this code will
> be executed only if size <= PAGE_SIZE. Since slot_size for the last list
> even exceeds PAGE_SIZE, block_type will be always valid.

Ah-ha, understood. Well, if you do want to catch it if there is ever a
typo in the block_desc values (which are not obviously >4096 without
sitting down and calculating them), perhaps add:

        if (WARN_ON(block_type >= ARRAY_SIZE(block_desc))
                return -ENOSPC;


-- 
Kees Cook

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

* Re: Coverity: zblock_alloc(): Memory - illegal accesses
  2022-11-18 16:43   ` Kees Cook
@ 2022-11-18 19:44     ` Ananda Badmaev
  0 siblings, 0 replies; 4+ messages in thread
From: Ananda Badmaev @ 2022-11-18 19:44 UTC (permalink / raw)
  To: Kees Cook
  Cc: Jonathan Corbet, linux-kernel, Minchan Kim, Andrew Morton,
	Sergey Senozhatsky, linux-mm, linux-doc, Vitaly Wool,
	Gustavo A. R. Silva, linux-next, linux-hardening

18.11.2022 19:43, Kees Cook пишет:
> Ah-ha, understood. Well, if you do want to catch it if there is ever a
> typo in the block_desc values (which are not obviously >4096 without
> sitting down and calculating them), perhaps add:
> 
>          if (WARN_ON(block_type >= ARRAY_SIZE(block_desc))
>                  return -ENOSPC;
> 
> 

Probably it would be better to add a single check on the largest 
slot_size >= PAGE_SIZE at pool creation time.


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

end of thread, other threads:[~2022-11-18 19:44 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-17 22:20 Coverity: zblock_alloc(): Memory - illegal accesses coverity-bot
2022-11-18 13:05 ` Ananda Badmaev
2022-11-18 16:43   ` Kees Cook
2022-11-18 19:44     ` Ananda Badmaev

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).