• C
    mnt_idmapping: add vfs{g,u}id_t · 1e5267cd
    Christian Brauner 提交于
    Introduces new vfs{g,u}id_t types. Similar to k{g,u}id_t the new types
    are just simple wrapper structs around regular {g,u}id_t types.
    
    They allows to establish a type safety boundary between {g,u}ids on
    idmapped mounts and {g,u}ids as they are represented in filesystems
    themselves.
    
    A vfs{g,u}id_t is always created from a k{g,u}id_t, never directly from
    a {g,u}id_t as idmapped mounts remap a given {g,u}id according to the
    mount's idmapping. This is expressed in the VFS{G,U}IDT_INIT() macros.
    
    A vfs{g,u}id_t may be used as a k{g,u}id_t via AS_K{G,U}IDT(). This
    often happens when we need to check whether a {g,u}id mapped according
    to an idmapped mount is identical to a given k{g,u}id_t. For an example,
    see vfsgid_in_group_p() which determines whether the value of vfsgid_t
    matches the value of any of the caller's groups. Similar logic is
    expressed in the k{g,u}id_eq_vfs{g,u}id().
    
    The from_vfs{g,u}id() helpers map a given vfs{g,u}id_t from the mount's
    idmapping into the filesystem idmapping. They make it possible to update
    a filesystem object such as inode->i_{g,u}id with the correct value.
    
    This makes it harder to accidently write a wrong {g,u}id anwywhere. The
    vfs{g,u}id_has_fsmapping() helpers check whether a given vfs{g,u}id_t
    can be mapped into the filesystem idmapping.
    
    All new helpers are nops on non-idmapped mounts.
    
    I've done work on this roughly 7 months ago but dropped it to focus on
    the testsuite. Linus brought this up independently just last week and
    it's time to move this along (see [1]).
    
    [1]: https://lore.kernel.org/lkml/CAHk-=win6+ahs1EwLkcq8apqLi_1wXFWbrPf340zYEhObpz4jA@mail.gmail.com
    
    Link: https://lore.kernel.org/r/20220621141454.2914719-2-brauner@kernel.org
    Cc: Seth Forshee <sforshee@digitalocean.com>
    Cc: Christoph Hellwig <hch@lst.de>
    Cc: Aleksa Sarai <cyphar@cyphar.com>
    Cc: Linus Torvalds <torvalds@linux-foundation.org>
    Cc: Al Viro <viro@zeniv.linux.org.uk>
    CC: linux-fsdevel@vger.kernel.org
    Reviewed-by: NSeth Forshee <sforshee@digitalocean.com>
    Signed-off-by: NChristian Brauner (Microsoft) <brauner@kernel.org>
    1e5267cd
mnt_idmapping.h 13.1 KB