linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Matthew Wilcox <willy@infradead.org>
To: Dan Carpenter <error27@gmail.com>
Cc: a.badmaev@clicknet.pro, linux-mm@kvack.org
Subject: Re: [bug report] mm: add zblock - new allocator for use via zpool API
Date: Tue, 22 Nov 2022 03:29:30 +0000	[thread overview]
Message-ID: <Y3xCGiNNO0LTbP8s@casper.infradead.org> (raw)
In-Reply-To: <Y3d4kO0+8Tt9Iy7u@kili>

On Fri, Nov 18, 2022 at 03:20:32PM +0300, Dan Carpenter wrote:
> Hello Ananda,
> 
> The patch 9097e28c25c8: "mm: add zblock - new allocator for use via
> zpool API" from Nov 4, 2022, leads to the following Smatch static
> checker warning:
> 
> mm/zblock.c:341 zblock_alloc() error: buffer overflow 'block_desc' 29 <= 29 (assuming for loop doesn't break)
> mm/zblock.c:165 cache_insert_block() error: uninitialized symbol 'min_index'.
> mm/zblock.c:412 zblock_reclaim_block() warn: always true condition '(block_type >= 0) => (0-u64max >= 0)'
> 
> mm/zblock.c
>     297 static int zblock_alloc(struct zblock_pool *pool, size_t size, gfp_t gfp,
>     298                         unsigned long *handle)
>     299 {
>     300         unsigned int block_type, slot;
>     301         struct zblock_block *block;
>     302         struct block_list *list;
>     303 
>     304         if (!size)
>     305                 return -EINVAL;
>     306 
>     307         if (size > PAGE_SIZE)
>     308                 return -ENOSPC;
>     309 
>     310         /* find basic block type with suitable slot size */
>     311         for (block_type = 0; block_type < ARRAY_SIZE(block_desc); block_type++) {
>     312                 if (size <= block_desc[block_type].slot_size)
>     313                         break;
>     314         }
> 
> "size" is always <= PAGE_SIZE.  Is PAGE_SIZE always 4k?  If so then this
> code is fine.  Smatch is bad at handling arrays.

PAGE_SIZE is 8kB on SPARC/Alpha.  It can be 64kB on PPC and ARM.  It can
even be 256kB on one of the weirdo architectures (but, honestly, it's
OK if that breaks; it's not well-tested)..


  reply	other threads:[~2022-11-22  3:29 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-18 12:20 Dan Carpenter
2022-11-22  3:29 ` Matthew Wilcox [this message]
2022-11-22  4:33   ` Ananda Badmaev

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=Y3xCGiNNO0LTbP8s@casper.infradead.org \
    --to=willy@infradead.org \
    --cc=a.badmaev@clicknet.pro \
    --cc=error27@gmail.com \
    --cc=linux-mm@kvack.org \
    /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