mirror of
				https://github.com/torvalds/linux.git
				synced 2025-11-04 10:40:15 +02:00 
			
		
		
		
	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>
This commit is contained in:
		
							parent
							
								
									9db9775224
								
							
						
					
					
						commit
						a01ac27be4
					
				
					 1 changed files with 2 additions and 0 deletions
				
			
		| 
						 | 
					@ -505,6 +505,8 @@ ssize_t __kernel_write(struct file *file, const void *buf, size_t count, loff_t
 | 
				
			||||||
	const char __user *p;
 | 
						const char __user *p;
 | 
				
			||||||
	ssize_t ret;
 | 
						ssize_t ret;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (WARN_ON_ONCE(!(file->f_mode & FMODE_WRITE)))
 | 
				
			||||||
 | 
							return -EBADF;
 | 
				
			||||||
	if (!(file->f_mode & FMODE_CAN_WRITE))
 | 
						if (!(file->f_mode & FMODE_CAN_WRITE))
 | 
				
			||||||
		return -EINVAL;
 | 
							return -EINVAL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue