fs/pipe.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/fs/pipe.c b/fs/pipe.c index 64a494cef0a0..b7889c2ebaf4 100644 --- a/fs/pipe.c +++ b/fs/pipe.c @@ -863,6 +863,10 @@ pipe_rdwr_open(struct inode *inode, struct file *filp) { int ret = -ENOENT; + /* We rely on the pipe reader/writer counts to keep track of the pipe */ + if (WARN_ON_ONCE(!(filp->f_mode & (FMODE_READ|FMODE_WRITE)))) + return -EINVAL; + mutex_lock(&inode->i_mutex); if (inode->i_pipe) {