From: Kees Cook <keescook@chromium.org>
To: Ananda Badmaev <a.badmaev@clicknet.pro>
Cc: Jonathan Corbet <corbet@lwn.net>,
linux-kernel@vger.kernel.org, Minchan Kim <minchan@kernel.org>,
Andrew Morton <akpm@linux-foundation.org>,
Sergey Senozhatsky <senozhatsky@chromium.org>,
linux-mm@kvack.org, linux-doc@vger.kernel.org,
Vitaly Wool <vitaly.wool@konsulko.com>,
"Gustavo A. R. Silva" <gustavo@embeddedor.com>,
linux-next@vger.kernel.org, linux-hardening@vger.kernel.org
Subject: Re: Coverity: zblock_alloc(): Memory - illegal accesses
Date: Fri, 18 Nov 2022 08:43:19 -0800 [thread overview]
Message-ID: <202211180841.39558B5E5@keescook> (raw)
In-Reply-To: <74337ebd-0222-2e78-9149-8fa40b0c815e@clicknet.pro>
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
next prev parent reply other threads:[~2022-11-18 16:43 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
2022-11-18 19:44 ` 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=202211180841.39558B5E5@keescook \
--to=keescook@chromium.org \
--cc=a.badmaev@clicknet.pro \
--cc=akpm@linux-foundation.org \
--cc=corbet@lwn.net \
--cc=gustavo@embeddedor.com \
--cc=linux-doc@vger.kernel.org \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-next@vger.kernel.org \
--cc=minchan@kernel.org \
--cc=senozhatsky@chromium.org \
--cc=vitaly.wool@konsulko.com \
/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 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.