On 27/02/2019 10:33, Christian Lindig wrote:
> Don't close stdin in daemonize() but dup2 /dev/null instead. This avoids
> fd 0 being reused and potentially written to.
>
> Signed-off-by: Christian Lindig <christian.lin...@citrix.com>

Possibly worth noting that this fixes a bug whereby /dev/xen/evtchn
reliably gets opened on fd 0.

I can fix the wording up on commit if there are no other concerns.

Reviewed-by: Andrew Cooper <andrew.coop...@citrix.com>, and CC'ing
Juergen for 4.12

> ---
>  tools/ocaml/xenstored/stdext.ml | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/tools/ocaml/xenstored/stdext.ml b/tools/ocaml/xenstored/stdext.ml
> index 879565c515..ffb516a0d4 100644
> --- a/tools/ocaml/xenstored/stdext.ml
> +++ b/tools/ocaml/xenstored/stdext.ml
> @@ -100,9 +100,9 @@ let daemonize () =
>  
>               begin match Unix.fork () with
>               | 0 ->
> -                     let nullfd = Unix.openfile "/dev/null" [ Unix.O_WRONLY 
> ] 0 in
> +                     let nullfd = Unix.openfile "/dev/null" [ Unix.O_RDWR] 0 
> in
>                       begin try
> -                             Unix.close Unix.stdin;
> +                             Unix.dup2 nullfd Unix.stdin;
>                               Unix.dup2 nullfd Unix.stdout;
>                               Unix.dup2 nullfd Unix.stderr;
>                       with exn -> Unix.close nullfd; raise exn


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

Reply via email to