Skip to contentSkip to conversation

KVM: selftests: kvm_vm_elf_load() and elfhdr_get() should close fd

PATCH In review Reiji Watanabe 2 participants 4 messages Dec 20, 2022 – Jan 19, 2023

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover KVM: selftests: kvm_vm_elf_load() and elfhdr_get() should close fd

kvm_vm_elf_load() and elfhdr_get() open one file each, but they never close the opened file descriptor. Fix those two functions to close the file descriptor.

This patch is the same as the one included in the patch series [1], with minor updates to the commit log (including adding Reviewed-bys I got).

[1] https://lore.kernel.org/linux-arm-kernel/[email protected]/

Reiji Watanabe (1):
KVM: selftests: kvm_vm_elf_load() and elfhdr_get() should close fd

 tools/testing/selftests/kvm/lib/elf.c | 2 ++
 1 file changed, 2 insertions(+)
Signature · 1 line
2.39.0.314.g84b9a713c41-goog
#1 lore raw

PATCH 1/1 KVM: selftests: kvm_vm_elf_load() and elfhdr_get() should close fd

kvm_vm_elf_load() and elfhdr_get() open one file each, but they never close the opened file descriptor. If a test repeatedly creates and destroys a VM with __vm_create(), which (directly or indirectly) calls those two functions, the test might end up getting a open failure with EMFILE.
Fix those two functions to close the file descriptor.

---
 tools/testing/selftests/kvm/lib/elf.c | 2 ++
 1 file changed, 2 insertions(+)
tools/testing/selftests/kvm/lib/elf.c +2 -0
index 9f54c098d9d0..ca7c3422e312 100644
@@ -90,6 +90,7 @@ static void elfhdr_get(const char *filename, Elf64_Ehdr *hdrp)
 		"  hdrp->e_shentsize: %x\n"
 		"  expected: %zx",
 		hdrp->e_shentsize, sizeof(Elf64_Shdr));
+	close(fd);
 }
 
 /* VM ELF Load
@@ -189,4 +190,5 @@ void kvm_vm_elf_load(struct kvm_vm *vm, const char *filename)
 				phdr.p_filesz);
 		}
 	}
+	close(fd);
 }
Signature · 1 line
2.39.0.314.g84b9a713c41-goog
reviewer Reviewed-by on v1 1/1
#2 lore raw
Quoted 11 lines · Reiji Watanabe

kvm_vm_elf_load() and elfhdr_get() open one file each, but they never close the opened file descriptor. If a test repeatedly creates and destroys a VM with __vm_create(), which (directly or indirectly) calls those two functions, the test might end up getting a open failure with EMFILE.
Fix those two functions to close the file descriptor.

---

#3 lore raw
In reply to Reiji Watanabe
Quoted 9 lines · Reiji Watanabe

kvm_vm_elf_load() and elfhdr_get() open one file each, but they never close the opened file descriptor. Fix those two functions to close the file descriptor.

This patch is the same as the one included in the patch series [1], with minor updates to the commit log (including adding Reviewed-bys I got).

[...]

Applied to kvm-x86 selftests, thanks!

[1/1] KVM: selftests: kvm_vm_elf_load() and elfhdr_get() should close fd

      https://github.com/kvm-x86/linux/commit/a6854fecd0b2

--
https://github.com/kvm-x86/linux/tree/next
https://github.com/kvm-x86/linux/tree/fixes