From patchwork Sun Dec 2 11:38:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 10707993 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 4CBC016B1 for ; Sun, 2 Dec 2018 11:38:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3F3BA2AEB6 for ; Sun, 2 Dec 2018 11:38:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 339D92AEFE; Sun, 2 Dec 2018 11:38:59 +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 C1F252AEBA for ; Sun, 2 Dec 2018 11:38:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725877AbeLBLjA (ORCPT ); Sun, 2 Dec 2018 06:39:00 -0500 Received: from mail-wm1-f68.google.com ([209.85.128.68]:52439 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725858AbeLBLjA (ORCPT ); Sun, 2 Dec 2018 06:39:00 -0500 Received: by mail-wm1-f68.google.com with SMTP id r11-v6so2994147wmb.2; Sun, 02 Dec 2018 03:38:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=7LpnNZhWvMJg/vdPbz8Vjnr7kqfFnYmS4jP0kp7KiGI=; b=LG9SQ1JrT2zcDfNs3wVheomARis3lnZ9L5OeHZR8F59YGLQd8kcEtfGb12AJKYiAye KIC8NIaWLeL7EPbgQI+bGE2e7Yjb+5ME06cOCxeBdKFlv4ZQ4tAs0QPppgYWho2uIUC+ cewvwtLybwGX8vV41LxuDfbC6Gmzt/NriSr9weACv+uHfPFcM5PzeV8XzwmHLFsdz1jT EZt+zOW7LjXMKv9geqWxXxVxXjc9idAkEF8M6SBiV25w9lF+r8pklBAUacjJd0yVre1u RpQl3XGfhv5fpS0kaKmRdUkQrzPpR0j4db1wwlMb/F4MttU+DpEsrPOl4/Y+0qohQYJK 5G7w== 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; bh=7LpnNZhWvMJg/vdPbz8Vjnr7kqfFnYmS4jP0kp7KiGI=; b=RiVrRe+uaVHC7QpYSEVtMgfXUW2tXI4+H5u/srD4WN+JWESlRIwDeUz77WvVFytH/O SlVLb5Vkdo8I6l9o92Ik/s1i2F2dMardH68WnbMfdQlZaL07YHfasz2wBF5Z7zRSTMFa l4avIKbjb495m1SI7TESnonAMqq9T8u+5xXsepScL8UJ/OheHGRCQZbuyfV1NtPMeejo g9jRaeR7CN59vCjRFHpvgXI8TbHPyihBsaeLq7yDPHmy/UJBE+KdKgbDcmQVrsz9eT6p eMg8i5g45I8uRxWGm3bQsUxGnJiqQahOWj2d3WsJCXs9/VLeycFl69cz+Rdpuh3YL/mB 4eww== X-Gm-Message-State: AA+aEWaYoYst6ueXluGyilyf7tezJptddy+vDiKb3YUH18U/Yhe6q3WR M3cS0OyC4cCI18AYbaf+8Hg= X-Google-Smtp-Source: AFSGD/VKQvRkTWwj4tl9Cqm+wKh95a1YEknPc369BDW78TrVep6WnglULe391g80cfsX3CnL0Mvaig== X-Received: by 2002:a1c:150d:: with SMTP id 13mr4716999wmv.104.1543750735471; Sun, 02 Dec 2018 03:38:55 -0800 (PST) Received: from localhost.localdomain (bzq-166-168-31-246.red.bezeqint.net. [31.168.166.246]) by smtp.gmail.com with ESMTPSA id c3-v6sm3448672wmb.46.2018.12.02.03.38.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 02 Dec 2018 03:38:54 -0800 (PST) From: Amir Goldstein To: Jan Kara Cc: Matthew Bobrowski , linux-fsdevel@vger.kernel.org, linux-api@vger.kernel.org Subject: [PATCH v4 15/15] fanotify: report FAN_ONDIR to listener with FAN_REPORT_FID Date: Sun, 2 Dec 2018 13:38:26 +0200 Message-Id: <20181202113826.32133-16-amir73il@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181202113826.32133-1-amir73il@gmail.com> References: <20181202113826.32133-1-amir73il@gmail.com> 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 dirent modification events (create/delete/move) do not carry the child entry name/inode information. Instead, we report FAN_ONDIR for mkdir/rmdir so user can differentiate them from creat/unlink. For backward compatibility and consistency, do not report FAN_ONDIR to user in legacy fanotify mode (reporting fd) and report FAN_ONDIR to user in FAN_REPORT_FID mode for all event types. Unlike legacy fanotify events (open/access/close), dirent events for subdir entries (mkdir/rmdir) will be reported regardless if user requested FAN_ONDIR, but the FAN_ONDIR flag itself will only be reported if the user asked for it. Cc: Signed-off-by: Amir Goldstein --- fs/notify/fanotify/fanotify.c | 31 +++++++++++++++++++++++++++++-- include/linux/fanotify.h | 9 ++++++--- 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/fs/notify/fanotify/fanotify.c b/fs/notify/fanotify/fanotify.c index 89c19db4d45f..1aa23cefae5d 100644 --- a/fs/notify/fanotify/fanotify.c +++ b/fs/notify/fanotify/fanotify.c @@ -112,6 +112,7 @@ static u32 fanotify_group_event_mask(struct fsnotify_group *group, int data_type) { __u32 marks_mask = 0, marks_ignored_mask = 0; + __u32 test_mask, user_mask = FANOTIFY_EVENT_TYPES; const struct path *path = data; struct fsnotify_mark *mark; int type; @@ -145,12 +146,38 @@ static u32 fanotify_group_event_mask(struct fsnotify_group *group, marks_ignored_mask |= mark->ignored_mask; } + test_mask = event_mask & marks_mask & ~marks_ignored_mask; + + /* + * dirent modification events (create/delete/move) do not carry the + * child entry name/inode information. Instead, we report FAN_ONDIR + * for mkdir/rmdir so user can differentiate them from creat/unlink. + * + * For backward compatibility and consistency, do not report FAN_ONDIR + * to user in legacy fanotify mode (reporting fd) and report FAN_ONDIR + * to user in FAN_REPORT_FID mode for all event types. + */ + if (FAN_GROUP_FLAG(group, FAN_REPORT_FID)) { + /* Do not report FAN_ONDIR without an event type */ + BUILD_BUG_ON(FANOTIFY_EVENT_TYPES & FANOTIFY_EVENT_FLAGS); + if (!(test_mask & FANOTIFY_EVENT_TYPES)) + return 0; + + user_mask |= FAN_ONDIR; + } + + /* + * Unlike legacy fanotify events (open/access/close), dirent events + * for subdir entries (mkdir/rmdir) will be reported regardless if + * user requested FAN_ONDIR, but the FAN_ONDIR flag itself will only + * be reported if the user asked for it. + */ if (event_mask & FS_ISDIR && + !(event_mask & ALL_FSNOTIFY_DIRENT_EVENTS) && !(marks_mask & FS_ISDIR & ~marks_ignored_mask)) return 0; - return event_mask & FANOTIFY_OUTGOING_EVENTS & marks_mask & - ~marks_ignored_mask; + return test_mask & user_mask; } static int fanotify_encode_fid(struct fanotify_event *event, diff --git a/include/linux/fanotify.h b/include/linux/fanotify.h index e9d45387089f..f5f86566c277 100644 --- a/include/linux/fanotify.h +++ b/include/linux/fanotify.h @@ -61,13 +61,16 @@ #define FANOTIFY_PERM_EVENTS (FAN_OPEN_PERM | FAN_ACCESS_PERM | \ FAN_OPEN_EXEC_PERM) +/* Events types that may be reported from vfs */ +#define FANOTIFY_EVENT_TYPES (FANOTIFY_EVENTS | \ + FANOTIFY_PERM_EVENTS) + /* Extra flags that may be reported with event or control handling of events */ #define FANOTIFY_EVENT_FLAGS (FAN_EVENT_ON_CHILD | FAN_ONDIR) /* Events that may be reported to user */ -#define FANOTIFY_OUTGOING_EVENTS (FANOTIFY_EVENTS | \ - FANOTIFY_PERM_EVENTS | \ - FAN_Q_OVERFLOW) +#define FANOTIFY_OUTGOING_EVENTS (FANOTIFY_EVENT_TYPES | \ + FAN_Q_OVERFLOW | FAN_ONDIR) #define ALL_FANOTIFY_EVENT_BITS (FANOTIFY_OUTGOING_EVENTS | \ FANOTIFY_EVENT_FLAGS)