From: Jan Kara Date: Wed, 7 Dec 2022 11:59:28 +0000 (+0100) Subject: ext4: avoid unaccounted block allocation when expanding inode X-Git-Tag: v6.2-rc1~154^2~3 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=8994d11395f8165b3deca1971946f549f0822630;p=thirdparty%2Fkernel%2Flinux.git ext4: avoid unaccounted block allocation when expanding inode When expanding inode space in ext4_expand_extra_isize_ea() we may need to allocate external xattr block. If quota is not initialized for the inode, the block allocation will not be accounted into quota usage. Make sure the quota is initialized before we try to expand inode space. Reported-by: Pengfei Xu Link: https://lore.kernel.org/all/Y5BT+k6xWqthZc1P@xpf.sh.intel.com Signed-off-by: Jan Kara Cc: stable@kernel.org Link: https://lore.kernel.org/r/20221207115937.26601-2-jack@suse.cz Signed-off-by: Theodore Ts'o --- diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 38b7db452d371..5a92e51863139 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -5945,6 +5945,14 @@ static int __ext4_expand_extra_isize(struct inode *inode, return 0; } + /* + * We may need to allocate external xattr block so we need quotas + * initialized. Here we can be called with various locks held so we + * cannot affort to initialize quotas ourselves. So just bail. + */ + if (dquot_initialize_needed(inode)) + return -EAGAIN; + /* try to expand with EAs present */ error = ext4_expand_extra_isize_ea(inode, new_extra_isize, raw_inode, handle);