Skip to content

Commit a01ac27

Browse files
author
Christoph Hellwig
committed
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 <[email protected]>
1 parent 9db9775 commit a01ac27

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

fs/read_write.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,8 @@ ssize_t __kernel_write(struct file *file, const void *buf, size_t count, loff_t
505505
const char __user *p;
506506
ssize_t ret;
507507

508+
if (WARN_ON_ONCE(!(file->f_mode & FMODE_WRITE)))
509+
return -EBADF;
508510
if (!(file->f_mode & FMODE_CAN_WRITE))
509511
return -EINVAL;
510512

0 commit comments

Comments
 (0)