From patchwork Wed Oct 3 21:25:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 10625331 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 2F0BC1515 for ; Wed, 3 Oct 2018 21:25:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2007E28FF9 for ; Wed, 3 Oct 2018 21:25:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 146E329087; Wed, 3 Oct 2018 21:25:58 +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 ACD2729080 for ; Wed, 3 Oct 2018 21:25:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726722AbeJDEQD (ORCPT ); Thu, 4 Oct 2018 00:16:03 -0400 Received: from mail-wm1-f68.google.com ([209.85.128.68]:37617 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725871AbeJDEQC (ORCPT ); Thu, 4 Oct 2018 00:16:02 -0400 Received: by mail-wm1-f68.google.com with SMTP id 185-v6so7007603wmt.2 for ; Wed, 03 Oct 2018 14:25:56 -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:in-reply-to:references; bh=VubmMs8lPgeCW9ugJpKFb18KZPGzApJG7PlMPdpS+NA=; b=QkwPDqZR73AwjjVCZBkGoA1Qdta39LqPvfPhI7u0OxcyzLWykBnn8hBOCcLZ0HZp7i 0w3lDW+WKUC1L1SwxmLtNypJ+eof7vLhzbLED4CGcQeCWbSHS96c0Srsc/UTUswg4+xz u9DKNC8IqJjGBcd/Vz5NkSkSEKT68nnKn+8njpSEXYCyXieWgHmH3PwbzkdbbQHPIgeQ CsVOC1YJu2/FsN1cShFOgeS6e9SD5RIRFnhbgTQVCSC+N/LDjtITrai4uRJb7C2ZVe6M q8U4F2HFNs+f2qRRAZ/KN60Ll2+7GXze5Z8DPGMv1qC53D5CNcrUAHDRZtk3LaESJzqw TLUQ== 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=VubmMs8lPgeCW9ugJpKFb18KZPGzApJG7PlMPdpS+NA=; b=PwU9od6Y6QsQAgFYoSqSoBujXk8Wr5hM9usVgpXqR09CY4KA6qygqVQx5d8oWrE4Ml /4/fxg3kByyJX4WDMtvfTpx/pepkLhO8WS4l5HXdw9QRiHNRsQPC4SE1SwMlJ2fltxIj OH9DcpzgK2Aa3Sj7Awc1w/32lP1FQCpw5/oGq/jza5mYkROFyXQUZsq/oLYicck5c70g w79AuYK51tYBDYx93anwak5dObqYQXtOIrkU40ZHK/PgHr5i67zBGrvbjeu/4HetI7DE 4JwIoL/j1bFDbjrjYpUCBpPJzisBAZSV6JyjRVTPjYnm2mOu1aPHbpjVEfJVE7Dmlh2S Uz4Q== X-Gm-Message-State: ABuFfoi0xtRIr2oz0F0uZYwoZpt+PgMXbMDZIiP5XxLg+A29f9E14i/u nup093dNi/V+IEq1MkCIaktdUsJv X-Google-Smtp-Source: ACcGV62Tgm6FbUCkWTFl6XnK21qjLTL3ExG8eQAzCOGBl22nOF+DDLgLf3bkYQfBs22yMZd3QIetXg== X-Received: by 2002:a1c:de88:: with SMTP id v130-v6mr2644647wmg.59.1538601955307; Wed, 03 Oct 2018 14:25:55 -0700 (PDT) Received: from localhost.localdomain ([141.226.14.107]) by smtp.gmail.com with ESMTPSA id 193-v6sm4073866wmj.21.2018.10.03.14.25.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 03 Oct 2018 14:25:54 -0700 (PDT) From: Amir Goldstein To: Jan Kara Cc: linux-fsdevel@vger.kernel.org Subject: [PATCH v3 6/8] fanotify: add BUILD_BUG_ON() to count the bits of fanotify constants Date: Thu, 4 Oct 2018 00:25:37 +0300 Message-Id: <20181003212539.2384-7-amir73il@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181003212539.2384-1-amir73il@gmail.com> References: <20181003212539.2384-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 Also define the FANOTIFY_EVENT_FLAGS consisting of the extra flags FAN_ONDIR and FAN_ON_CHILD. Signed-off-by: Amir Goldstein --- fs/notify/fanotify/fanotify.c | 2 ++ fs/notify/fanotify/fanotify_user.c | 5 ++++- include/linux/fanotify.h | 8 ++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/fs/notify/fanotify/fanotify.c b/fs/notify/fanotify/fanotify.c index 03498eb995be..361e3a0a445c 100644 --- a/fs/notify/fanotify/fanotify.c +++ b/fs/notify/fanotify/fanotify.c @@ -205,6 +205,8 @@ static int fanotify_handle_event(struct fsnotify_group *group, BUILD_BUG_ON(FAN_ACCESS_PERM != FS_ACCESS_PERM); BUILD_BUG_ON(FAN_ONDIR != FS_ISDIR); + BUILD_BUG_ON(HWEIGHT32(ALL_FANOTIFY_EVENT_BITS) != 10); + if (!fanotify_should_send_event(iter_info, mask, data, data_type)) return 0; diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c index 530e5e486105..14594e491d2b 100644 --- a/fs/notify/fanotify/fanotify_user.c +++ b/fs/notify/fanotify/fanotify_user.c @@ -803,7 +803,7 @@ static int do_fanotify_mark(int fanotify_fd, unsigned int flags, __u64 mask, struct fsnotify_group *group; struct fd f; struct path path; - u32 valid_mask = FANOTIFY_EVENTS | FAN_EVENT_ON_CHILD | FAN_ONDIR; + u32 valid_mask = FANOTIFY_EVENTS | FANOTIFY_EVENT_FLAGS; unsigned int mark_type = flags & FANOTIFY_MARK_TYPE_BITS; int ret; @@ -944,6 +944,9 @@ COMPAT_SYSCALL_DEFINE6(fanotify_mark, */ static int __init fanotify_user_setup(void) { + BUILD_BUG_ON(HWEIGHT32(FANOTIFY_INIT_FLAGS) != 6); + BUILD_BUG_ON(HWEIGHT32(FANOTIFY_MARK_FLAGS) != 9); + fanotify_mark_cache = KMEM_CACHE(fsnotify_mark, SLAB_PANIC|SLAB_ACCOUNT); fanotify_event_cachep = KMEM_CACHE(fanotify_event_info, SLAB_PANIC); diff --git a/include/linux/fanotify.h b/include/linux/fanotify.h index 4519b0988afe..afddd7e0d5a1 100644 --- a/include/linux/fanotify.h +++ b/include/linux/fanotify.h @@ -41,11 +41,19 @@ /* Events that require a permission response from user */ #define FANOTIFY_PERM_EVENTS (FAN_OPEN_PERM | FAN_ACCESS_PERM) +/* 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 ALL_FANOTIFY_EVENT_BITS (FANOTIFY_EVENTS | \ + FANOTIFY_PERM_EVENTS | \ + FANOTIFY_EVENT_FLAGS | \ + FANOTIFY_OUTGOING_EVENTS) + /* Do not use these old uapi constants internally */ #undef FAN_ALL_CLASS_BITS #undef FAN_ALL_INIT_FLAGS