From: Sean Christopherson <seanjc@google.com>
To: Ackerley Tng <ackerleytng@google.com>
Cc: sashiko-reviews@lists.linux.dev, kvm@vger.kernel.org
Subject: Re: [PATCH v3 3/3] KVM: selftests: Add guest_memfd regression test signed offset+size bug
Date: Tue, 2 Jun 2026 10:01:23 -0700 [thread overview]
Message-ID: <ah8MY3HwEQMYoQy9@google.com> (raw)
In-Reply-To: <CAEvNRgECjs5UqJsBjsgMc2JF8rRirCPAtB02dKxSgsTY0LAe6w@mail.gmail.com>
On Sat, May 30, 2026, Ackerley Tng wrote:
> sashiko-bot@kernel.org writes:
>
> >
> > [...snip...]
> >
> >> @@ -345,6 +345,16 @@ static void test_invalid_punch_hole(int fd, size_t total_size)
> >> }
> >> }
> >>
> >> +static void test_invalid_binding(struct kvm_vm *vm, int fd, size_t size)
> >> +{
> >> + int r;
> >> +
> >> + r = __vm_set_user_memory_region2(vm, 0, KVM_MEM_GUEST_MEMFD, 0, size, 0,
> >> + fd, 0x7ffffffffffff000ull);
> >
> > [Severity: Medium]
> > Is this hardcoded offset value correct?
> >
> > The literal 0x7ffffffffffff000ull contains 17 hex digits (68 bits), which
> > will be truncated to 64 bits (0xfffffffffffff000ull) by the compiler. Because
> > this truncated value is very close to the maximum 64-bit unsigned integer,
> > adding the size to it will wrap around zero.
> >
>
> Sashiko miscounted the number of hex digits, it's actually 16. That
> said, humans also have to count to understand what the test is
> doing... How about this, which I think highlights the signed overflow
> requirement on the selected offset?
>
> static void test_invalid_binding(struct kvm_vm *vm, int fd, size_t size)
> {
> + const u64 large_offset = align_down(INT64_MAX, getpagesize());
Eh, I don't see any need for a local variable and an extra assert. The size of
the gmem file _must_ be >= page_size, otherwise creation would fail due to lack
of alignment.
This can+should use ALIGN_DOWN(). Actually, why does align_down() even exists?
Ugh, because KVM selftests predate commit 10a04ff09bcc ("tools: move alignment-related
macros to new <linux/align.h>") by many years. I'll send a separate series to
drop align_{down,up}(), and hopefully align_ptr_up() as well (should need a cast
version since ALIGN() is a macro, i.e. doesn't do implicit type conversion).
v4 incoming...
prev parent reply other threads:[~2026-06-02 17:01 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-28 2:11 [PATCH v3 0/3] KVM: guest_memfd: Fix signed offset+size goof Sean Christopherson
2026-05-28 2:11 ` [PATCH v3 1/3] KVM: guest_memfd: Treat memslot binding offset+size as unsigned values Sean Christopherson
2026-05-28 3:00 ` sashiko-bot
2026-05-28 17:24 ` Ackerley Tng
2026-05-28 17:57 ` Sean Christopherson
2026-05-28 20:42 ` Ackerley Tng
2026-05-28 23:25 ` Michael Roth
2026-05-28 2:11 ` [PATCH v3 2/3] KVM: selftests: Expand the guest_memfd test macros to allow passing the VM Sean Christopherson
2026-05-30 23:18 ` Ackerley Tng
2026-05-28 2:11 ` [PATCH v3 3/3] KVM: selftests: Add guest_memfd regression test signed offset+size bug Sean Christopherson
2026-05-28 3:29 ` sashiko-bot
2026-05-30 23:17 ` Ackerley Tng
2026-06-02 17:01 ` Sean Christopherson [this message]
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=ah8MY3HwEQMYoQy9@google.com \
--to=seanjc@google.com \
--cc=ackerleytng@google.com \
--cc=kvm@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/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.