Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp3500399pxb; Mon, 18 Oct 2021 17:01:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyanxDwh7dzmYCaJMwSErk9kdWYzEBudcGhO5Ex0MKISRv3T3GBuSFrZZWsr3IirjEluE8T X-Received: by 2002:a05:6402:5c9:: with SMTP id n9mr48100093edx.90.1634601689910; Mon, 18 Oct 2021 17:01:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634601689; cv=none; d=google.com; s=arc-20160816; b=Akr9o92WGGKlQWr5tvfPPLUBi7O99s8Z0oAUDVejeSQ4N/reoHmCW7R9J31X+VC2pK ZRsorDBD/iLtmPJb0dkr4/W6bLiLXVj9tAjJdjRqgVWkQdU4FGU6/va8B04016+bPz6e MsLazTbPQNZ7s0UVOA3VWt00tCWf13CV5rIahJTgti3R2waZReRwP4a1FwsBF5RWdgoO EvasYOhEJE1B/IlP9KlQejDfvwr5g3kDKcT+z4N5fCzgp2GMUeVkZlJ80E1SMlEZamSZ pUxgIX1m2ob+YT5Cb7p4+SKC4joVaWUTxtYb2cAMwqkzE4gGsheg35h8DUii0dUKeKnJ 5iSw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=UH5heJbipzt778PgIk1x3hQEvzC1prGiC7taS+nb4RI=; b=xh9arskEVJmjWZxlJIEiTzpvSETpfHZvFePumMyxJxPevQ5x1gRBdS1ww3AglkwAq/ VHi/9Dd7Rn11PmDXyfn2wu/XZhN0IrOGv9DA+OlGtLOCk4a5esHoJJVN0uYLbKYP8RL/ rTOmRciTARm4HRAI5wDognmpTX4/dTih4gX+XrRB+KvqbNFivezS+hemPVw30xqpM69r KQkFOxPz0hOrZFEvEoupipbBxXTqDVXcVCvGVfAY305DeiroZZS60EtwC9eC5Nk1nFfe RvdbEjyWxHfTRoe03bP8xGUYNUeHHL4+IL1smN3CBvGBeLM0z34UhLxezhH7jcvmZDGH RPOg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 9si22156717ejf.632.2021.10.18.17.01.05; Mon, 18 Oct 2021 17:01:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233343AbhJSAC4 (ORCPT + 99 others); Mon, 18 Oct 2021 20:02:56 -0400 Received: from bhuna.collabora.co.uk ([46.235.227.227]:40630 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229529AbhJSAC4 (ORCPT ); Mon, 18 Oct 2021 20:02:56 -0400 Received: from localhost (unknown [IPv6:2804:14c:124:8a08::1007]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: krisman) by bhuna.collabora.co.uk (Postfix) with ESMTPSA id 0131F1F4342C; Tue, 19 Oct 2021 01:00:42 +0100 (BST) From: Gabriel Krisman Bertazi To: jack@suse.com, amir73il@gmail.com Cc: djwong@kernel.org, tytso@mit.edu, david@fromorbit.com, dhowells@redhat.com, khazhy@google.com, linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org, linux-api@vger.kernel.org, kernel@collabora.com, Jan Kara , Gabriel Krisman Bertazi Subject: [PATCH v8 03/32] fsnotify: clarify contract for create event hooks Date: Mon, 18 Oct 2021 20:59:46 -0300 Message-Id: <20211019000015.1666608-4-krisman@collabora.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211019000015.1666608-1-krisman@collabora.com> References: <20211019000015.1666608-1-krisman@collabora.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org From: Amir Goldstein Clarify argument names and contract for fsnotify_create() and fsnotify_mkdir() to reflect the anomaly of kernfs, which leaves dentries negavite after mkdir/create. Remove the WARN_ON(!inode) in audit code that were added by the Fixes commit under the wrong assumption that dentries cannot be negative after mkdir/create. Fixes: aa93bdc5500c ("fsnotify: use helpers to access data by data_type") Link: https://lore.kernel.org/linux-fsdevel/87mtp5yz0q.fsf@collabora.com/ Reviewed-by: Jan Kara Reported-by: Gabriel Krisman Bertazi Signed-off-by: Amir Goldstein Signed-off-by: Gabriel Krisman Bertazi --- include/linux/fsnotify.h | 22 ++++++++++++++++------ kernel/audit_fsnotify.c | 3 +-- kernel/audit_watch.c | 3 +-- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h index df0fa4687a18..1e5f7435a4b5 100644 --- a/include/linux/fsnotify.h +++ b/include/linux/fsnotify.h @@ -192,16 +192,22 @@ static inline void fsnotify_inoderemove(struct inode *inode) /* * fsnotify_create - 'name' was linked in + * + * Caller must make sure that dentry->d_name is stable. + * Note: some filesystems (e.g. kernfs) leave @dentry negative and instantiate + * ->d_inode later */ -static inline void fsnotify_create(struct inode *inode, struct dentry *dentry) +static inline void fsnotify_create(struct inode *dir, struct dentry *dentry) { - audit_inode_child(inode, dentry, AUDIT_TYPE_CHILD_CREATE); + audit_inode_child(dir, dentry, AUDIT_TYPE_CHILD_CREATE); - fsnotify_dirent(inode, dentry, FS_CREATE); + fsnotify_dirent(dir, dentry, FS_CREATE); } /* * fsnotify_link - new hardlink in 'inode' directory + * + * Caller must make sure that new_dentry->d_name is stable. * Note: We have to pass also the linked inode ptr as some filesystems leave * new_dentry->d_inode NULL and instantiate inode pointer later */ @@ -230,12 +236,16 @@ static inline void fsnotify_unlink(struct inode *dir, struct dentry *dentry) /* * fsnotify_mkdir - directory 'name' was created + * + * Caller must make sure that dentry->d_name is stable. + * Note: some filesystems (e.g. kernfs) leave @dentry negative and instantiate + * ->d_inode later */ -static inline void fsnotify_mkdir(struct inode *inode, struct dentry *dentry) +static inline void fsnotify_mkdir(struct inode *dir, struct dentry *dentry) { - audit_inode_child(inode, dentry, AUDIT_TYPE_CHILD_CREATE); + audit_inode_child(dir, dentry, AUDIT_TYPE_CHILD_CREATE); - fsnotify_dirent(inode, dentry, FS_CREATE | FS_ISDIR); + fsnotify_dirent(dir, dentry, FS_CREATE | FS_ISDIR); } /* diff --git a/kernel/audit_fsnotify.c b/kernel/audit_fsnotify.c index 60739d5e3373..02348b48447c 100644 --- a/kernel/audit_fsnotify.c +++ b/kernel/audit_fsnotify.c @@ -160,8 +160,7 @@ static int audit_mark_handle_event(struct fsnotify_mark *inode_mark, u32 mask, audit_mark = container_of(inode_mark, struct audit_fsnotify_mark, mark); - if (WARN_ON_ONCE(inode_mark->group != audit_fsnotify_group) || - WARN_ON_ONCE(!inode)) + if (WARN_ON_ONCE(inode_mark->group != audit_fsnotify_group)) return 0; if (mask & (FS_CREATE|FS_MOVED_TO|FS_DELETE|FS_MOVED_FROM)) { diff --git a/kernel/audit_watch.c b/kernel/audit_watch.c index 2acf7ca49154..223eed7b39cd 100644 --- a/kernel/audit_watch.c +++ b/kernel/audit_watch.c @@ -472,8 +472,7 @@ static int audit_watch_handle_event(struct fsnotify_mark *inode_mark, u32 mask, parent = container_of(inode_mark, struct audit_parent, mark); - if (WARN_ON_ONCE(inode_mark->group != audit_watch_group) || - WARN_ON_ONCE(!inode)) + if (WARN_ON_ONCE(inode_mark->group != audit_watch_group)) return 0; if (mask & (FS_CREATE|FS_MOVED_TO) && inode) -- 2.33.0