Skip to content

Commit 5b08dcc

Browse files
ntfs3: reject direct userspace writes to reserved $LX* xattrs
NTFS3 uses $LXUID, $LXGID, $LXMOD and $LXDEV as internal WSL permission metadata and reloads them into i_uid, i_gid and i_mode from ntfs_get_wsl_perm(). Because the empty-prefix xattr handler also lets file owners call setxattr() on these names directly, an unprivileged writer on a writable ntfs3 mount can plant root ownership and S_ISUID on their own file and gain euid 0 after inode reload. Reject direct userspace writes to the reserved $LX* names. Internal ntfs3 metadata updates are unchanged because ntfs_save_wsl_perm() writes them via ntfs_set_ea() directly. Signed-off-by: Zhen Yan <sdjasjbuaa@gmail.com> [almaz.alexandrovich@paragon-software.com: added an additional check for non privileged users] Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
1 parent 5a35454 commit 5b08dcc

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

fs/ntfs3/xattr.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -851,6 +851,12 @@ static int ntfs_getxattr(const struct xattr_handler *handler, struct dentry *de,
851851
return err;
852852
}
853853

854+
static bool ntfs_is_reserved_lxattr(const char *name)
855+
{
856+
return !strcmp(name, "$LXUID") || !strcmp(name, "$LXGID") ||
857+
!strcmp(name, "$LXMOD") || !strcmp(name, "$LXDEV");
858+
}
859+
854860
/*
855861
* ntfs_setxattr - inode_operations::setxattr
856862
*/
@@ -957,6 +963,12 @@ static noinline int ntfs_setxattr(const struct xattr_handler *handler,
957963
goto out;
958964
}
959965

966+
/* Do not allow non privileged users to change $LXUID/$LXGID... */
967+
if (ntfs_is_reserved_lxattr(name) && !capable(CAP_SYS_ADMIN)) {
968+
err = -EPERM;
969+
goto out;
970+
}
971+
960972
/* Deal with NTFS extended attribute. */
961973
err = ntfs_set_ea(inode, name, strlen(name), value, size, flags, 0,
962974
NULL);

0 commit comments

Comments
 (0)