[PATCH 1/2] hax: Fix setting of FD_CLOEXEC

Eric Blake posted 2 patches 5 years, 9 months ago
Maintainers: Wenchao Wang <wenchao.wang@intel.com>, Eduardo Habkost <ehabkost@redhat.com>, Colin Xu <colin.xu@intel.com>, Paolo Bonzini <pbonzini@redhat.com>, Richard Henderson <rth@twiddle.net>
[PATCH 1/2] hax: Fix setting of FD_CLOEXEC
Posted by Eric Blake 5 years, 9 months ago
Blindly setting FD_CLOEXEC without a read-modify-write will
inadvertently clear any other intentionally-set bits, such as a
proposed new bit for designating a fd that must behave in 32-bit mode.
Use our wrapper function instead of an incorrect hand-rolled version.

Signed-off-by: Eric Blake <eblake@redhat.com>
---
 target/i386/hax-posix.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/target/i386/hax-posix.c b/target/i386/hax-posix.c
index 3bad89f13337..5f9d1b803dec 100644
--- a/target/i386/hax-posix.c
+++ b/target/i386/hax-posix.c
@@ -23,7 +23,7 @@ hax_fd hax_mod_open(void)
         fprintf(stderr, "Failed to open the hax module\n");
     }

-    fcntl(fd, F_SETFD, FD_CLOEXEC);
+    qemu_set_cloexec(fd);

     return fd;
 }
@@ -147,7 +147,7 @@ hax_fd hax_host_open_vm(struct hax_state *hax, int vm_id)
     fd = open(vm_name, O_RDWR);
     g_free(vm_name);

-    fcntl(fd, F_SETFD, FD_CLOEXEC);
+    qemu_set_cloexec(fd);

     return fd;
 }
@@ -200,7 +200,7 @@ hax_fd hax_host_open_vcpu(int vmid, int vcpuid)
     if (fd < 0) {
         fprintf(stderr, "Failed to open the vcpu devfs\n");
     }
-    fcntl(fd, F_SETFD, FD_CLOEXEC);
+    qemu_set_cloexec(fd);
     return fd;
 }

-- 
2.26.1


Re: [PATCH 1/2] hax: Fix setting of FD_CLOEXEC
Posted by Eduardo Habkost 5 years, 9 months ago
On Mon, Apr 20, 2020 at 12:53:07PM -0500, Eric Blake wrote:
> Blindly setting FD_CLOEXEC without a read-modify-write will
> inadvertently clear any other intentionally-set bits, such as a
> proposed new bit for designating a fd that must behave in 32-bit mode.
> Use our wrapper function instead of an incorrect hand-rolled version.
> 
> Signed-off-by: Eric Blake <eblake@redhat.com>

Thanks, queued for 5.1.

-- 
Eduardo


Re: [PATCH 1/2] hax: Fix setting of FD_CLOEXEC
Posted by Eric Blake 5 years, 8 months ago
On 4/20/20 5:07 PM, Eduardo Habkost wrote:
> On Mon, Apr 20, 2020 at 12:53:07PM -0500, Eric Blake wrote:
>> Blindly setting FD_CLOEXEC without a read-modify-write will
>> inadvertently clear any other intentionally-set bits, such as a
>> proposed new bit for designating a fd that must behave in 32-bit mode.
>> Use our wrapper function instead of an incorrect hand-rolled version.
>>
>> Signed-off-by: Eric Blake <eblake@redhat.com>
> 
> Thanks, queued for 5.1.

Ping - I still don't see this upstream.

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org


Re: [PATCH 1/2] hax: Fix setting of FD_CLOEXEC
Posted by Colin Xu 5 years, 9 months ago
Looks good to me.

Reviewed-by: Colin Xu <colin.xu@intel.com>

--
Best Regards,
Colin Xu

On Tue, 21 Apr 2020, Eric Blake wrote:

> Blindly setting FD_CLOEXEC without a read-modify-write will
> inadvertently clear any other intentionally-set bits, such as a
> proposed new bit for designating a fd that must behave in 32-bit mode.
> Use our wrapper function instead of an incorrect hand-rolled version.
>
> Signed-off-by: Eric Blake <eblake@redhat.com>
> ---
> target/i386/hax-posix.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/target/i386/hax-posix.c b/target/i386/hax-posix.c
> index 3bad89f13337..5f9d1b803dec 100644
> --- a/target/i386/hax-posix.c
> +++ b/target/i386/hax-posix.c
> @@ -23,7 +23,7 @@ hax_fd hax_mod_open(void)
>         fprintf(stderr, "Failed to open the hax module\n");
>     }
>
> -    fcntl(fd, F_SETFD, FD_CLOEXEC);
> +    qemu_set_cloexec(fd);
>
>     return fd;
> }
> @@ -147,7 +147,7 @@ hax_fd hax_host_open_vm(struct hax_state *hax, int vm_id)
>     fd = open(vm_name, O_RDWR);
>     g_free(vm_name);
>
> -    fcntl(fd, F_SETFD, FD_CLOEXEC);
> +    qemu_set_cloexec(fd);
>
>     return fd;
> }
> @@ -200,7 +200,7 @@ hax_fd hax_host_open_vcpu(int vmid, int vcpuid)
>     if (fd < 0) {
>         fprintf(stderr, "Failed to open the vcpu devfs\n");
>     }
> -    fcntl(fd, F_SETFD, FD_CLOEXEC);
> +    qemu_set_cloexec(fd);
>     return fd;
> }
>
> -- 
> 2.26.1
>
>