Re: [PATCH] policycoreutils/run_init: fix EINTR/EAGAIN checking in open_init_pty

Stephen Smalley <[email protected]> Tue, 21 Jul 2026 08:49:47 -0400
Newsgroups org.kernel.vger.selinux
Message-ID <CAEjxPJ4KPaOsjJHqiSevmSAUojxmPdA3wS84f6b_VOB26bZZ9w@mail.gmail.com>
On Thu, Jul 16, 2026 at 10:35 AM Stephen Smalley
<[email protected]> wrote:
>
> open_init_pty was incorrectly checking the number of bytes
> read/written against EINTR/EAGAIN. Check errno instead, and only check
> it if the return value is less than 0 since otherwise errno could have
> been set by an earlier operation.
>
> Signed-off-by: Stephen Smalley <[email protected]>

Merged.

> ---
>  policycoreutils/run_init/open_init_pty.c | 12 ++++++++----
>  1 file changed, 8 insertions(+), 4 deletions(-)
>
> diff --git a/policycoreutils/run_init/open_init_pty.c b/policycoreutils/run_init/open_init_pty.c
> index a51320a5..bd65c991 100644
> --- a/policycoreutils/run_init/open_init_pty.c
> +++ b/policycoreutils/run_init/open_init_pty.c
> @@ -371,7 +371,8 @@ int main(int argc, char *argv[])
>                         fprintf(stderr, "stdout can be written\n");
>  #endif
>                         ssize_t n = rb_write(&outbuf, STDOUT_FILENO);
> -                       if (n <= 0 && n != EINTR && n != EAGAIN)
> +                       if (n == 0 ||
> +                           (n < 0 && errno != EINTR && errno != EAGAIN))
>                                 err_n_stdout++;
>  #ifdef DEBUG
>                         if (n >= 0)
> @@ -387,7 +388,8 @@ int main(int argc, char *argv[])
>                         fprintf(stderr, "pty_master can be written\n");
>  #endif
>                         ssize_t n = rb_write(&inbuf, pty_master);
> -                       if (n <= 0 && n != EINTR && n != EAGAIN)
> +                       if (n == 0 ||
> +                           (n < 0 && errno != EINTR && errno != EAGAIN))
>                                 err_n_wpty++;
>  #ifdef DEBUG
>                         if (n >= 0)
> @@ -404,7 +406,8 @@ int main(int argc, char *argv[])
>                         fprintf(stderr, "stdin can be read\n");
>  #endif
>                         ssize_t n = rb_read(&inbuf, STDIN_FILENO);
> -                       if (n <= 0 && n != EINTR && n != EAGAIN)
> +                       if (n == 0 ||
> +                           (n < 0 && errno != EINTR && errno != EAGAIN))
>                                 err_n_stdin++;
>  #ifdef DEBUG
>                         if (n >= 0)
> @@ -420,7 +423,8 @@ int main(int argc, char *argv[])
>                         fprintf(stderr, "pty_master can be read\n");
>  #endif
>                         ssize_t n = rb_read(&outbuf, pty_master);
> -                       if (n <= 0 && n != EINTR && n != EAGAIN)
> +                       if (n == 0 ||
> +                           (n < 0 && errno != EINTR && errno != EAGAIN))
>                                 err_n_rpty++;
>  #ifdef DEBUG
>                         if (n >= 0)
> --
> 2.55.0
>