Skip to contentSkip to conversation

autofs: clear O_NONBLOCK on the pipe.

PATCH In review NeilBrown 2 participants 2 messages Feb 10, 2019 – Feb 11, 2019 Kernel automounter

lore
Share & tools
lore

NeilBrown

author
#0 lore raw

PATCH 1/1 autofs: clear O_NONBLOCK on the pipe.

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.

---
 fs/autofs/autofs_i.h | 2 ++
 1 file changed, 2 insertions(+)
fs/autofs/autofs_i.h +2 -0
index 3e59f0ed777b..331192bed0d5 100644
@@ -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;
 }
 
Signature · 1 line
2.14.0.rc0.dirty
maintainer
#1 lore raw
Quoted 10 lines · NeilBrown

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.

Quoted 19 lines
---
 fs/autofs/autofs_i.h | 2 ++
 1 file changed, 2 insertions(+)
fs/autofs/autofs_i.h +2 -0
index 3e59f0ed777b..331192bed0d5 100644
@@ -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;
 }