From patchwork Tue Apr 23 06:50:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Murphy Zhou X-Patchwork-Id: 10912019 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 E1103112C for ; Tue, 23 Apr 2019 06:51:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D0D3728739 for ; Tue, 23 Apr 2019 06:51:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C4553287ED; Tue, 23 Apr 2019 06:51:25 +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_ADSP_CUSTOM_MED, FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham 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 61B2728739 for ; Tue, 23 Apr 2019 06:51:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726213AbfDWGvY (ORCPT ); Tue, 23 Apr 2019 02:51:24 -0400 Received: from mx1.redhat.com ([209.132.183.28]:42866 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725946AbfDWGvY (ORCPT ); Tue, 23 Apr 2019 02:51:24 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B9A2B3082263; Tue, 23 Apr 2019 06:51:23 +0000 (UTC) Received: from localhost (dhcp-12-130.nay.redhat.com [10.66.12.130]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2F9D85D71E; Tue, 23 Apr 2019 06:51:22 +0000 (UTC) From: Murphy Zhou To: miklos@szeredi.hu, linux-unionfs@vger.kernel.org, linux-fsdevel@vger.kernel.org Cc: amir73il@gmail.com, Murphy Zhou Subject: [PATCH] ovl: add RWF_NONITIFY flag to skip wrong duplicate fanotify event Date: Tue, 23 Apr 2019 14:50:24 +0800 Message-Id: <20190423065024.12695-1-jencce.kernel@gmail.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Tue, 23 Apr 2019 06:51:24 +0000 (UTC) Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Overlays ovl_iter_write calls vfs_iter_write to write on real file, in which calls fsnotify_modify on this change, however vfs_write also calls fsnotify_modify after ovl_iter_write. The first notification sent by vfs_iter_write grabs marks from upper inode and overlay mnt, because of its fake path. The second one sent by vfs_write grabs marks from ovl inode and ovl mnt. LTP fanotify06 add modify mark for mnt point, then add ignore modify mask on testfile, then truncate and write the file. Because the ignore mask is marked on ovl inode, not the upper inode, the first event is not masked like the second one. So we get a modification event even with a mask on the file. Proposing fixing this by add a new RWF flag to skip fsnotify on this IO. vfs_iter_write used by ovl can use this flag to skip one duplicate event. Signed-off-by: Murphy Zhou Reported-by: Murphy Zhou Signed-off-by: Amir Goldstein Reported-by: Murphy Zhou Signed-off-by: Amir Goldstein --- fs/overlayfs/file.c | 2 +- fs/read_write.c | 2 +- include/uapi/linux/fs.h | 5 ++++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/fs/overlayfs/file.c b/fs/overlayfs/file.c index 84dd957efa24..0827199a5311 100644 --- a/fs/overlayfs/file.c +++ b/fs/overlayfs/file.c @@ -242,7 +242,7 @@ static ssize_t ovl_write_iter(struct kiocb *iocb, struct iov_iter *iter) old_cred = ovl_override_creds(file_inode(file)->i_sb); file_start_write(real.file); ret = vfs_iter_write(real.file, iter, &iocb->ki_pos, - ovl_iocb_to_rwf(iocb)); + ovl_iocb_to_rwf(iocb)|RWF_NONOTIFY); file_end_write(real.file); revert_creds(old_cred); diff --git a/fs/read_write.c b/fs/read_write.c index 61b43ad7608e..aec751cacedf 100644 --- a/fs/read_write.c +++ b/fs/read_write.c @@ -957,7 +957,7 @@ static ssize_t do_iter_write(struct file *file, struct iov_iter *iter, ret = do_iter_readv_writev(file, iter, pos, WRITE, flags); else ret = do_loop_readv_writev(file, iter, pos, WRITE, flags); - if (ret > 0) + if (ret > 0 && !(flags & RWF_NONOTIFY)) fsnotify_modify(file); return ret; } diff --git a/include/uapi/linux/fs.h b/include/uapi/linux/fs.h index 121e82ce296b..103f1a9375f2 100644 --- a/include/uapi/linux/fs.h +++ b/include/uapi/linux/fs.h @@ -342,8 +342,11 @@ typedef int __bitwise __kernel_rwf_t; /* per-IO O_APPEND */ #define RWF_APPEND ((__force __kernel_rwf_t)0x00000010) +/* do not notify this IO */ +#define RWF_NONOTIFY ((__force __kernel_rwf_t)0x00000020) + /* mask of flags supported by the kernel */ #define RWF_SUPPORTED (RWF_HIPRI | RWF_DSYNC | RWF_SYNC | RWF_NOWAIT |\ - RWF_APPEND) + RWF_APPEND | RWF_NONOTIFY) #endif /* _UAPI_LINUX_FS_H */