]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
KVM: guest_memfd: Return -EEXIST for overlapping bindings
authorZongyao Chen <ZongYao.Chen@linux.alibaba.com>
Fri, 22 May 2026 17:21:49 +0000 (10:21 -0700)
committerSean Christopherson <seanjc@google.com>
Tue, 26 May 2026 19:23:36 +0000 (12:23 -0700)
commit7ea987a905855d89073d172556720c93f95de93f
tree3dfcb89cd5e26748b7fb8f51e3f654ede13f4d3d
parentb7fbe9a1bf9ee6c967ef77d366ca58c35fcf1887
KVM: guest_memfd: Return -EEXIST for overlapping bindings

KVM_SET_USER_MEMORY_REGION2 rejects guest_memfd ranges that overlap an
existing binding, but kvm_gmem_bind() currently reports the failure through
its generic -EINVAL path.  That makes binding conflicts indistinguishable
from malformed guest_memfd parameters.

Return -EEXIST when the target guest_memfd range is already bound, matching
the errno used for overlapping GPA memslots and making the two types of
range conflicts report the same class of error to userspace.

Note, returning -EINVAL was definitely not intentional, as guest_memfd
support was accompanied by a selftest to verify that attempting to create
overlapping bindings fails with -EEXIST.  Except the selftest was also
flawed in that it unintentionally overlapped memslot GPAs, and so failed
on KVM's common memslot checks before reaching guest_memfd.

Fixes: a7800aa80ea4 ("KVM: Add KVM_CREATE_GUEST_MEMFD ioctl() for guest-specific backing memory")
Signed-off-by: Zongyao Chen <ZongYao.Chen@linux.alibaba.com>
Reviewed-by: Ackerley Tng <ackerleytng@google.com>
Tested-by: Ackerley Tng <ackerleytng@google.com>
[sean: call out that the original intent was to return -EEXIST]
Link: https://patch.msgid.link/20260522172151.3530267-2-seanjc@google.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
virt/kvm/guest_memfd.c