* [PATCH for-4.19 v2] tools/xl: Open xldevd.log with O_CLOEXEC
@ 2024-06-21 16:16 Andrew Cooper
2024-06-21 16:31 ` Marek Marczykowski-Górecki
` (3 more replies)
0 siblings, 4 replies; 9+ messages in thread
From: Andrew Cooper @ 2024-06-21 16:16 UTC (permalink / raw)
To: Xen-devel
Cc: Andrew Cooper, Demi Marie Obenour, Anthony PERARD, Juergen Gross,
Marek Marczykowski-Górecki, Oleksii Kurochko
`xl devd` has been observed leaking /var/log/xldevd.log into children.
Note this is specifically safe; dup2() leaves O_CLOEXEC disabled on newfd, so
after setting up stdout/stderr, it's only the logfile fd which will close on
exec().
Link: https://github.com/QubesOS/qubes-issues/issues/8292
Reported-by: Demi Marie Obenour <demi@invisiblethingslab.com>
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
---
CC: Anthony PERARD <anthony@xenproject.org>
CC: Juergen Gross <jgross@suse.com>
CC: Demi Marie Obenour <demi@invisiblethingslab.com>
CC: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
CC: Oleksii Kurochko <oleksii.kurochko@gmail.com>
Also entirely speculative based on the QubesOS ticket.
v2:
* Extend the commit message to explain why stdout/stderr aren't closed by
this change
For 4.19. This bugfix was posted earlier, but fell between the cracks.
---
tools/xl/xl_utils.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/xl/xl_utils.c b/tools/xl/xl_utils.c
index 17489d182954..060186db3a59 100644
--- a/tools/xl/xl_utils.c
+++ b/tools/xl/xl_utils.c
@@ -270,7 +270,7 @@ int do_daemonize(const char *name, const char *pidfile)
exit(-1);
}
- CHK_SYSCALL(logfile = open(fullname, O_WRONLY|O_CREAT|O_APPEND, 0644));
+ CHK_SYSCALL(logfile = open(fullname, O_WRONLY | O_CREAT | O_APPEND | O_CLOEXEC, 0644));
free(fullname);
assert(logfile >= 3);
--
2.39.2
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH for-4.19 v2] tools/xl: Open xldevd.log with O_CLOEXEC
2024-06-21 16:16 [PATCH for-4.19 v2] tools/xl: Open xldevd.log with O_CLOEXEC Andrew Cooper
@ 2024-06-21 16:31 ` Marek Marczykowski-Górecki
2024-06-21 16:55 ` Anthony PERARD
` (2 subsequent siblings)
3 siblings, 0 replies; 9+ messages in thread
From: Marek Marczykowski-Górecki @ 2024-06-21 16:31 UTC (permalink / raw)
To: Andrew Cooper
Cc: Xen-devel, Demi Marie Obenour, Anthony PERARD, Juergen Gross,
Oleksii Kurochko
[-- Attachment #1: Type: text/plain, Size: 1799 bytes --]
On Fri, Jun 21, 2024 at 05:16:56PM +0100, Andrew Cooper wrote:
> `xl devd` has been observed leaking /var/log/xldevd.log into children.
>
> Note this is specifically safe; dup2() leaves O_CLOEXEC disabled on newfd, so
> after setting up stdout/stderr, it's only the logfile fd which will close on
> exec().
>
> Link: https://github.com/QubesOS/qubes-issues/issues/8292
> Reported-by: Demi Marie Obenour <demi@invisiblethingslab.com>
> Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
> ---
> CC: Anthony PERARD <anthony@xenproject.org>
> CC: Juergen Gross <jgross@suse.com>
> CC: Demi Marie Obenour <demi@invisiblethingslab.com>
> CC: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
> CC: Oleksii Kurochko <oleksii.kurochko@gmail.com>
>
> Also entirely speculative based on the QubesOS ticket.
>
> v2:
> * Extend the commit message to explain why stdout/stderr aren't closed by
> this change
>
> For 4.19. This bugfix was posted earlier, but fell between the cracks.
> ---
> tools/xl/xl_utils.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/tools/xl/xl_utils.c b/tools/xl/xl_utils.c
> index 17489d182954..060186db3a59 100644
> --- a/tools/xl/xl_utils.c
> +++ b/tools/xl/xl_utils.c
> @@ -270,7 +270,7 @@ int do_daemonize(const char *name, const char *pidfile)
> exit(-1);
> }
>
> - CHK_SYSCALL(logfile = open(fullname, O_WRONLY|O_CREAT|O_APPEND, 0644));
> + CHK_SYSCALL(logfile = open(fullname, O_WRONLY | O_CREAT | O_APPEND | O_CLOEXEC, 0644));
> free(fullname);
> assert(logfile >= 3);
>
> --
> 2.39.2
>
--
Best Regards,
Marek Marczykowski-Górecki
Invisible Things Lab
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH for-4.19 v2] tools/xl: Open xldevd.log with O_CLOEXEC
2024-06-21 16:16 [PATCH for-4.19 v2] tools/xl: Open xldevd.log with O_CLOEXEC Andrew Cooper
2024-06-21 16:31 ` Marek Marczykowski-Górecki
@ 2024-06-21 16:55 ` Anthony PERARD
2024-06-21 16:59 ` Andrew Cooper
` (2 more replies)
2024-06-21 21:41 ` Demi Marie Obenour
2024-06-24 8:14 ` Oleksii
3 siblings, 3 replies; 9+ messages in thread
From: Anthony PERARD @ 2024-06-21 16:55 UTC (permalink / raw)
To: Andrew Cooper
Cc: Xen-devel, Demi Marie Obenour, Anthony PERARD, Juergen Gross,
Marek Marczykowski-Górecki, Oleksii Kurochko
On Fri, Jun 21, 2024 at 05:16:56PM +0100, Andrew Cooper wrote:
> `xl devd` has been observed leaking /var/log/xldevd.log into children.
>
> Note this is specifically safe; dup2() leaves O_CLOEXEC disabled on newfd, so
> after setting up stdout/stderr, it's only the logfile fd which will close on
> exec().
>
> Link: https://github.com/QubesOS/qubes-issues/issues/8292
> Reported-by: Demi Marie Obenour <demi@invisiblethingslab.com>
> Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
> ---
> CC: Anthony PERARD <anthony@xenproject.org>
> CC: Juergen Gross <jgross@suse.com>
> CC: Demi Marie Obenour <demi@invisiblethingslab.com>
> CC: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
> CC: Oleksii Kurochko <oleksii.kurochko@gmail.com>
>
> Also entirely speculative based on the QubesOS ticket.
>
> v2:
> * Extend the commit message to explain why stdout/stderr aren't closed by
> this change
>
> For 4.19. This bugfix was posted earlier, but fell between the cracks.
> ---
> tools/xl/xl_utils.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/tools/xl/xl_utils.c b/tools/xl/xl_utils.c
> index 17489d182954..060186db3a59 100644
> --- a/tools/xl/xl_utils.c
> +++ b/tools/xl/xl_utils.c
> @@ -270,7 +270,7 @@ int do_daemonize(const char *name, const char *pidfile)
> exit(-1);
> }
>
> - CHK_SYSCALL(logfile = open(fullname, O_WRONLY|O_CREAT|O_APPEND, 0644));
> + CHK_SYSCALL(logfile = open(fullname, O_WRONLY | O_CREAT | O_APPEND | O_CLOEXEC, 0644));
Everytime we use O_CLOEXEC, we add in the C file
#ifndef O_CLOEXEC
#define O_CLOEXEC 0
#endif
we don't need to do that anymore?
Or I guess we'll see if someone complain when they try to build on an
ancien version of Linux.
Acked-by: Anthony PERARD <anthony.perard@vates.tech>
Thanks,
--
Anthony Perard | Vates XCP-ng Developer
XCP-ng & Xen Orchestra - Vates solutions
web: https://vates.tech
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH for-4.19 v2] tools/xl: Open xldevd.log with O_CLOEXEC
2024-06-21 16:55 ` Anthony PERARD
@ 2024-06-21 16:59 ` Andrew Cooper
2024-06-24 7:47 ` Jan Beulich
2024-06-24 7:46 ` Jan Beulich
2024-06-24 10:18 ` Andrew Cooper
2 siblings, 1 reply; 9+ messages in thread
From: Andrew Cooper @ 2024-06-21 16:59 UTC (permalink / raw)
To: Anthony PERARD
Cc: Xen-devel, Demi Marie Obenour, Anthony PERARD, Juergen Gross,
Marek Marczykowski-Górecki, Oleksii Kurochko
On 21/06/2024 5:55 pm, Anthony PERARD wrote:
> On Fri, Jun 21, 2024 at 05:16:56PM +0100, Andrew Cooper wrote:
>> `xl devd` has been observed leaking /var/log/xldevd.log into children.
>>
>> Note this is specifically safe; dup2() leaves O_CLOEXEC disabled on newfd, so
>> after setting up stdout/stderr, it's only the logfile fd which will close on
>> exec().
>>
>> Link: https://github.com/QubesOS/qubes-issues/issues/8292
>> Reported-by: Demi Marie Obenour <demi@invisiblethingslab.com>
>> Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
>> ---
>> CC: Anthony PERARD <anthony@xenproject.org>
>> CC: Juergen Gross <jgross@suse.com>
>> CC: Demi Marie Obenour <demi@invisiblethingslab.com>
>> CC: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
>> CC: Oleksii Kurochko <oleksii.kurochko@gmail.com>
>>
>> Also entirely speculative based on the QubesOS ticket.
>>
>> v2:
>> * Extend the commit message to explain why stdout/stderr aren't closed by
>> this change
>>
>> For 4.19. This bugfix was posted earlier, but fell between the cracks.
>> ---
>> tools/xl/xl_utils.c | 2 +-
>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/tools/xl/xl_utils.c b/tools/xl/xl_utils.c
>> index 17489d182954..060186db3a59 100644
>> --- a/tools/xl/xl_utils.c
>> +++ b/tools/xl/xl_utils.c
>> @@ -270,7 +270,7 @@ int do_daemonize(const char *name, const char *pidfile)
>> exit(-1);
>> }
>>
>> - CHK_SYSCALL(logfile = open(fullname, O_WRONLY|O_CREAT|O_APPEND, 0644));
>> + CHK_SYSCALL(logfile = open(fullname, O_WRONLY | O_CREAT | O_APPEND | O_CLOEXEC, 0644));
> Everytime we use O_CLOEXEC, we add in the C file
> #ifndef O_CLOEXEC
> #define O_CLOEXEC 0
> #endif
> we don't need to do that anymore?
> Or I guess we'll see if someone complain when they try to build on an
> ancien version of Linux.
>
> Acked-by: Anthony PERARD <anthony.perard@vates.tech>
Thanks. I did originally have that ifdefary here, but then I noticed
that this isn't the first instance like this in xl, and I'm going to be
using that as a justification soon to explicitly drop support for Linux
< 2.6.23.
~Andrew
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH for-4.19 v2] tools/xl: Open xldevd.log with O_CLOEXEC
2024-06-21 16:16 [PATCH for-4.19 v2] tools/xl: Open xldevd.log with O_CLOEXEC Andrew Cooper
2024-06-21 16:31 ` Marek Marczykowski-Górecki
2024-06-21 16:55 ` Anthony PERARD
@ 2024-06-21 21:41 ` Demi Marie Obenour
2024-06-24 8:14 ` Oleksii
3 siblings, 0 replies; 9+ messages in thread
From: Demi Marie Obenour @ 2024-06-21 21:41 UTC (permalink / raw)
To: Andrew Cooper, Xen-devel
Cc: Anthony PERARD, Juergen Gross, Marek Marczykowski-Górecki,
Oleksii Kurochko
[-- Attachment #1: Type: text/plain, Size: 1956 bytes --]
On Fri, Jun 21, 2024 at 05:16:56PM +0100, Andrew Cooper wrote:
> `xl devd` has been observed leaking /var/log/xldevd.log into children.
>
> Note this is specifically safe; dup2() leaves O_CLOEXEC disabled on newfd, so
> after setting up stdout/stderr, it's only the logfile fd which will close on
> exec().
>
> Link: https://github.com/QubesOS/qubes-issues/issues/8292
> Reported-by: Demi Marie Obenour <demi@invisiblethingslab.com>
> Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
> ---
> CC: Anthony PERARD <anthony@xenproject.org>
> CC: Juergen Gross <jgross@suse.com>
> CC: Demi Marie Obenour <demi@invisiblethingslab.com>
> CC: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
> CC: Oleksii Kurochko <oleksii.kurochko@gmail.com>
>
> Also entirely speculative based on the QubesOS ticket.
>
> v2:
> * Extend the commit message to explain why stdout/stderr aren't closed by
> this change
>
> For 4.19. This bugfix was posted earlier, but fell between the cracks.
> ---
> tools/xl/xl_utils.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/tools/xl/xl_utils.c b/tools/xl/xl_utils.c
> index 17489d182954..060186db3a59 100644
> --- a/tools/xl/xl_utils.c
> +++ b/tools/xl/xl_utils.c
> @@ -270,7 +270,7 @@ int do_daemonize(const char *name, const char *pidfile)
> exit(-1);
> }
>
> - CHK_SYSCALL(logfile = open(fullname, O_WRONLY|O_CREAT|O_APPEND, 0644));
> + CHK_SYSCALL(logfile = open(fullname, O_WRONLY | O_CREAT | O_APPEND | O_CLOEXEC, 0644));
> free(fullname);
> assert(logfile >= 3);
Definitely an improvement. I would also add O_NOCTTY to work around a
particularly unfortunate Linux kernel design decision, but that can
either be fixed up on commit or be a separate patch.
Reviewed-by: Demi Marie Obenour <demi@invisiblethingslab.com>
--
Sincerely,
Demi Marie Obenour (she/her/hers)
Invisible Things Lab
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH for-4.19 v2] tools/xl: Open xldevd.log with O_CLOEXEC
2024-06-21 16:55 ` Anthony PERARD
2024-06-21 16:59 ` Andrew Cooper
@ 2024-06-24 7:46 ` Jan Beulich
2024-06-24 10:18 ` Andrew Cooper
2 siblings, 0 replies; 9+ messages in thread
From: Jan Beulich @ 2024-06-24 7:46 UTC (permalink / raw)
To: Anthony PERARD, Andrew Cooper
Cc: Xen-devel, Demi Marie Obenour, Anthony PERARD, Juergen Gross,
Marek Marczykowski-Górecki, Oleksii Kurochko
On 21.06.2024 18:55, Anthony PERARD wrote:
> On Fri, Jun 21, 2024 at 05:16:56PM +0100, Andrew Cooper wrote:
>> `xl devd` has been observed leaking /var/log/xldevd.log into children.
>>
>> Note this is specifically safe; dup2() leaves O_CLOEXEC disabled on newfd, so
>> after setting up stdout/stderr, it's only the logfile fd which will close on
>> exec().
>>
>> Link: https://github.com/QubesOS/qubes-issues/issues/8292
>> Reported-by: Demi Marie Obenour <demi@invisiblethingslab.com>
>> Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
>> ---
>> CC: Anthony PERARD <anthony@xenproject.org>
>> CC: Juergen Gross <jgross@suse.com>
>> CC: Demi Marie Obenour <demi@invisiblethingslab.com>
>> CC: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
>> CC: Oleksii Kurochko <oleksii.kurochko@gmail.com>
>>
>> Also entirely speculative based on the QubesOS ticket.
>>
>> v2:
>> * Extend the commit message to explain why stdout/stderr aren't closed by
>> this change
>>
>> For 4.19. This bugfix was posted earlier, but fell between the cracks.
>> ---
>> tools/xl/xl_utils.c | 2 +-
>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/tools/xl/xl_utils.c b/tools/xl/xl_utils.c
>> index 17489d182954..060186db3a59 100644
>> --- a/tools/xl/xl_utils.c
>> +++ b/tools/xl/xl_utils.c
>> @@ -270,7 +270,7 @@ int do_daemonize(const char *name, const char *pidfile)
>> exit(-1);
>> }
>>
>> - CHK_SYSCALL(logfile = open(fullname, O_WRONLY|O_CREAT|O_APPEND, 0644));
>> + CHK_SYSCALL(logfile = open(fullname, O_WRONLY | O_CREAT | O_APPEND | O_CLOEXEC, 0644));
>
> Everytime we use O_CLOEXEC, we add in the C file
> #ifndef O_CLOEXEC
> #define O_CLOEXEC 0
> #endif
> we don't need to do that anymore?
> Or I guess we'll see if someone complain when they try to build on an
> ancien version of Linux.
I'm pretty certain I'll run into that issue on one of my pretty old systems,
but if the general view is that we don't care about such environments anymore,
then so be it (and I'll take care of such issues locally).
Jan
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH for-4.19 v2] tools/xl: Open xldevd.log with O_CLOEXEC
2024-06-21 16:59 ` Andrew Cooper
@ 2024-06-24 7:47 ` Jan Beulich
0 siblings, 0 replies; 9+ messages in thread
From: Jan Beulich @ 2024-06-24 7:47 UTC (permalink / raw)
To: Andrew Cooper
Cc: Xen-devel, Demi Marie Obenour, Anthony PERARD, Juergen Gross,
Marek Marczykowski-Górecki, Oleksii Kurochko, Anthony PERARD
On 21.06.2024 18:59, Andrew Cooper wrote:
> On 21/06/2024 5:55 pm, Anthony PERARD wrote:
>> On Fri, Jun 21, 2024 at 05:16:56PM +0100, Andrew Cooper wrote:
>>> `xl devd` has been observed leaking /var/log/xldevd.log into children.
>>>
>>> Note this is specifically safe; dup2() leaves O_CLOEXEC disabled on newfd, so
>>> after setting up stdout/stderr, it's only the logfile fd which will close on
>>> exec().
>>>
>>> Link: https://github.com/QubesOS/qubes-issues/issues/8292
>>> Reported-by: Demi Marie Obenour <demi@invisiblethingslab.com>
>>> Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
>>> ---
>>> CC: Anthony PERARD <anthony@xenproject.org>
>>> CC: Juergen Gross <jgross@suse.com>
>>> CC: Demi Marie Obenour <demi@invisiblethingslab.com>
>>> CC: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
>>> CC: Oleksii Kurochko <oleksii.kurochko@gmail.com>
>>>
>>> Also entirely speculative based on the QubesOS ticket.
>>>
>>> v2:
>>> * Extend the commit message to explain why stdout/stderr aren't closed by
>>> this change
>>>
>>> For 4.19. This bugfix was posted earlier, but fell between the cracks.
>>> ---
>>> tools/xl/xl_utils.c | 2 +-
>>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>>
>>> diff --git a/tools/xl/xl_utils.c b/tools/xl/xl_utils.c
>>> index 17489d182954..060186db3a59 100644
>>> --- a/tools/xl/xl_utils.c
>>> +++ b/tools/xl/xl_utils.c
>>> @@ -270,7 +270,7 @@ int do_daemonize(const char *name, const char *pidfile)
>>> exit(-1);
>>> }
>>>
>>> - CHK_SYSCALL(logfile = open(fullname, O_WRONLY|O_CREAT|O_APPEND, 0644));
>>> + CHK_SYSCALL(logfile = open(fullname, O_WRONLY | O_CREAT | O_APPEND | O_CLOEXEC, 0644));
>> Everytime we use O_CLOEXEC, we add in the C file
>> #ifndef O_CLOEXEC
>> #define O_CLOEXEC 0
>> #endif
>> we don't need to do that anymore?
>> Or I guess we'll see if someone complain when they try to build on an
>> ancien version of Linux.
>>
>> Acked-by: Anthony PERARD <anthony.perard@vates.tech>
>
> Thanks. I did originally have that ifdefary here, but then I noticed
> that this isn't the first instance like this in xl, and I'm going to be
> using that as a justification soon to explicitly drop support for Linux
> < 2.6.23.
Just to mention that this is a two fold thing: I surely don't try to run
up-to-date Xen on top of this old a Linux kernel, but what is used for
building is still what the distro (with a very old kernel) would have put
there.
Jan
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH for-4.19 v2] tools/xl: Open xldevd.log with O_CLOEXEC
2024-06-21 16:16 [PATCH for-4.19 v2] tools/xl: Open xldevd.log with O_CLOEXEC Andrew Cooper
` (2 preceding siblings ...)
2024-06-21 21:41 ` Demi Marie Obenour
@ 2024-06-24 8:14 ` Oleksii
3 siblings, 0 replies; 9+ messages in thread
From: Oleksii @ 2024-06-24 8:14 UTC (permalink / raw)
To: Andrew Cooper, Xen-devel
Cc: Demi Marie Obenour, Anthony PERARD, Juergen Gross,
Marek Marczykowski-Górecki
On Fri, 2024-06-21 at 17:16 +0100, Andrew Cooper wrote:
> `xl devd` has been observed leaking /var/log/xldevd.log into
> children.
>
> Note this is specifically safe; dup2() leaves O_CLOEXEC disabled on
> newfd, so
> after setting up stdout/stderr, it's only the logfile fd which will
> close on
> exec().
>
> Link: https://github.com/QubesOS/qubes-issues/issues/8292
> Reported-by: Demi Marie Obenour <demi@invisiblethingslab.com>
> Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Release-Acked-by: Oleksii Kurochko <oleksii.kurochko@gmail.com>
~ Oleksii
> ---
> CC: Anthony PERARD <anthony@xenproject.org>
> CC: Juergen Gross <jgross@suse.com>
> CC: Demi Marie Obenour <demi@invisiblethingslab.com>
> CC: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
> CC: Oleksii Kurochko <oleksii.kurochko@gmail.com>
>
> Also entirely speculative based on the QubesOS ticket.
>
> v2:
> * Extend the commit message to explain why stdout/stderr aren't
> closed by
> this change
>
> For 4.19. This bugfix was posted earlier, but fell between the
> cracks.
> ---
> tools/xl/xl_utils.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/tools/xl/xl_utils.c b/tools/xl/xl_utils.c
> index 17489d182954..060186db3a59 100644
> --- a/tools/xl/xl_utils.c
> +++ b/tools/xl/xl_utils.c
> @@ -270,7 +270,7 @@ int do_daemonize(const char *name, const char
> *pidfile)
> exit(-1);
> }
>
> - CHK_SYSCALL(logfile = open(fullname, O_WRONLY|O_CREAT|O_APPEND,
> 0644));
> + CHK_SYSCALL(logfile = open(fullname, O_WRONLY | O_CREAT |
> O_APPEND | O_CLOEXEC, 0644));
> free(fullname);
> assert(logfile >= 3);
>
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH for-4.19 v2] tools/xl: Open xldevd.log with O_CLOEXEC
2024-06-21 16:55 ` Anthony PERARD
2024-06-21 16:59 ` Andrew Cooper
2024-06-24 7:46 ` Jan Beulich
@ 2024-06-24 10:18 ` Andrew Cooper
2 siblings, 0 replies; 9+ messages in thread
From: Andrew Cooper @ 2024-06-24 10:18 UTC (permalink / raw)
To: Anthony PERARD
Cc: Xen-devel, Demi Marie Obenour, Anthony PERARD, Juergen Gross,
Marek Marczykowski-Górecki, Oleksii Kurochko
On 21/06/2024 5:55 pm, Anthony PERARD wrote:
> On Fri, Jun 21, 2024 at 05:16:56PM +0100, Andrew Cooper wrote:
>> `xl devd` has been observed leaking /var/log/xldevd.log into children.
>>
>> Note this is specifically safe; dup2() leaves O_CLOEXEC disabled on newfd, so
>> after setting up stdout/stderr, it's only the logfile fd which will close on
>> exec().
>>
>> Link: https://github.com/QubesOS/qubes-issues/issues/8292
>> Reported-by: Demi Marie Obenour <demi@invisiblethingslab.com>
>> Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
>> ---
>> CC: Anthony PERARD <anthony@xenproject.org>
>> CC: Juergen Gross <jgross@suse.com>
>> CC: Demi Marie Obenour <demi@invisiblethingslab.com>
>> CC: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
>> CC: Oleksii Kurochko <oleksii.kurochko@gmail.com>
>>
>> Also entirely speculative based on the QubesOS ticket.
>>
>> v2:
>> * Extend the commit message to explain why stdout/stderr aren't closed by
>> this change
>>
>> For 4.19. This bugfix was posted earlier, but fell between the cracks.
>> ---
>> tools/xl/xl_utils.c | 2 +-
>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/tools/xl/xl_utils.c b/tools/xl/xl_utils.c
>> index 17489d182954..060186db3a59 100644
>> --- a/tools/xl/xl_utils.c
>> +++ b/tools/xl/xl_utils.c
>> @@ -270,7 +270,7 @@ int do_daemonize(const char *name, const char *pidfile)
>> exit(-1);
>> }
>>
>> - CHK_SYSCALL(logfile = open(fullname, O_WRONLY|O_CREAT|O_APPEND, 0644));
>> + CHK_SYSCALL(logfile = open(fullname, O_WRONLY | O_CREAT | O_APPEND | O_CLOEXEC, 0644));
> Everytime we use O_CLOEXEC, we add in the C file
> #ifndef O_CLOEXEC
> #define O_CLOEXEC 0
> #endif
> we don't need to do that anymore?
> Or I guess we'll see if someone complain when they try to build on an
> ancien version of Linux.
I double checked, and it turns out it was an FD_CLOEXEC, not an
O_CLOEXEC which xl was using, so we don't have a pre-existing example.
Therefore I've re-added this at the top of xl_utils.c
~Andrew
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2024-06-24 10:19 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-06-21 16:16 [PATCH for-4.19 v2] tools/xl: Open xldevd.log with O_CLOEXEC Andrew Cooper
2024-06-21 16:31 ` Marek Marczykowski-Górecki
2024-06-21 16:55 ` Anthony PERARD
2024-06-21 16:59 ` Andrew Cooper
2024-06-24 7:47 ` Jan Beulich
2024-06-24 7:46 ` Jan Beulich
2024-06-24 10:18 ` Andrew Cooper
2024-06-21 21:41 ` Demi Marie Obenour
2024-06-24 8:14 ` Oleksii
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.