Search code examples
linuxunixlinux-kernelfilesystemsfuse

When does a (FUSE) filesystem check acces rights?


"Unix world" filesystems (like ext4) store for each file, in the inode a list of permission/access rights for the 3 types of available users owner,group,other. I want to know when the "authentication" happens; what I mean is:

let's say we have a file

file.txt     rwx     rw-     ---       st_uid=54    st_gid=99
             owner   group   others    

user tim having uid=100, gid=99

runs cat file.txt in the terminal, the request gets to the filesystem which compares tim to the permisions of the file;

tim is not the owner: his uid=100 not the same with file's uid=54;

but he has the same gid as the file (99), so the response he gets is rw-

cat is actually a read so the user recieves the content

In which system function is this scenario executed? Can I modify it by implementing a custom filesystem?

UPDATE: the sole purpose of my filesystem is to mess a little more with the permissions and be a proof of concept (it's a research project) so any ideas about where I should start would be highly appreciated. Thanks in advance!!


Solution

  • The solution is straight forward with respect to a FUSE filesystem: The FUSE implementation provides a context for each user request made to the filesystem;

    The workflow looks like this:

    1. A user makes a filesystem-related request (i.e. ls)
    2. The kernel notices that that specific filesystem is mounted using FUSE
    3. The request is forwarded to the custom filesystem (created using FUSE). Here you can access the request's metadata using fuse_context which will return a uid,gid,pid.
    4. The ball is in your court now: you can do (almost) anything you want having full control over the filesystem and the user's requests