All of lore.kernel.org
 help / color / mirror / Atom feed
From: Keith Busch <kbusch@kernel.org>
To: Dan Carpenter <dan.carpenter@linaro.org>
Cc: linux-block@vger.kernel.org
Subject: Re: [bug report] block: bio-integrity: directly map user buffers
Date: Tue, 5 Dec 2023 09:29:39 -0700	[thread overview]
Message-ID: <ZW9P8w_Gp9IS8022@kbusch-mbp> (raw)
In-Reply-To: <1177558a-9dcd-432f-89b1-4ac9cbd9cd25@moroto.mountain>

On Tue, Dec 05, 2023 at 12:35:30PM +0300, Dan Carpenter wrote:
> Hello Keith Busch,
> 
> The patch 492c5d455969: "block: bio-integrity: directly map user
> buffers" from Nov 30, 2023 (linux-next), leads to the following
> Smatch static checker warning:
> 
> 	block/bio-integrity.c:350 bio_integrity_map_user()
> 	error: uninitialized symbol 'offset'.
> 
> block/bio-integrity.c
>     340                 if (!bvec)
>     341                         return -ENOMEM;
>     342                 pages = NULL;
>     343         }
>     344 
>     345         copy = !iov_iter_is_aligned(&iter, align, align);
>     346         ret = iov_iter_extract_pages(&iter, &pages, bytes, nr_vecs, 0, &offset);
> 
> Smatch is concerned about the first "return 0;" if bytes or iter.count
> is zero.  In that situation then offset is uninitialized.
>
>     347         if (unlikely(ret < 0))
>     348                 goto free_bvec;
>     349 
> --> 350         nr_bvecs = bvec_from_pages(bvec, pages, nr_vecs, bytes, offset);
>                                                                         ^^^^^^

Thanks for the report! I don't think there's any scenario where someone
would purposefully request a 0 length metadata mapping, so I'll have it
return EINVAL for that condition.

But ... bvec_from_pages() only reads 'offset' if nr_vecs > 0. nr_vecs
would have to be 0 in this case, so it's not really accessing an
uninitialized variable. Everything in fact appears to "work" if you do
request 0 length, though again, I don't think there's a legit reason to
ever do that.

  reply	other threads:[~2023-12-05 16:29 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-05  9:35 [bug report] block: bio-integrity: directly map user buffers Dan Carpenter
2023-12-05 16:29 ` Keith Busch [this message]
2023-12-06  5:26   ` Dan Carpenter

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=ZW9P8w_Gp9IS8022@kbusch-mbp \
    --to=kbusch@kernel.org \
    --cc=dan.carpenter@linaro.org \
    --cc=linux-block@vger.kernel.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 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.