diff options
author | Christoph Hellwig <hch@lst.de> | 2020-05-08 08:55:03 +0200 |
---|---|---|
committer | Christoph Hellwig <hch@lst.de> | 2020-07-08 08:27:56 +0200 |
commit | a01ac27be4729f80176a45c54611b768dfbdc840 (patch) | |
tree | a16940d89cd9a69f4119cd29fc80f4e0018fd2ec /fs | |
parent | fs: unexport __kernel_write (diff) | |
download | linux-a01ac27be4729f80176a45c54611b768dfbdc840.tar.xz linux-a01ac27be4729f80176a45c54611b768dfbdc840.zip |
fs: check FMODE_WRITE in __kernel_write
Add a WARN_ON_ONCE if the file isn't actually open for write. This
matches the check done in vfs_write, but actually warn warns as a
kernel user calling write on a file not opened for writing is a pretty
obvious programming error.
Signed-off-by: Christoph Hellwig <hch@lst.de>
Diffstat (limited to 'fs')
-rw-r--r-- | fs/read_write.c | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/fs/read_write.c b/fs/read_write.c index 2c601d853ff3..8f9fc05990ae 100644 --- a/fs/read_write.c +++ b/fs/read_write.c @@ -505,6 +505,8 @@ ssize_t __kernel_write(struct file *file, const void *buf, size_t count, loff_t const char __user *p; ssize_t ret; + if (WARN_ON_ONCE(!(file->f_mode & FMODE_WRITE))) + return -EBADF; if (!(file->f_mode & FMODE_CAN_WRITE)) return -EINVAL; |