KVM: selftests: kvm_vm_elf_load() and elfhdr_get() should close fd
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
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
@@ -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
Quoted 11 lines · Reiji Watanabe
kvm_vm_elf_load()andelfhdr_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.Signed-off-by Reiji Watanabe <[email protected]>Reviewed-by Oliver Upton <[email protected]>Reviewed-by Andrew Jones <[email protected]>---
Sean Christopherson
reviewerQuoted 9 lines · Reiji Watanabe
kvm_vm_elf_load()andelfhdr_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