From patchwork Wed Apr 24 10:09:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 10914435 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 3C5B91515 for ; Wed, 24 Apr 2019 10:10:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2B54628698 for ; Wed, 24 Apr 2019 10:10:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1D8E9288D1; Wed, 24 Apr 2019 10:10:02 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,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 A811D28698 for ; Wed, 24 Apr 2019 10:10:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727645AbfDXKKB (ORCPT ); Wed, 24 Apr 2019 06:10:01 -0400 Received: from mail-wm1-f66.google.com ([209.85.128.66]:54117 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727625AbfDXKKA (ORCPT ); Wed, 24 Apr 2019 06:10:00 -0400 Received: by mail-wm1-f66.google.com with SMTP id q16so3820142wmj.3; Wed, 24 Apr 2019 03:09:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=igx2IARgHoJkTDb+8iMvDevmkxjLQ6tV7UkFj4QTLa8=; b=nMfVgilCKTx7uT3RGiKP+arpCg3lt4VWPvLFHTdEMrKkaCwv7lg/hbspUZqWL6OZM8 fo0l1AYJF1q53ic5d5dRt0uijzpyGwKGnbK4AvVCiD7GocRVt9Ggfl/zEZnp0AnpzY3v x8SZM7LJgJ/2m/5wX5kX/tsTeFg08n8ipK28H5QpjGXwTb22IVakYIBGCOH/nlrL59Cn ZWY5XWQyM/wPxEhHtH4Kffi+ziyfpljVg9Y/3ev5Ez/HSyFoYZ1zZHwduwgouCXLXuFV L1C5T1/syPcu1XmUAAk0ojuEFJ6Zlj75BkVNnkjEHynjX0OnK1uWDojLxmceBymnTnaT ljkw== 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; bh=igx2IARgHoJkTDb+8iMvDevmkxjLQ6tV7UkFj4QTLa8=; b=WFOuhytHjfsloe65+0q+TOhvMv2B+S/RjB7QjDud9leqvr06vIko5Ol3qDs6JVlnl/ +gK1ZmHzRU/ZhvpHdDVMgLucoNUrEyAaGL1zgvlkvdzV7c3y9b80oHndEocZv0bcR5Rd Yo/vLtG3QSKZT/E4t6TxGcq0stD3zUZdLLKPh0orcgkTGuJ7am7vhc0AfYQgLNOmfDdz 6zx2fCis1B6Eip28Feao6QRb90jbz99vvwftqyAzPluyDeoOCOAS883nutRD02mZujux gju5poWQjVhvt9XVjGk3bopprpfeQpcKpOI+f25xxtVa8YLGbfBS0bH+NqVOECpyuoNc e1tA== X-Gm-Message-State: APjAAAU5K0XjTGYrWwxjlayKJ+INYoZgtz0XqOcGqxVP4lfw6BHx2bbt b0sZlc7gzlCVDTFUEVciD7E= X-Google-Smtp-Source: APXvYqwGQ+UPY2yjCPlWQW2/yIVIFivASGRTE9JsDEuHtAs/jf9/AX/P/qK2w5a/BcRMTiltT9DIQg== X-Received: by 2002:a7b:cd08:: with SMTP id f8mr5750898wmj.86.1556100598620; Wed, 24 Apr 2019 03:09:58 -0700 (PDT) Received: from localhost.localdomain ([5.102.238.208]) by smtp.gmail.com with ESMTPSA id c139sm3129542wmd.26.2019.04.24.03.09.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 24 Apr 2019 03:09:57 -0700 (PDT) From: Amir Goldstein To: Jan Kara Cc: Murphy Zhou , Miklos Szeredi , linux-fsdevel@vger.kernel.org, linux-unionfs@vger.kernel.org Subject: [PATCH] fsnotify: do not generate duplicate events for "fake" path Date: Wed, 24 Apr 2019 13:09:51 +0300 Message-Id: <20190424100951.16678-1-amir73il@gmail.com> X-Mailer: git-send-email 2.17.1 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 Overlayfs "fake" path is used for stacked file operations on underlying files. Operations on files with "fake" path must not generate events on mount marks and on parent watches, because those events have already been generated at overlayfs layer. The reported event->fd for inode/sb marks will have the wrong path (overlayfs path), but we have no choice but to report them anyway. Link: https://lore.kernel.org/linux-fsdevel/20190423065024.12695-1-jencce.kernel@gmail.com/ Reported-by: Murphy Zhou Fixes: d1d04ef8572b ("ovl: stack file ops") Signed-off-by: Amir Goldstein --- Jan, This is a slightly simplified and cleaner version of the patch I posted yesterday on the linked bug report thread. I have posted an additional overlayfs test case to fanotify06 on LTP list. Thanks, Amir. fs/notify/fsnotify.c | 3 ++- include/linux/fsnotify.h | 23 ++++++++++++++++++++--- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/fs/notify/fsnotify.c b/fs/notify/fsnotify.c index df06f3da166c..6f752b13e3fd 100644 --- a/fs/notify/fsnotify.c +++ b/fs/notify/fsnotify.c @@ -334,7 +334,8 @@ int fsnotify(struct inode *to_tell, __u32 mask, const void *data, int data_is, int ret = 0; __u32 test_mask = (mask & ALL_FSNOTIFY_EVENTS); - if (data_is == FSNOTIFY_EVENT_PATH) { + if (data_is == FSNOTIFY_EVENT_PATH && + !fsnotify_is_fake_path(to_tell, data)) { mnt = real_mount(((const struct path *)data)->mnt); mnt_or_sb_mask |= mnt->mnt_fsnotify_mask; } diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h index 09587e2860b5..c51f57d3a025 100644 --- a/include/linux/fsnotify.h +++ b/include/linux/fsnotify.h @@ -40,6 +40,20 @@ static inline int fsnotify_parent(const struct path *path, return __fsnotify_parent(path, dentry, mask); } +/* + * Overlayfs "fake" path is used for stacked file operations on underlying + * files. file->f_path is from overlayfs layer and file->f_inode is from + * underlying layer. We must not generate events on mount and on parent + * based on fake path, because those events have already been generated at + * overlayfs layer. The reported event->fd for inode/sb marks will have the + * wrong path (overlayfs path), but we have no choice but to report them as is. + */ +static inline bool fsnotify_is_fake_path(struct inode *inode, + const struct path *path) +{ + return unlikely(inode->i_sb != path->dentry->d_sb); +} + /* * Simple wrapper to consolidate calls fsnotify_parent()/fsnotify() when * an event is on a path. @@ -47,10 +61,13 @@ static inline int fsnotify_parent(const struct path *path, static inline int fsnotify_path(struct inode *inode, const struct path *path, __u32 mask) { - int ret = fsnotify_parent(path, NULL, mask); + if (!fsnotify_is_fake_path(inode, path)) { + int ret = fsnotify_parent(path, NULL, mask); + + if (ret) + return ret; + } - if (ret) - return ret; return fsnotify(inode, mask, path, FSNOTIFY_EVENT_PATH, NULL, 0); }