From d03ef4daf33a33da8d7c397102fff8ae87d04a93 Mon Sep 17 00:00:00 2001 From: Wang Shilong Date: Tue, 3 Aug 2021 09:48:04 -0700 Subject: fs: forbid invalid project ID fileattr_set_prepare() should check if project ID is valid, otherwise dqget() will return NULL for such project ID quota. Signed-off-by: Wang Shilong Reviewed-by: Darrick J. Wong Signed-off-by: Darrick J. Wong --- fs/ioctl.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'fs/ioctl.c') diff --git a/fs/ioctl.c b/fs/ioctl.c index 1e2204fa9963..d4fabb5421cd 100644 --- a/fs/ioctl.c +++ b/fs/ioctl.c @@ -817,6 +817,14 @@ static int fileattr_set_prepare(struct inode *inode, if ((old_ma->fsx_xflags ^ fa->fsx_xflags) & FS_XFLAG_PROJINHERIT) return -EINVAL; + } else { + /* + * Caller is allowed to change the project ID. If it is being + * changed, make sure that the new value is valid. + */ + if (old_ma->fsx_projid != fa->fsx_projid && + !projid_valid(make_kprojid(&init_user_ns, fa->fsx_projid))) + return -EINVAL; } /* Check extent size hints. */ -- cgit v1.2.3