* [PATCH gmem FIXUP] KVM: Don't re-use inodes when creating guest_memfd files
@ 2023-10-02 13:32 Michael Roth
2023-10-06 2:20 ` Sean Christopherson
0 siblings, 1 reply; 2+ messages in thread
From: Michael Roth @ 2023-10-02 13:32 UTC (permalink / raw)
To: kvm; +Cc: linux-kernel, seanjc, Paolo Bonzini
anon_inode_getfile() uses a singleton inode, which results in the inode
size changing based with each new KVM_CREATE_GUEST_MEMFD call, which
can later lead to previously-created guest_memfd files failing bounds
checks that are later performed when memslots are bound to them. More
generally, the inode may be associated with other state that cannot be
shared across multiple guest_memfd instances.
Revert back to having 1 inode per guest_memfd instance by using the
"secure" variant of anon_inode_getfile().
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Sean Christopherson <seanjc@google.com>
Fixes: 0f7e60a5f42a ("kvm: guestmem: do not use a file system")
Signed-off-by: Michael Roth <michael.roth@amd.com>
---
fs/anon_inodes.c | 1 +
virt/kvm/guest_memfd.c | 4 ++--
2 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/fs/anon_inodes.c b/fs/anon_inodes.c
index 24192a7667ed..4190336180ee 100644
--- a/fs/anon_inodes.c
+++ b/fs/anon_inodes.c
@@ -176,6 +176,7 @@ struct file *anon_inode_getfile_secure(const char *name,
return __anon_inode_getfile(name, fops, priv, flags,
context_inode, true);
}
+EXPORT_SYMBOL_GPL(anon_inode_getfile_secure);
static int __anon_inode_getfd(const char *name,
const struct file_operations *fops,
diff --git a/virt/kvm/guest_memfd.c b/virt/kvm/guest_memfd.c
index 78928ebd1bff..4d74b66cfbf7 100644
--- a/virt/kvm/guest_memfd.c
+++ b/virt/kvm/guest_memfd.c
@@ -378,8 +378,8 @@ static int __kvm_gmem_create(struct kvm *kvm, loff_t size, u64 flags)
goto err_fd;
}
- file = anon_inode_getfile(anon_name, &kvm_gmem_fops, gmem,
- O_RDWR);
+ file = anon_inode_getfile_secure(anon_name, &kvm_gmem_fops, gmem,
+ O_RDWR, NULL);
if (IS_ERR(file)) {
err = PTR_ERR(file);
goto err_gmem;
--
2.25.1
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH gmem FIXUP] KVM: Don't re-use inodes when creating guest_memfd files
2023-10-02 13:32 [PATCH gmem FIXUP] KVM: Don't re-use inodes when creating guest_memfd files Michael Roth
@ 2023-10-06 2:20 ` Sean Christopherson
0 siblings, 0 replies; 2+ messages in thread
From: Sean Christopherson @ 2023-10-06 2:20 UTC (permalink / raw)
To: Sean Christopherson, kvm, Michael Roth; +Cc: linux-kernel, Paolo Bonzini
On Mon, 02 Oct 2023 08:32:30 -0500, Michael Roth wrote:
> anon_inode_getfile() uses a singleton inode, which results in the inode
> size changing based with each new KVM_CREATE_GUEST_MEMFD call, which
> can later lead to previously-created guest_memfd files failing bounds
> checks that are later performed when memslots are bound to them. More
> generally, the inode may be associated with other state that cannot be
> shared across multiple guest_memfd instances.
>
> [...]
Applied to kvm-x86 guest_memfd, thanks! I added a comment to explain the use
of the "secure" API, there's a non-zero chance we'll forget that wrinkle again
in the future.
[1/1] KVM: Don't re-use inodes when creating guest_memfd files
https://github.com/kvm-x86/linux/commit/b3bf68b66062
--
https://github.com/kvm-x86/linux/tree/next
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-10-06 2:21 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-02 13:32 [PATCH gmem FIXUP] KVM: Don't re-use inodes when creating guest_memfd files Michael Roth
2023-10-06 2:20 ` Sean Christopherson
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®