public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/1] KVM: selftests: kvm_vm_elf_load() and elfhdr_get() should close fd
@ 2022-12-20 17:09 Reiji Watanabe
  2022-12-20 17:09 ` [PATCH 1/1] " Reiji Watanabe
  2023-01-19 21:01 ` [PATCH 0/1] " Sean Christopherson
  0 siblings, 2 replies; 4+ messages in thread
From: Reiji Watanabe @ 2022-12-20 17:09 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: kvm, Sean Christopherson, Oliver Upton, Andrew Jones,
	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).

[1] https://lore.kernel.org/linux-arm-kernel/20220217034947.180935-1-reijiw@google.com/

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(+)

-- 
2.39.0.314.g84b9a713c41-goog


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/1] KVM: selftests: kvm_vm_elf_load() and elfhdr_get() should close fd
  2022-12-20 17:09 [PATCH 0/1] KVM: selftests: kvm_vm_elf_load() and elfhdr_get() should close fd Reiji Watanabe
@ 2022-12-20 17:09 ` Reiji Watanabe
  2023-01-04 15:00   ` Sean Christopherson
  2023-01-19 21:01 ` [PATCH 0/1] " Sean Christopherson
  1 sibling, 1 reply; 4+ messages in thread
From: Reiji Watanabe @ 2022-12-20 17:09 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: kvm, Sean Christopherson, Oliver Upton, Andrew Jones,
	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.

Signed-off-by: Reiji Watanabe <reijiw@google.com>
Reviewed-by: Oliver Upton <oliver.upton@linux.dev>
Reviewed-by: Andrew Jones <andrew.jones@linux.dev>
---
 tools/testing/selftests/kvm/lib/elf.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/tools/testing/selftests/kvm/lib/elf.c b/tools/testing/selftests/kvm/lib/elf.c
index 9f54c098d9d0..ca7c3422e312 100644
--- a/tools/testing/selftests/kvm/lib/elf.c
+++ b/tools/testing/selftests/kvm/lib/elf.c
@@ -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);
 }
-- 
2.39.0.314.g84b9a713c41-goog


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/1] KVM: selftests: kvm_vm_elf_load() and elfhdr_get() should close fd
  2022-12-20 17:09 ` [PATCH 1/1] " Reiji Watanabe
@ 2023-01-04 15:00   ` Sean Christopherson
  0 siblings, 0 replies; 4+ messages in thread
From: Sean Christopherson @ 2023-01-04 15:00 UTC (permalink / raw)
  To: Reiji Watanabe; +Cc: Paolo Bonzini, kvm, Oliver Upton, Andrew Jones

On Tue, Dec 20, 2022, Reiji Watanabe wrote:
> 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.
> 
> Signed-off-by: Reiji Watanabe <reijiw@google.com>
> Reviewed-by: Oliver Upton <oliver.upton@linux.dev>
> Reviewed-by: Andrew Jones <andrew.jones@linux.dev>
> ---

Reviewed-by: Sean Christopherson <seanjc@google.com>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 0/1] KVM: selftests: kvm_vm_elf_load() and elfhdr_get() should close fd
  2022-12-20 17:09 [PATCH 0/1] KVM: selftests: kvm_vm_elf_load() and elfhdr_get() should close fd Reiji Watanabe
  2022-12-20 17:09 ` [PATCH 1/1] " Reiji Watanabe
@ 2023-01-19 21:01 ` Sean Christopherson
  1 sibling, 0 replies; 4+ messages in thread
From: Sean Christopherson @ 2023-01-19 21:01 UTC (permalink / raw)
  To: Sean Christopherson, Paolo Bonzini, Reiji Watanabe
  Cc: kvm, Oliver Upton, Andrew Jones

On Tue, 20 Dec 2022 09:09:20 -0800, Reiji Watanabe wrote:
> 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

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-01-19 21:10 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-12-20 17:09 [PATCH 0/1] KVM: selftests: kvm_vm_elf_load() and elfhdr_get() should close fd Reiji Watanabe
2022-12-20 17:09 ` [PATCH 1/1] " Reiji Watanabe
2023-01-04 15:00   ` Sean Christopherson
2023-01-19 21:01 ` [PATCH 0/1] " Sean Christopherson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox