autofs: clear O_NONBLOCK on the pipe.
diff mbox series

Message ID 871s4fi5b5.fsf@notabene.neil.brown.name
State Accepted
Commit 660c9fc72e06d7a46d96d2cb8524a26565072a76
Headers show
Series
  • autofs: clear O_NONBLOCK on the pipe.
Related show

Commit Message

NeilBrown Feb. 10, 2019, 11:37 p.m. UTC
autofs does not expect the pipe it is given
to have O_NONBLOCK set - specifically if __kernel_write()
in autofs_write() returns -EAGAIN, this is treated
as a fatal error and the pipe is closed.

For safety autofs should, therefore, clear the O_NONBLOCK flag.

Releases of systemd prior to 8th February 2019 used
  pipe2(p, O_NONBLOCK|O_CLOEXEC)
and thus (inadvertently) set this flag.

Signed-off-by: NeilBrown <neilb@suse.com>
---
 fs/autofs/autofs_i.h | 2 ++
 1 file changed, 2 insertions(+)

Comments

Ian Kent Feb. 11, 2019, 5:31 a.m. UTC | #1
On Mon, 2019-02-11 at 10:37 +1100, NeilBrown wrote:
> autofs does not expect the pipe it is given
> to have O_NONBLOCK set - specifically if __kernel_write()
> in autofs_write() returns -EAGAIN, this is treated
> as a fatal error and the pipe is closed.
> 
> For safety autofs should, therefore, clear the O_NONBLOCK flag.
> 
> Releases of systemd prior to 8th February 2019 used
>   pipe2(p, O_NONBLOCK|O_CLOEXEC)
> and thus (inadvertently) set this flag.

Thanks Neil, this does look like an obvious problem.

> 
> Signed-off-by: NeilBrown <neilb@suse.com>
> ---
>  fs/autofs/autofs_i.h | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/fs/autofs/autofs_i.h b/fs/autofs/autofs_i.h
> index 3e59f0ed777b..331192bed0d5 100644
> --- a/fs/autofs/autofs_i.h
> +++ b/fs/autofs/autofs_i.h
> @@ -215,6 +215,8 @@ static inline int autofs_prepare_pipe(struct file *pipe)
>  		return -EINVAL;
>  	/* We want a packet pipe */
>  	pipe->f_flags |= O_DIRECT;
> +	/* We don't expect -EAGAIN */
> +	pipe->f_flags &= ~O_NONBLOCK;
>  	return 0;
>  }
>

Patch
diff mbox series

diff --git a/fs/autofs/autofs_i.h b/fs/autofs/autofs_i.h
index 3e59f0ed777b..331192bed0d5 100644
--- a/fs/autofs/autofs_i.h
+++ b/fs/autofs/autofs_i.h
@@ -215,6 +215,8 @@  static inline int autofs_prepare_pipe(struct file *pipe)
 		return -EINVAL;
 	/* We want a packet pipe */
 	pipe->f_flags |= O_DIRECT;
+	/* We don't expect -EAGAIN */
+	pipe->f_flags &= ~O_NONBLOCK;
 	return 0;
 }