kernel/fs: Introduce check_write_stat_permissions utility method.

Like check_access_permissions() but for write_stat() hook instead
of access().

Basic logic copied from BFS, but with the UID/GID logic rewritten
to better conform to behavior on other OSes: notably, we allow
chown() requests that keep the UID the same to go through, same
as Linux seems to, which should fix #19666. We now also validate
that the GID is one of the current team's groups.
This commit is contained in:
Augustin Cavalier
2025-07-07 15:10:01 -04:00
parent 7ed202f9ed
commit 9ea1065b16
5 changed files with 103 additions and 0 deletions
@@ -950,6 +950,7 @@
#define get_vnode_removed fssh_get_vnode_removed
#define volume_for_vnode fssh_volume_for_vnode
#define check_access_permissions fssh_check_access_permissions
#define check_write_stat_permissions fssh_check_write_stat_permissions
#define read_pages fssh_read_pages
#define write_pages fssh_write_pages
#define read_file_io_vec_pages fssh_read_file_io_vec_pages
@@ -364,6 +364,9 @@ extern fssh_fs_volume* fssh_volume_for_vnode(fssh_fs_vnode *vnode);
extern fssh_status_t fssh_check_access_permissions(int accessMode,
fssh_mode_t mode, fssh_gid_t nodeGroupID,
fssh_uid_t nodeUserID);
extern fssh_status_t fssh_check_write_stat_permissions(fssh_gid_t nodeGroupID,
fssh_uid_t nodeUserID, fssh_mode_t nodeMode, uint32_t mask,
const struct fssh_stat* stat);
extern fssh_status_t fssh_read_pages(int fd, fssh_off_t pos,
const struct fssh_iovec *vecs, fssh_size_t count,