summaryrefslogtreecommitdiffstats
path: root/virt
diff options
context:
space:
mode:
authorOliver Upton <oupton@google.com>2022-07-20 09:22:50 +0000
committerPaolo Bonzini <pbonzini@redhat.com>2022-08-10 15:08:28 -0400
commit59f82aad5940ffd0fedfe07ff755168722193d56 (patch)
tree860c5b87f50397ee11a48dc9218cee342bd8b493 /virt
parent20020f4cf2f92115c34b7bbaea02fcc810709a7e (diff)
downloadlinux-stable-59f82aad5940ffd0fedfe07ff755168722193d56.tar.gz
linux-stable-59f82aad5940ffd0fedfe07ff755168722193d56.tar.bz2
linux-stable-59f82aad5940ffd0fedfe07ff755168722193d56.zip
KVM: Pass the name of the VM fd to kvm_create_vm_debugfs()
At the time the VM fd is used in kvm_create_vm_debugfs(), the fd has been allocated but not yet installed. It is only really useful as an identifier in strings for the VM (such as debugfs). Treat it exactly as such by passing the string name of the fd to kvm_create_vm_debugfs(), futureproofing against possible misuse of the VM fd. Suggested-by: Sean Christopherson <seanjc@google.com> Signed-off-by: Oliver Upton <oupton@google.com> Message-Id: <20220720092259.3491733-5-oliver.upton@linux.dev> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'virt')
-rw-r--r--virt/kvm/kvm_main.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index eeb084a9cb70..8e08f66ddbd4 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -1021,7 +1021,7 @@ static void kvm_destroy_vm_debugfs(struct kvm *kvm)
}
}
-static int kvm_create_vm_debugfs(struct kvm *kvm, int fd)
+static int kvm_create_vm_debugfs(struct kvm *kvm, const char *fdname)
{
static DEFINE_MUTEX(kvm_debugfs_lock);
struct dentry *dent;
@@ -1035,7 +1035,7 @@ static int kvm_create_vm_debugfs(struct kvm *kvm, int fd)
if (!debugfs_initialized())
return 0;
- snprintf(dir_name, sizeof(dir_name), "%d-%d", task_pid_nr(current), fd);
+ snprintf(dir_name, sizeof(dir_name), "%d-%s", task_pid_nr(current), fdname);
mutex_lock(&kvm_debugfs_lock);
dent = debugfs_lookup(dir_name, kvm_debugfs_dir);
if (dent) {
@@ -4889,6 +4889,7 @@ EXPORT_SYMBOL_GPL(file_is_kvm);
static int kvm_dev_ioctl_create_vm(unsigned long type)
{
+ char fdname[ITOA_MAX_LEN + 1];
int r, fd;
struct kvm *kvm;
struct file *file;
@@ -4897,6 +4898,8 @@ static int kvm_dev_ioctl_create_vm(unsigned long type)
if (fd < 0)
return fd;
+ snprintf(fdname, sizeof(fdname), "%d", fd);
+
kvm = kvm_create_vm(type);
if (IS_ERR(kvm)) {
r = PTR_ERR(kvm);
@@ -4920,7 +4923,7 @@ static int kvm_dev_ioctl_create_vm(unsigned long type)
* cases it will be called by the final fput(file) and will take
* care of doing kvm_put_kvm(kvm).
*/
- if (kvm_create_vm_debugfs(kvm, fd) < 0) {
+ if (kvm_create_vm_debugfs(kvm, fdname) < 0) {
fput(file);
r = -ENOMEM;
goto put_fd;