Skip to contentSkip to conversation

fanotify: add support for more events

RFC PATCH Marko Rauhamaa 2 participants 7 messages Oct 13, 2016 – Dec 9, 2016 VFS

lore
Share & tools
lore
#0 lore raw

Amir Goldstein:

Quoted 8 lines

This series is a prep work for using fanotify to monitor all events in a file system with a single watch.

[...]

I am posting this WIP to get feedback on the idea and to find out if there are any users out there interested in the improved fanotify capabilities and/or in the super block monitoring use case.

My employer certainly is in need of monitoring a whole filesystem. We have noticed that namespaces evade monitoring via FAN_MARK_MOUNT. I was thinking something like a FAN_MARK_FILESYSTEM would be needed.

(There are some other needed features but filesystem monitoring is the most pressing one.)

Jan Kara:

Quoted 4 lines

Careful here. In the world of user namespaces and containers you have to be really careful so that events from one container don't leak into another container despite they live in the same physical filesystem, just a different bind mount.

Obviously, proper care needs to be taken, but a namespace should not be able smuggle filesystem events past fanotify monitoring.

Marko

#1 lore raw
Quoted 7 lines · Marko Rauhamaa

Amir Goldstein:

Quoted 5 lines

This series is a prep work for using fanotify to monitor all events in a file system with a single watch.

[...]

Quoted 8 lines
Quoted 3 lines

I am posting this WIP to get feedback on the idea and to find out if there are any users out there interested in the improved fanotify capabilities and/or in the super block monitoring use case.

My employer certainly is in need of monitoring a whole filesystem. We have noticed that namespaces evade monitoring via FAN_MARK_MOUNT. I was thinking something like a FAN_MARK_FILESYSTEM would be needed.

I have a POC of monitoring entire file system, while filtering to namespace only the events that should be visible to its mounts.
I need to get the patches into shape and shake them a bit, then I will post them and I am hoping that others could test them for their use case as well.

I keep hearing about people that wanted that feature, but those people will need to come forward and voice their use cases.

Quoted 4 lines

(There are some other needed features but filesystem monitoring is the most pressing one.)

Quoted 9 lines

Jan Kara:

Quoted 4 lines

Careful here. In the world of user namespaces and containers you have to be really careful so that events from one container don't leak into another container despite they live in the same physical filesystem, just a different bind mount.

Obviously, proper care needs to be taken, but a namespace should not be able smuggle filesystem events past fanotify monitoring.

I agree.

Cheers,
Amir.

#2 lore raw

Amir Goldstein <[email protected]>:

Quoted 9 lines

On Thu, Oct 13, 2016 at 8:35 PM, Marko Rauhamaa

Quoted 3 lines

My employer certainly is in need of monitoring a whole filesystem. We have noticed that namespaces evade monitoring via FAN_MARK_MOUNT. I was thinking something like a FAN_MARK_FILESYSTEM would be needed.

[...]

I keep hearing about people that wanted that feature, but those people will need to come forward and voice their use cases.

Well, F-Secure's Linux Security product monitors files to detect malware. Files are analyzed for viruses and unexpected modifications to system files are flagged.

Other fanotify deficiencies include:

* the offending process can die without leaving a trace because FAN_CLOSE_WRITE events do not block (instead of blocking, it would be enough for the /proc/$PID directory to stay available while the related fanotify fd is open)

* the (e)uid and (e)gid of the offending process are not conveyed in the fanotify event

* the FAN_OPEN_PERM event does not carry the mode so write access cannot be denied

* there is no (PERM or non-PERM) event generated by the first modification (FAN_MODIFY generates a flurry of events; FAN_CLOSE_WRITE does not get generated unless the file is closed)

Marko

#3 lore raw
Quoted 7 lines · Marko Rauhamaa

Amir Goldstein <[email protected]>:

Quoted 5 lines

On Thu, Oct 13, 2016 at 8:35 PM, Marko Rauhamaa

