Skip to content

Commit 635bc4d

Browse files
amir73iljankara
authored andcommitted
fsnotify: do not generate ACCESS/MODIFY events on child for special files
inotify/fanotify do not allow users with no read access to a file to subscribe to events (e.g. IN_ACCESS/IN_MODIFY), but they do allow the same user to subscribe for watching events on children when the user has access to the parent directory (e.g. /dev). Users with no read access to a file but with read access to its parent directory can still stat the file and see if it was accessed/modified via atime/mtime change. The same is not true for special files (e.g. /dev/null). Users will not generally observe atime/mtime changes when other users read/write to special files, only when someone sets atime/mtime via utimensat(). Align fsnotify events with this stat behavior and do not generate ACCESS/MODIFY events to parent watchers on read/write of special files. The events are still generated to parent watchers on utimensat(). This closes some side-channels that could be possibly used for information exfiltration [1]. [1] https://snee.la/pdf/pubs/file-notification-attacks.pdf Reported-by: Sudheendra Raghav Neela <sneela@tugraz.at> CC: stable@vger.kernel.org Signed-off-by: Amir Goldstein <amir73il@gmail.com> Signed-off-by: Jan Kara <jack@suse.cz>
1 parent 7d0a66e commit 635bc4d

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

fs/notify/fsnotify.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,8 +270,15 @@ int __fsnotify_parent(struct dentry *dentry, __u32 mask, const void *data,
270270
/*
271271
* Include parent/name in notification either if some notification
272272
* groups require parent info or the parent is interested in this event.
273+
* The parent interest in ACCESS/MODIFY events does not apply to special
274+
* files, where read/write are not on the filesystem of the parent and
275+
* events can provide an undesirable side-channel for information
276+
* exfiltration.
273277
*/
274-
parent_interested = mask & p_mask & ALL_FSNOTIFY_EVENTS;
278+
parent_interested = mask & p_mask & ALL_FSNOTIFY_EVENTS &&
279+
!(data_type == FSNOTIFY_EVENT_PATH &&
280+
d_is_special(dentry) &&
281+
(mask & (FS_ACCESS | FS_MODIFY)));
275282
if (parent_needed || parent_interested) {
276283
/* When notifying parent, child should be passed as data */
277284
WARN_ON_ONCE(inode != fsnotify_data_inode(data, data_type));

0 commit comments

Comments
 (0)