From patchwork Wed Nov 21 02:43:57 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eiichi Tsukata X-Patchwork-Id: 10691561 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3FD9214E2 for ; Wed, 21 Nov 2018 02:44:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2D2F5290B8 for ; Wed, 21 Nov 2018 02:44:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 20B4529186; Wed, 21 Nov 2018 02:44:22 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9603E290B8 for ; Wed, 21 Nov 2018 02:44:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726343AbeKUNQl (ORCPT ); Wed, 21 Nov 2018 08:16:41 -0500 Received: from mail-pl1-f196.google.com ([209.85.214.196]:41352 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726149AbeKUNQk (ORCPT ); Wed, 21 Nov 2018 08:16:40 -0500 Received: by mail-pl1-f196.google.com with SMTP id u6so3196766plm.8 for ; Tue, 20 Nov 2018 18:44:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=etsukata-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=yt8PoaemXktUDXcbs8OaqA+cqzxKCb1NSTFmw9XeNgE=; b=WzXoUtUTYTJvd8mZcZ+N4A4M5D2PkNCoj+0a3JDsuUgezuaHfxD3I+r+ahpfiN8IvI 5NdgwDlqdBzUWAh48/dx2/5g8GPrEibYmWaOvXhYO625u9su0ReFAleYmYuLeJMCH9T/ XIYI9wDpfS8v9YsvOs/5WPrKtKlmttqjFgWqWTK14I1SRWVjGXcp6K7gtggi2JimjHo3 3gol/Q7Rct8h2E+DAiW+PCHfQFKlFNNTYDf0rUPO6jf9UWogU3yoreeEXPibmQOHaMQO anbg26nRow0gPgyeq/DDhSCd4Ro4z2QbBV6k3824eCVSu3OgBVGgFiYxe4OYB6PCEUe1 Gg+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=yt8PoaemXktUDXcbs8OaqA+cqzxKCb1NSTFmw9XeNgE=; b=VuraOIoDJwa0AkOxnrR1CH0ZPURBbSCPKMdlz9bOfcpyvtJ2DZZ1yjVyoShrbcjNox kuG6ZvfJm1OBVP4cJc9622epzDqObV338LdQomohQbS6UImZX22ofFQ35nF23j6Y7q0G lz2qwxR+droeS+F2ScCuRHK8LmeUr1M1Awa6ZBlJ9iOC6NZRf70iqlEHyNIuK4di5smm 43qxhbV9NW57phL+3NGS0QkqN2UQpETiZI0DDijo+ZtkXLF6n82UL2btfA7JvvWk3LEv 6hOpmyJSl65u/780fBRc+O3LzmhRLShmUKMwU6PFC00JEMboeKHjSNEGQ0jv4XBh0U1E J5Bg== X-Gm-Message-State: AA+aEWb2zlr7agNFq5s0B7oONoN/Yr0Jt/5z+n/loseGWUz30O9Qoz8f kYGoSS7zEFCu00xTiBVypE1XVw== X-Google-Smtp-Source: AJdET5ehuVJicXoRb15dUWz/DbHA4i0uMgWmMn3EBTQmb+nQsB3O9ClZqj6gFRqXTdiqGMl//JfYpw== X-Received: by 2002:a63:4e15:: with SMTP id c21mr4322512pgb.50.1542768258288; Tue, 20 Nov 2018 18:44:18 -0800 (PST) Received: from fedora.fout.local (fs76eecbcd.tkyc008.ap.nuro.jp. [118.238.203.205]) by smtp.gmail.com with ESMTPSA id l63-v6sm46356677pfb.75.2018.11.20.18.44.13 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 20 Nov 2018 18:44:17 -0800 (PST) From: Eiichi Tsukata To: andi@firstfloor.org, Chris Mason , Josef Bacik , David Sterba , "Theodore Ts'o" , Andreas Dilger , Jaegeuk Kim , Chao Yu , Miklos Szeredi , Bob Peterson , Andreas Gruenbacher , Alexander Viro , linux-btrfs@vger.kernel.org, linux-ext4@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, linux-fsdevel@vger.kernel.org, cluster-devel@redhat.com, linux-unionfs@vger.kernel.org Cc: Eiichi Tsukata Subject: [PATCH v1 1/4] vfs: fix race between llseek SEEK_END and write Date: Wed, 21 Nov 2018 11:43:57 +0900 Message-Id: <20181121024400.4346-2-devel@etsukata.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181121024400.4346-1-devel@etsukata.com> References: <20181121024400.4346-1-devel@etsukata.com> MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The commit ef3d0fd27e90 ("vfs: do (nearly) lockless generic_file_llseek") removed almost all locks in llseek() including SEEK_END. It based on the idea that write() updates size atomically. But in fact, write() can be divided into two or more parts in generic_perform_write() when pos straddles over the PAGE_SIZE, which results in updating size multiple times in one write(). It means that llseek() can see the size being updated during write(). This race changes behavior of some applications. 'tail' is one of those applications. It reads range [pos, pos_end] where pos_end is obtained via llseek() SEEK_END. Sometimes, a read line could be broken. reproducer: $ while true; do echo 123456 >> out; done $ while true; do tail out | grep -v 123456 ; done example output(take 30 secs): 12345 1 1234 1 12 1234 This patch re-introduces generic_file_llseek_unlocked() and implements a lock for SEEK_END/DATA/HOLE in generic_file_llseek(). I replaced all generic_file_llseek() callers with _unlocked() if they are called with a inode lock. All file systems which call generic_file_llseek_size() directly are fixed in the later commits. Fixes: ef3d0fd27e90 ("vfs: do (nearly) lockless generic_file_llseek") Signed-off-by: Eiichi Tsukata --- fs/btrfs/file.c | 2 +- fs/fuse/file.c | 5 +++-- fs/gfs2/file.c | 3 ++- fs/read_write.c | 37 ++++++++++++++++++++++++++++++++++--- include/linux/fs.h | 2 ++ 5 files changed, 42 insertions(+), 7 deletions(-) diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c index a3c22e16509b..ec932fa0f8a9 100644 --- a/fs/btrfs/file.c +++ b/fs/btrfs/file.c @@ -3256,7 +3256,7 @@ static loff_t btrfs_file_llseek(struct file *file, loff_t offset, int whence) switch (whence) { case SEEK_END: case SEEK_CUR: - offset = generic_file_llseek(file, offset, whence); + offset = generic_file_llseek_unlocked(file, offset, whence); goto out; case SEEK_DATA: case SEEK_HOLE: diff --git a/fs/fuse/file.c b/fs/fuse/file.c index b52f9baaa3e7..e220b848929b 100644 --- a/fs/fuse/file.c +++ b/fs/fuse/file.c @@ -2336,13 +2336,14 @@ static loff_t fuse_file_llseek(struct file *file, loff_t offset, int whence) case SEEK_SET: case SEEK_CUR: /* No i_mutex protection necessary for SEEK_CUR and SEEK_SET */ - retval = generic_file_llseek(file, offset, whence); + retval = generic_file_llseek_unlocked(file, offset, whence); break; case SEEK_END: inode_lock(inode); retval = fuse_update_attributes(inode, file); if (!retval) - retval = generic_file_llseek(file, offset, whence); + retval = generic_file_llseek_unlocked(file, offset, + whence); inode_unlock(inode); break; case SEEK_HOLE: diff --git a/fs/gfs2/file.c b/fs/gfs2/file.c index 45a17b770d97..171df9550c27 100644 --- a/fs/gfs2/file.c +++ b/fs/gfs2/file.c @@ -66,7 +66,8 @@ static loff_t gfs2_llseek(struct file *file, loff_t offset, int whence) error = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, LM_FLAG_ANY, &i_gh); if (!error) { - error = generic_file_llseek(file, offset, whence); + error = generic_file_llseek_unlocked(file, offset, + whence); gfs2_glock_dq_uninit(&i_gh); } break; diff --git a/fs/read_write.c b/fs/read_write.c index bfcb4ced5664..859dbac5b2f6 100644 --- a/fs/read_write.c +++ b/fs/read_write.c @@ -131,6 +131,24 @@ generic_file_llseek_size(struct file *file, loff_t offset, int whence, } EXPORT_SYMBOL(generic_file_llseek_size); +/** + * generic_file_llseek_unlocked - lockless generic llseek implementation + * @file: file structure to seek on + * @offset: file offset to seek to + * @whence: type of seek + * + */ +loff_t generic_file_llseek_unlocked(struct file *file, loff_t offset, + int whence) +{ + struct inode *inode = file->f_mapping->host; + + return generic_file_llseek_size(file, offset, whence, + inode->i_sb->s_maxbytes, + i_size_read(inode)); +} +EXPORT_SYMBOL(generic_file_llseek_unlocked); + /** * generic_file_llseek - generic llseek implementation for regular files * @file: file structure to seek on @@ -144,10 +162,23 @@ EXPORT_SYMBOL(generic_file_llseek_size); loff_t generic_file_llseek(struct file *file, loff_t offset, int whence) { struct inode *inode = file->f_mapping->host; + loff_t retval; - return generic_file_llseek_size(file, offset, whence, - inode->i_sb->s_maxbytes, - i_size_read(inode)); + switch (whence) { + default: + return generic_file_llseek_unlocked(file, offset, whence); + case SEEK_END: + case SEEK_DATA: + case SEEK_HOLE: + /* + * protects against inode size race with write so that llseek + * doesn't see inode size being updated in write. + */ + inode_lock_shared(inode); + retval = generic_file_llseek_unlocked(file, offset, whence); + inode_unlock_shared(inode); + return retval; + } } EXPORT_SYMBOL(generic_file_llseek); diff --git a/include/linux/fs.h b/include/linux/fs.h index c95c0807471f..ee35d7c013cb 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -3054,6 +3054,8 @@ extern loff_t noop_llseek(struct file *file, loff_t offset, int whence); extern loff_t no_llseek(struct file *file, loff_t offset, int whence); extern loff_t vfs_setpos(struct file *file, loff_t offset, loff_t maxsize); extern loff_t generic_file_llseek(struct file *file, loff_t offset, int whence); +extern loff_t generic_file_llseek_unlocked(struct file *file, loff_t offset, + int whence); extern loff_t generic_file_llseek_size(struct file *file, loff_t offset, int whence, loff_t maxsize, loff_t eof); extern loff_t fixed_size_llseek(struct file *file, loff_t offset, From patchwork Wed Nov 21 02:43:58 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eiichi Tsukata X-Patchwork-Id: 10691565 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E159C16B1 for ; Wed, 21 Nov 2018 02:44:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CE915290B8 for ; Wed, 21 Nov 2018 02:44:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C2C7F29186; Wed, 21 Nov 2018 02:44:27 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7772D290B8 for ; Wed, 21 Nov 2018 02:44:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726554AbeKUNQr (ORCPT ); Wed, 21 Nov 2018 08:16:47 -0500 Received: from mail-pl1-f193.google.com ([209.85.214.193]:35875 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726406AbeKUNQr (ORCPT ); Wed, 21 Nov 2018 08:16:47 -0500 Received: by mail-pl1-f193.google.com with SMTP id y6-v6so3201950plt.3 for ; Tue, 20 Nov 2018 18:44:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=etsukata-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=o4bI2dtYrGOAUpbYMucH7yfA9XmsvLCuXCvEpdFsK7M=; b=OUz7eIz3RPAgFBe6iyTWlhqJq25rEkkQVokaXHn0D+mWM70F4kZjqQb2dqZy/lxugF jhXK2tF+Ck1TZMK7HFEXlfsxy+TYrcAmWieaccXdwSL7Rn/lJSscu65AEK9sYJEnMIuv UwDqVIhtaPMh3TtwSzBeCav8boZZdXg6u8utPUG5KK1OigOrSYuVqABYmkPOG5Sn+buN gSNVF45TxTIih6RiIxRZ/bxhwezWW73wNZ+THeTWJvvHHPspV16Yj1aTqvcM9DCusLYf VJ49Vs0dnuc3w3wqB4cS16AjH2DMrAVL99EkyUI3N5YgT60U+jdD5mmU4anM4SXCEwtH E1cw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=o4bI2dtYrGOAUpbYMucH7yfA9XmsvLCuXCvEpdFsK7M=; b=lOMAOuWYBGuQm+XJbgHFG1P7SCzxKoh/4CnhbVSjybUa2EzGMPMymJPyPCZtvD5Qfx 3/wVZ+bRd6m1ddTxtIr4akn1NEOFj9e75lZFCb1FlMqN2OON5BCBf6JV697oJPjIbDxf 52BMoBhl78qdSr+uqTcFZu9eHTJVvuAAO7xNKKCoKraAqYyTCqfrYj7yLyInv+rpfkkC Q/h+x1nl+py92EbWC4oOC28nqMp0P+XGJLYccFicNMmKLWNBYWihJnXUO1rbi+HzY/Ao UPqbXUMRhiVIdfzef9cnNs1dWuhbxLjXvQcCxTwnK5mAAo99t1abRrewvOlKYrbeMEpI pt1Q== X-Gm-Message-State: AA+aEWZOepWURjyZA9oHiwJYqwFeizQU88X1pEnLt7TfXcDkqK175ZzT w5UbWioUj4+zaJB66zdywAVL5g== X-Google-Smtp-Source: AFSGD/We3KVL/NQp518ltKarCdUcQa3Qe0SZqlTIBGxQcTgQjhTgsXupL+rS4fNnjpR9PsQxYBpHfQ== X-Received: by 2002:a63:df50:: with SMTP id h16mr4319304pgj.421.1542768264717; Tue, 20 Nov 2018 18:44:24 -0800 (PST) Received: from fedora.fout.local (fs76eecbcd.tkyc008.ap.nuro.jp. [118.238.203.205]) by smtp.gmail.com with ESMTPSA id l63-v6sm46356677pfb.75.2018.11.20.18.44.18 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 20 Nov 2018 18:44:24 -0800 (PST) From: Eiichi Tsukata To: andi@firstfloor.org, Chris Mason , Josef Bacik , David Sterba , "Theodore Ts'o" , Andreas Dilger , Jaegeuk Kim , Chao Yu , Miklos Szeredi , Bob Peterson , Andreas Gruenbacher , Alexander Viro , linux-btrfs@vger.kernel.org, linux-ext4@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, linux-fsdevel@vger.kernel.org, cluster-devel@redhat.com, linux-unionfs@vger.kernel.org Cc: Eiichi Tsukata Subject: [PATCH v1 2/4] ext4: fix race between llseek SEEK_END and write Date: Wed, 21 Nov 2018 11:43:58 +0900 Message-Id: <20181121024400.4346-3-devel@etsukata.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181121024400.4346-1-devel@etsukata.com> References: <20181121024400.4346-1-devel@etsukata.com> MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Implement individual lock for SEEK_END for ext4 which directly calls generic_file_llseek_size(). Signed-off-by: Eiichi Tsukata --- fs/ext4/file.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/fs/ext4/file.c b/fs/ext4/file.c index 69d65d49837b..6479f3066043 100644 --- a/fs/ext4/file.c +++ b/fs/ext4/file.c @@ -477,6 +477,16 @@ loff_t ext4_llseek(struct file *file, loff_t offset, int whence) default: return generic_file_llseek_size(file, offset, whence, maxbytes, i_size_read(inode)); + case SEEK_END: + /* + * protects against inode size race with write so that llseek + * doesn't see inode size being updated in generic_perform_write + */ + inode_lock_shared(inode); + offset = generic_file_llseek_size(file, offset, whence, + maxbytes, i_size_read(inode)); + inode_unlock_shared(inode); + return offset; case SEEK_HOLE: inode_lock_shared(inode); offset = iomap_seek_hole(inode, offset, &ext4_iomap_ops); From patchwork Wed Nov 21 02:43:59 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eiichi Tsukata X-Patchwork-Id: 10691573 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 27A8A14E2 for ; Wed, 21 Nov 2018 02:44:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 14490290B8 for ; Wed, 21 Nov 2018 02:44:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 04E0629232; Wed, 21 Nov 2018 02:44:42 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9AC82290B8 for ; Wed, 21 Nov 2018 02:44:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726605AbeKUNQw (ORCPT ); Wed, 21 Nov 2018 08:16:52 -0500 Received: from mail-pl1-f193.google.com ([209.85.214.193]:42895 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726603AbeKUNQw (ORCPT ); Wed, 21 Nov 2018 08:16:52 -0500 Received: by mail-pl1-f193.google.com with SMTP id x21-v6so3191368pln.9 for ; Tue, 20 Nov 2018 18:44:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=etsukata-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=S98AfvktK5ubznf+7tPpcMB3RtXLxMLR6IfafpV0zKk=; b=MctSODymScBuzbx1+dDPa9v56o9gD57nrquuXfOeQULzH/WJok3qX9EIWI+17fyejf YGsOHW4U2G6Yytw8c7Iv2R+VtTD5N5f/MwzSZNA9qEW+aSE6w4JPtK93hGbg0WrkRohl +onbDDlihN0knzxF/xksLrmLUBiY4tbJe9NYa5zVV9bV382Rrs8kPaXuged6X3RWPeQq qrYJYF46HStnFlSV6NZFg3j9MvOCqang4naUmtcFpb1D4+7khtbHqv9cQoCSuNyT4NYC NkSro/Q/8IQg9hVNLBwuR/FTr+us0+JiZEMDMV3YxifKQN5761JeTqE4KK8obgf0Ft2f q++g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=S98AfvktK5ubznf+7tPpcMB3RtXLxMLR6IfafpV0zKk=; b=Edm+qboyhPEtIBVAxC/fdytZt7gcwiFUF7J0imn+UaktUbh+65ZANk1qLaHnCiWUZE BBR3X+mOw/cdF9Y96mpbjJqSrsPxNHy/Hn6tJSE2EoWGCfGHjIjGFGO6hy10dn06yh3V +9dYcO2rZO+36+ymRdiUqfreB0W3c4xjRvrzY9bZKON0yUbnajzAW7yofJKRqS3dfM17 k8CU40cszF6qV5SRWsH/7PvclE6vvDeOu58klfdBRhxLDNsbwj/rqeZ4y5oPgCx1tfnI OoM6x3tbgCP6Foop/cy3q41I8PEMi1vVLrq4HcrCe34zDNtxeoNEu+SJ9LLlF1l3OmyJ TClQ== X-Gm-Message-State: AA+aEWaAGAjMwKbhWVINAi24RiWc83u/91kXOMipQyw7MXIfWv4M0HBz DHM3waMG/Cf4GR27hzk07NCnuw== X-Google-Smtp-Source: AFSGD/XiiUFmvgYaucgphQWKiIX3V6pLpVlSIfA+n1TJa6RGP1bQ1zL6qQB1pi6O4YiOq/9A4vsZ/A== X-Received: by 2002:a17:902:a70b:: with SMTP id w11mr4857981plq.84.1542768269956; Tue, 20 Nov 2018 18:44:29 -0800 (PST) Received: from fedora.fout.local (fs76eecbcd.tkyc008.ap.nuro.jp. [118.238.203.205]) by smtp.gmail.com with ESMTPSA id l63-v6sm46356677pfb.75.2018.11.20.18.44.24 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 20 Nov 2018 18:44:29 -0800 (PST) From: Eiichi Tsukata To: andi@firstfloor.org, Chris Mason , Josef Bacik , David Sterba , "Theodore Ts'o" , Andreas Dilger , Jaegeuk Kim , Chao Yu , Miklos Szeredi , Bob Peterson , Andreas Gruenbacher , Alexander Viro , linux-btrfs@vger.kernel.org, linux-ext4@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, linux-fsdevel@vger.kernel.org, cluster-devel@redhat.com, linux-unionfs@vger.kernel.org Cc: Eiichi Tsukata Subject: [PATCH v1 3/4] f2fs: fix race between llseek SEEK_END and write Date: Wed, 21 Nov 2018 11:43:59 +0900 Message-Id: <20181121024400.4346-4-devel@etsukata.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181121024400.4346-1-devel@etsukata.com> References: <20181121024400.4346-1-devel@etsukata.com> MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch itself seems to be just a cleanup but with the commit b25bd1d9fd87 ("vfs: fix race between llseek SEEK_END and write") it fixes race. Signed-off-by: Eiichi Tsukata --- fs/f2fs/file.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index 88b124677189..14a923607eff 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -447,15 +447,11 @@ static loff_t f2fs_seek_block(struct file *file, loff_t offset, int whence) static loff_t f2fs_llseek(struct file *file, loff_t offset, int whence) { - struct inode *inode = file->f_mapping->host; - loff_t maxbytes = inode->i_sb->s_maxbytes; - switch (whence) { case SEEK_SET: case SEEK_CUR: case SEEK_END: - return generic_file_llseek_size(file, offset, whence, - maxbytes, i_size_read(inode)); + return generic_file_llseek(file, offset, whence); case SEEK_DATA: case SEEK_HOLE: if (offset < 0) From patchwork Wed Nov 21 02:44:00 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eiichi Tsukata X-Patchwork-Id: 10691571 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 81B5B17FE for ; Wed, 21 Nov 2018 02:44:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6F58B2917F for ; Wed, 21 Nov 2018 02:44:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 639C829232; Wed, 21 Nov 2018 02:44:37 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1B7022917F for ; Wed, 21 Nov 2018 02:44:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726736AbeKUNQ6 (ORCPT ); Wed, 21 Nov 2018 08:16:58 -0500 Received: from mail-pl1-f196.google.com ([209.85.214.196]:32811 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725995AbeKUNQ5 (ORCPT ); Wed, 21 Nov 2018 08:16:57 -0500 Received: by mail-pl1-f196.google.com with SMTP id z23so3213978plo.0 for ; Tue, 20 Nov 2018 18:44:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=etsukata-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=roGZa/MKql6l9BK2xvgfzkfB6UbYkloVfkrOARQfiPM=; b=L6mImjkxHwhkz5MgjbWQs1Bdl5HixsFOnS+PVuyYdbb//OsZhhZL3QReo/ycJEvUXf 52is2GuKGOF4FkREwDqE4dLAEaf66a5SgW3MVhue7Gz0B+oPs9REvOFLjsDwT8q8xeB4 h8koNaszwHNTBxst9A9uMusjxsS6Emb+qVfUzut83SW3eAWCF+fwMvVEd9Sm/Yikw+9o 61tnzlt+5LxImfOeqsUGw8476I/uY+B1uoIvY6N7pduX92/zlRR4k5PiBWLph7kBQWp8 UuGm+OSk9AOw165scmoA6lELO1w9oqPnDQQhdDm63WH2cTJPptto9Sv5VcpdoBf9nU9O k8PQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=roGZa/MKql6l9BK2xvgfzkfB6UbYkloVfkrOARQfiPM=; b=A0F15rDUFxVmeW1p5mkV2x/0VFnhuG3GW7rzLM8mqWBial0CI4cqG9LeWqiXSkemHK jlPP19Keg9lT2Qrmz3Kr/kEpKPFVk4Y7y9cayB3+5YBZy48jFxya3riXqUnyFeQox5fM GGIkvUk8elM01RY9khubnqzDFZcFW9992ng2t1SSXGGUmJX8vBYr/rWa83wBAop2fs2n NHwRH4xbphZ1o7Tyb5LZ37oKn1cP4apVqCxXND2i9x/G3fNuBcsGBfDoHkym+1MfbeSs HDOAbl/PXQ0WTIFhdfdD4kaS8lDQX3OhbRsV3HBRTghOdQLSbmNYrTyyEa/sXU0xnLxV gFSQ== X-Gm-Message-State: AGRZ1gJynfdv1UhRfLUAmUUurOq3USuHXpQFCn+YqQ+J2bg3D4EJQBFR B+ySxuDAClFfGMrfs5kvIRLobA== X-Google-Smtp-Source: AJdET5c3PaB5bn7Jr0K2IjCIQuZpxqik+trbni3tBVgegGEJxUc4B/4QOTzlnS97VODoqDX5Y+Tb5w== X-Received: by 2002:a62:2ad6:: with SMTP id q205-v6mr4857372pfq.152.1542768275274; Tue, 20 Nov 2018 18:44:35 -0800 (PST) Received: from fedora.fout.local (fs76eecbcd.tkyc008.ap.nuro.jp. [118.238.203.205]) by smtp.gmail.com with ESMTPSA id l63-v6sm46356677pfb.75.2018.11.20.18.44.30 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 20 Nov 2018 18:44:34 -0800 (PST) From: Eiichi Tsukata To: andi@firstfloor.org, Chris Mason , Josef Bacik , David Sterba , "Theodore Ts'o" , Andreas Dilger , Jaegeuk Kim , Chao Yu , Miklos Szeredi , Bob Peterson , Andreas Gruenbacher , Alexander Viro , linux-btrfs@vger.kernel.org, linux-ext4@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, linux-fsdevel@vger.kernel.org, cluster-devel@redhat.com, linux-unionfs@vger.kernel.org Cc: Eiichi Tsukata Subject: [PATCH v1 4/4] overlayfs: fix race between llseek SEEK_END and write Date: Wed, 21 Nov 2018 11:44:00 +0900 Message-Id: <20181121024400.4346-5-devel@etsukata.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181121024400.4346-1-devel@etsukata.com> References: <20181121024400.4346-1-devel@etsukata.com> MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Implement individual lock for SEEK_END for overlayfs which directly calls generic_file_llseek_size(). Signed-off-by: Eiichi Tsukata --- fs/overlayfs/file.c | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/fs/overlayfs/file.c b/fs/overlayfs/file.c index 84dd957efa24..57bc6538eea8 100644 --- a/fs/overlayfs/file.c +++ b/fs/overlayfs/file.c @@ -146,10 +146,27 @@ static int ovl_release(struct inode *inode, struct file *file) static loff_t ovl_llseek(struct file *file, loff_t offset, int whence) { struct inode *realinode = ovl_inode_real(file_inode(file)); + loff_t ret; - return generic_file_llseek_size(file, offset, whence, - realinode->i_sb->s_maxbytes, - i_size_read(realinode)); + switch (whence) { + default: + return generic_file_llseek_size(file, offset, whence, + realinode->i_sb->s_maxbytes, + i_size_read(realinode)); + case SEEK_END: + case SEEK_DATA: + case SEEK_HOLE: + /* + * protects against inode size race with write so that llseek + * doesn't see inode size being updated in individual fs write + */ + inode_lock(realinode); + ret = generic_file_llseek_size(file, offset, whence, + realinode->i_sb->s_maxbytes, + i_size_read(realinode)); + inode_unlock(realinode); + return ret; + } } static void ovl_file_accessed(struct file *file)