Quoted 3 lines

My employer certainly is in need of monitoring a whole filesystem. We have noticed that namespaces evade monitoring via FAN_MARK_MOUNT. I was thinking something like a FAN_MARK_FILESYSTEM would be needed.

Quoted 9 lines
Quoted 4 lines

[...]

I keep hearing about people that wanted that feature, but those people will need to come forward and voice their use cases.

Well, F-Secure's Linux Security product monitors files to detect malware. Files are analyzed for viruses and unexpected modifications to system files are flagged.

This I could have guessed :-)

Let me rephrse my question - please argue why monitoring a file system instead of a mount point is important for your use case and more impotantly, please argue why you cannot achive the same result by monitoring all the relevant mount points from user space.

For example, the argument I used against the legacy recursive intotify watch of all directories in the treee is the poor ability to scale well over millions of directories.

Quoted 11 lines

Other fanotify deficiencies include:

* the offending process can die without leaving a trace because FAN_CLOSE_WRITE events do not block (instead of blocking, it would be enough for the /proc/$PID directory to stay available while the related fanotify fd is open)

* the (e)uid and (e)gid of the offending process are not conveyed in the fanotify event

Quoted 8 lines

* the FAN_OPEN_PERM event does not carry the mode so write access cannot be denied

* there is no (PERM or non-PERM) event generated by the first modification (FAN_MODIFY generates a flurry of events; FAN_CLOSE_WRITE does not get generated unless the file is closed)

I am not sure I will be able help you wrt those extra requirements.

Amir.

#4 lore raw

Amir Goldstein <[email protected]>:

Quoted 4 lines

Let me rephrse my question - please argue why monitoring a file system instead of a mount point is important for your use case and more impotantly, please argue why you cannot achive the same result by monitoring all the relevant mount points from user space.

We are already doing that and missing fanotify events that are shrouded by namespaces. Namespaces are popular through the use of containers, but not only that. Distros are using namespaces to protect the private files of services:

<URL: http://fedoraproject.org/wiki/Features/ServicesPrivateTmp>

<URL: https://access.redhat.com/blogs/766093/posts/1976243>.

Quoted 3 lines

For example, the argument I used against the legacy recursive intotify watch of all directories in the treee is the poor ability to scale well over millions of directories.

Sure, that would be untenable. I'd argue the namespace issue is at least equally tough because you'd have to keep monitoring namespaces deep under the /proc hierarchy where processes come and go, there is no epollable notification scheme available (to my knowledge) and race conditions are inevitable. It would be virtually impossible for a top-level fanotify monitor to keep track of what is going on.

Marko

#5 lore raw
In reply to Amir Goldstein
Quoted 18 lines · Amir Goldstein
Quoted 7 lines · Marko Rauhamaa

Amir Goldstein:

Quoted 5 lines

This series is a prep work for using fanotify to monitor all events in a file system with a single watch.

[...]

Quoted 8 lines
Quoted 3 lines

I am posting this WIP to get feedback on the idea and to find out if there are any users out there interested in the improved fanotify capabilities and/or in the super block monitoring use case.

My employer certainly is in need of monitoring a whole filesystem. We have noticed that namespaces evade monitoring via FAN_MARK_MOUNT. I was thinking something like a FAN_MARK_FILESYSTEM would be needed.

Quoted 6 lines

I have a POC of monitoring entire file system, while filtering to namespace only the events that should be visible to its mounts.
I need to get the patches into shape and shake them a bit, then I will post them and I am hoping that others could test them for their use case as well.

Marko,

The super block watch patches are available on my git tree at:
https://github.com/amir73il/linux/commits/fanotify_sb-4.9

I won't bother to post them to the list unless someone shows interest. Note that beyond the ability to watch a file system, they also provide all the legacy intotify events (create/remove), so maybe that's also useful to you guys.

Anyway, if you are interested and willing to give them a try please send me feedback.

Thanks,
Amir.