From: "Alex Bennée" <alex.bennee@linaro.org>
To: Peter Maydell <peter.maydell@linaro.org>
Cc: qemu-devel@nongnu.org, "Paolo Bonzini" <pbonzini@redhat.com>,
"Marc-André Lureau" <marcandre.lureau@redhat.com>,
patches@linaro.org
Subject: Re: [Qemu-devel] [PATCH] memfd: Avoid Coverity warning about integer overflow
Date: Tue, 15 May 2018 20:27:49 +0100 [thread overview]
Message-ID: <87zi10en2i.fsf@linaro.org> (raw)
In-Reply-To: <20180515172729.24564-1-peter.maydell@linaro.org>
Peter Maydell <peter.maydell@linaro.org> writes:
> Coverity complains about qemu_memfd_create() (CID 1385858) because
> we calculate a bit position htsize which could be up to 63, but
> then use it in "1 << htsize" which is a 32-bit integer calculation
> and could push the 1 off the top of the value.
>
> Silence the complaint bu using "1ULL"; this isn't a bug in
> practice since a hugetlbsize of 4GB is not very plausible.
>
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
> ---
> util/memfd.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/util/memfd.c b/util/memfd.c
> index b3ecbac19e..d248a53c3c 100644
> --- a/util/memfd.c
> +++ b/util/memfd.c
> @@ -66,7 +66,7 @@ int qemu_memfd_create(const char *name, size_t size, bool hugetlb,
> {
> int htsize = hugetlbsize ? ctz64(hugetlbsize) : 0;
>
> - if (htsize && 1 << htsize != hugetlbsize) {
> + if (htsize && 1ULL << htsize != hugetlbsize) {
> error_setg(errp, "Hugepage size must be a power of 2");
> return -1;
> }
--
Alex Bennée
next prev parent reply other threads:[~2018-05-15 19:27 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-05-15 17:27 [Qemu-devel] [PATCH] memfd: Avoid Coverity warning about integer overflow Peter Maydell
2018-05-15 18:14 ` Marc-André Lureau
2018-05-15 19:27 ` Alex Bennée [this message]
2018-05-16 7:23 ` Paolo Bonzini
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=87zi10en2i.fsf@linaro.org \
--to=alex.bennee@linaro.org \
--cc=marcandre.lureau@redhat.com \
--cc=patches@linaro.org \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.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;
as well as URLs for NNTP newsgroup(s).