From patchwork Wed Apr 24 16:39:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 10915213 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 4783A922 for ; Wed, 24 Apr 2019 16:40:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 348EA286F2 for ; Wed, 24 Apr 2019 16:40:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2403A28751; Wed, 24 Apr 2019 16:40:01 +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 BC1B4286F2 for ; Wed, 24 Apr 2019 16:40:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732608AbfDXQkA (ORCPT ); Wed, 24 Apr 2019 12:40:00 -0400 Received: from mail-wr1-f66.google.com ([209.85.221.66]:38312 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731234AbfDXQj7 (ORCPT ); Wed, 24 Apr 2019 12:39:59 -0400 Received: by mail-wr1-f66.google.com with SMTP id f14so25498382wrj.5; Wed, 24 Apr 2019 09:39:58 -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=zAya8dJlxX/FAf78lvm5vHk9QlU9rxDPHASQ8X4ctWo=; b=cG6faOGpRMM2Fx8iJRuoy1VgPPogTAgVF0OnHIGl9fc+9b0ntg/lLeGczwrfBdfKP1 mjWLODSyWvsooaT/tboZ6qD6WQHaKzDWrLzhqie83NcsLdy/7M3U6h0POfzz20erKS7h 4oGuD4gsvZ24HvRxEDjIawqkZxPWf0U3dqgrujeZRDmNJcvvt3Rj6rwNvMQlpm4zx86x 2+200FVCgbvlvswyouE9zkLbaCHRbVy79DnYto6GycHJH5io38ijUPrrTXpzybN3+Mgy uieyOAQlACsPbD/ZFP+Xu/OGoixCXlexUAI7eIl9a6U17TE8wSxZd3q+og2vOsj5+SHQ KyKQ== 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=zAya8dJlxX/FAf78lvm5vHk9QlU9rxDPHASQ8X4ctWo=; b=Iv05979GhiKmEl4qBbHxlkyuv4Te1x44UhWEV6hOKdaBiTnNG/OQ5WFtIVwO9BkQFA UeEAz9CrPSXg3Y2rfsebi26OjRUYaOUVY2bsayl7infaZdQZve+KnBYZyeSidj9wQYYM Ok/Si8rHOU/LCUpa0btUpb/+G7CW9ZEeAy0kirbAqqeh1gl8HXaxZfOQq0jHRv0TqA24 MqKqloT4gI/Xn95/+/d0mVvVreCjL+mhhysql+TGsMHD8dV5Dg8Kc/CsKQfiPKiGsHmK 2JLoTMHP6RmRT8qPwMHyHji/uFJ+Qj1KJr8I6aZKcZ0Yyxk1/0bu7qhBBkYIZfBTCbkS gu2Q== X-Gm-Message-State: APjAAAVlp4yrjFDK3cI7Smnvms0EfnEhacSQV2WF1GJtv98v4/VB4IJP nELpRmw++DZEDXUPeLw5VNI3NHEe X-Google-Smtp-Source: APXvYqyqpzx8ssZ0/jpnyF2guhsKyM7kMmkZ4aLvjID/TTDHkjKcStzIf7xCKclkTck/TCb3BZX7Mw== X-Received: by 2002:adf:f1ce:: with SMTP id z14mr22926549wro.152.1556123997447; Wed, 24 Apr 2019 09:39:57 -0700 (PDT) Received: from localhost.localdomain ([5.102.238.208]) by smtp.gmail.com with ESMTPSA id r9sm24209131wrv.82.2019.04.24.09.39.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 24 Apr 2019 09:39:56 -0700 (PDT) From: Amir Goldstein To: Miklos Szeredi Cc: Jan Kara , Murphy Zhou , linux-fsdevel@vger.kernel.org, linux-unionfs@vger.kernel.org Subject: [PATCH v2] ovl: do not generate duplicate fsnotify events for "fake" path Date: Wed, 24 Apr 2019 19:39:50 +0300 Message-Id: <20190424163950.14123-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 fsnotify events with path data, because those events have already been generated at overlayfs layer and because the reported event->fd for fanotify marks on underlying inode/filesystem will have the wrong path (the overlayfs path). 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 --- Miklos, V1 was addressed to Jan and was trying to teach fsnotify about fake path. V2 leaves fsnotify subsystem alone and just sets the FMODE_NONOTIFY flag on realfile. All the rest of the complications with mark mounts are irrelevant. Same extended fanotify06 that was used to verify V1 also verified V2. Thanks, Amir. fs/overlayfs/file.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/fs/overlayfs/file.c b/fs/overlayfs/file.c index ddfd93f13cc5..7d2f01957e40 100644 --- a/fs/overlayfs/file.c +++ b/fs/overlayfs/file.c @@ -29,10 +29,11 @@ static struct file *ovl_open_realfile(const struct file *file, struct inode *inode = file_inode(file); struct file *realfile; const struct cred *old_cred; + int flags = file->f_flags | O_NOATIME | FMODE_NONOTIFY; old_cred = ovl_override_creds(inode->i_sb); - realfile = open_with_fake_path(&file->f_path, file->f_flags | O_NOATIME, - realinode, current_cred()); + realfile = open_with_fake_path(&file->f_path, flags, realinode, + current_cred()); revert_creds(old_cred); pr_debug("open(%p[%pD2/%c], 0%o) -> (%p, 0%o)\n", @@ -50,7 +51,7 @@ static int ovl_change_flags(struct file *file, unsigned int flags) int err; /* No atime modificaton on underlying */ - flags |= O_NOATIME; + flags |= O_NOATIME | FMODE_NONOTIFY; /* If some flag changed that cannot be changed then something's amiss */ if (WARN_ON((file->f_flags ^ flags) & ~OVL_SETFL_MASK))