Skip to contentSkip to conversation

vfs: get inode after passing previous check in rw_verify_area()

PATCH Superseded [email protected] 2 participants 3 messages Jun 21, 2018 VFS

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 vfs: get inode after passing previous check in rw_verify_area()

From: Lorne Li <[email protected]>

Move file_inode function to the front of line actually using inode.

---
 fs/read_write.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/read_write.c +1 -1
index 153f8f6..ab63e87 100644
@@ -368,7 +368,6 @@ int rw_verify_area(int read_write, struct file *file, const loff_t *ppos, size_t
 	loff_t pos;
 	int retval = -EINVAL;
 
-	inode = file_inode(file);
 	if (unlikely((ssize_t) count < 0))
 		return retval;
 	pos = *ppos;
@@ -382,6 +381,7 @@ int rw_verify_area(int read_write, struct file *file, const loff_t *ppos, size_t
 			return retval;
 	}
 
+	inode = file_inode(file);
 	if (unlikely(inode->i_flctx && mandatory_lock(inode))) {
 		retval = locks_mandatory_area(inode, file, pos, pos + count - 1,
 				read_write == READ ? F_RDLCK : F_WRLCK);
Signature · 1 line
1.8.3.1
author
#2 lore raw

If previous check (pos and overflow check) fails, there's no chance to

use variable inode, initialized by file_inode func in the beginning.

So delay the operation until actuallyneeding inode for check.

Maybe I should add a more detailed commit message.

Quoted 5 lines · Christoph Hellwig
Quoted 3 lines · On Thu, Jun 21, 2018 at 06:29:33PM +0800, [email protected] wrote:

From: Lorne Li <[email protected]>

Move file_inode function to the front of line actually using inode.

Why?