Return-Path: Received: from mail-pg0-f68.google.com ([74.125.83.68]:46219 "EHLO mail-pg0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751752AbeFYGuW (ORCPT ); Mon, 25 Jun 2018 02:50:22 -0400 Received: by mail-pg0-f68.google.com with SMTP id q14-v6so1882626pgt.13 for ; Sun, 24 Jun 2018 23:50:22 -0700 (PDT) From: lorneli.cs@gmail.com To: viro@zeniv.linux.org.uk Cc: linux-fsdevel@vger.kernel.org, axboe@kernel.dk, hch@infradead.org, jmorris@namei.org, Lorne Li Subject: [PATCH v2] vfs: get inode after passing previous check in rw_verify_area() Date: Mon, 25 Jun 2018 14:50:15 +0800 Message-Id: <1529909415-2923-1-git-send-email-lorneli.cs@gmail.com> Sender: linux-fsdevel-owner@vger.kernel.org List-ID: From: Lorne Li If previous check (pos and overflow check) fails, there's no chance to use local variable inode, initialized by file_inode() in the beginning of rw_verify_area(). So delay getting inode until actually needing it for check. Signed-off-by: Lorne Li --- fs/read_write.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/read_write.c b/fs/read_write.c index 153f8f6..ab63e87 100644 --- a/fs/read_write.c +++ b/fs/read_write.c @@ -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); -- 1.8.3.1