diff --git a/packages/linux/patches/default/fs-ntfs3-since-5-15.patch b/packages/linux/patches/default/fs-ntfs3-since-5-15.patch index 2fb16c72ff..60c54cd4a3 100644 --- a/packages/linux/patches/default/fs-ntfs3-since-5-15.patch +++ b/packages/linux/patches/default/fs-ntfs3-since-5-15.patch @@ -1,259 +1,7 @@ -From e589f9b7078e1c0191613cd736f598e81d2390de Mon Sep 17 00:00:00 2001 -From: Christophe JAILLET -Date: Thu, 11 Nov 2021 08:45:44 +0100 -Subject: [PATCH 1/9] fs/ntfs3: Fix some memory leaks in an error handling path - of 'log_replay()' - -All error handling paths lead to 'out' where many resources are freed. - -Do it as well here instead of a direct return, otherwise 'log', 'ra' and -'log->one_page_buf' (at least) will leak. - -Fixes: b46acd6a6a62 ("fs/ntfs3: Add NTFS journal") -Signed-off-by: Christophe JAILLET -Signed-off-by: Konstantin Komarov ---- - fs/ntfs3/fslog.c | 6 ++++-- - 1 file changed, 4 insertions(+), 2 deletions(-) - -diff --git a/fs/ntfs3/fslog.c b/fs/ntfs3/fslog.c -index 06492f088d60..915f42cf07bc 100644 ---- a/fs/ntfs3/fslog.c -+++ b/fs/ntfs3/fslog.c -@@ -4085,8 +4085,10 @@ int log_replay(struct ntfs_inode *ni, bool *initialized) - if (client == LFS_NO_CLIENT_LE) { - /* Insert "NTFS" client LogFile. */ - client = ra->client_idx[0]; -- if (client == LFS_NO_CLIENT_LE) -- return -EINVAL; -+ if (client == LFS_NO_CLIENT_LE) { -+ err = -EINVAL; -+ goto out; -+ } - - t16 = le16_to_cpu(client); - cr = ca + t16; --- -2.25.1 - -From e95113ed4d428219e3395044e29f5713fc446720 Mon Sep 17 00:00:00 2001 -From: Konstantin Komarov -Date: Fri, 22 Oct 2021 17:37:52 +0300 -Subject: [PATCH 2/9] fs/ntfs3: Keep preallocated only if option prealloc - enabled - -If size of file was reduced, we still kept allocated blocks. -This commit makes ntfs3 work as other fs like btrfs. -Link: https://bugzilla.kernel.org/show_bug.cgi?id=214719 -Fixes: 4342306f0f0d ("fs/ntfs3: Add file operations and implementation") - -Reported-by: Ganapathi Kamath -Tested-by: Ganapathi Kamath -Reviewed-by: Kari Argillander -Signed-off-by: Konstantin Komarov ---- - fs/ntfs3/file.c | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/fs/ntfs3/file.c b/fs/ntfs3/file.c -index 43b1451bff53..3ac0482c6880 100644 ---- a/fs/ntfs3/file.c -+++ b/fs/ntfs3/file.c -@@ -494,7 +494,7 @@ static int ntfs_truncate(struct inode *inode, loff_t new_size) - - down_write(&ni->file.run_lock); - err = attr_set_size(ni, ATTR_DATA, NULL, 0, &ni->file.run, new_size, -- &new_valid, true, NULL); -+ &new_valid, ni->mi.sbi->options->prealloc, NULL); - up_write(&ni->file.run_lock); - - if (new_valid < ni->i_valid) --- -2.25.1 - -From 87e21c99bad763524c953ff4d1a61ee19038ddc2 Mon Sep 17 00:00:00 2001 -From: Konstantin Komarov -Date: Fri, 22 Oct 2021 18:15:36 +0300 -Subject: [PATCH 3/9] fs/ntfs3: Restore ntfs_xattr_get_acl and - ntfs_xattr_set_acl functions - -Apparently we need to maintain these functions with -ntfs_get_acl_ex and ntfs_set_acl_ex. -This commit fixes xfstest generic/099 -Fixes: 95dd8b2c1ed0 ("fs/ntfs3: Remove unnecessary functions") - -Reviewed-by: Kari Argillander -Signed-off-by: Konstantin Komarov ---- - fs/ntfs3/xattr.c | 96 +++++++++++++++++++++++++++++++++++++++++++++++- - 1 file changed, 95 insertions(+), 1 deletion(-) - -diff --git a/fs/ntfs3/xattr.c b/fs/ntfs3/xattr.c -index afd0ddad826f..56e774d0f56a 100644 ---- a/fs/ntfs3/xattr.c -+++ b/fs/ntfs3/xattr.c -@@ -112,7 +112,7 @@ static int ntfs_read_ea(struct ntfs_inode *ni, struct EA_FULL **ea, - return -ENOMEM; - - if (!size) { -- ; -+ /* EA info persists, but xattr is empty. Looks like EA problem. */ - } else if (attr_ea->non_res) { - struct runs_tree run; - -@@ -619,6 +619,67 @@ int ntfs_set_acl(struct user_namespace *mnt_userns, struct inode *inode, - return ntfs_set_acl_ex(mnt_userns, inode, acl, type); - } - -+static int ntfs_xattr_get_acl(struct user_namespace *mnt_userns, -+ struct inode *inode, int type, void *buffer, -+ size_t size) -+{ -+ struct posix_acl *acl; -+ int err; -+ -+ if (!(inode->i_sb->s_flags & SB_POSIXACL)) { -+ ntfs_inode_warn(inode, "add mount option \"acl\" to use acl"); -+ return -EOPNOTSUPP; -+ } -+ -+ acl = ntfs_get_acl(inode, type, false); -+ if (IS_ERR(acl)) -+ return PTR_ERR(acl); -+ -+ if (!acl) -+ return -ENODATA; -+ -+ err = posix_acl_to_xattr(mnt_userns, acl, buffer, size); -+ posix_acl_release(acl); -+ -+ return err; -+} -+ -+static int ntfs_xattr_set_acl(struct user_namespace *mnt_userns, -+ struct inode *inode, int type, const void *value, -+ size_t size) -+{ -+ struct posix_acl *acl; -+ int err; -+ -+ if (!(inode->i_sb->s_flags & SB_POSIXACL)) { -+ ntfs_inode_warn(inode, "add mount option \"acl\" to use acl"); -+ return -EOPNOTSUPP; -+ } -+ -+ if (!inode_owner_or_capable(mnt_userns, inode)) -+ return -EPERM; -+ -+ if (!value) { -+ acl = NULL; -+ } else { -+ acl = posix_acl_from_xattr(mnt_userns, value, size); -+ if (IS_ERR(acl)) -+ return PTR_ERR(acl); -+ -+ if (acl) { -+ err = posix_acl_valid(mnt_userns, acl); -+ if (err) -+ goto release_and_out; -+ } -+ } -+ -+ err = ntfs_set_acl(mnt_userns, inode, acl, type); -+ -+release_and_out: -+ posix_acl_release(acl); -+ return err; -+} -+ - /* - * ntfs_init_acl - Initialize the ACLs of a new inode. - * -@@ -785,6 +846,23 @@ static int ntfs_getxattr(const struct xattr_handler *handler, struct dentry *de, - goto out; - } - -+#ifdef CONFIG_NTFS3_FS_POSIX_ACL -+ if ((name_len == sizeof(XATTR_NAME_POSIX_ACL_ACCESS) - 1 && -+ !memcmp(name, XATTR_NAME_POSIX_ACL_ACCESS, -+ sizeof(XATTR_NAME_POSIX_ACL_ACCESS))) || -+ (name_len == sizeof(XATTR_NAME_POSIX_ACL_DEFAULT) - 1 && -+ !memcmp(name, XATTR_NAME_POSIX_ACL_DEFAULT, -+ sizeof(XATTR_NAME_POSIX_ACL_DEFAULT)))) { -+ /* TODO: init_user_ns? */ -+ err = ntfs_xattr_get_acl( -+ &init_user_ns, inode, -+ name_len == sizeof(XATTR_NAME_POSIX_ACL_ACCESS) - 1 -+ ? ACL_TYPE_ACCESS -+ : ACL_TYPE_DEFAULT, -+ buffer, size); -+ goto out; -+ } -+#endif - /* Deal with NTFS extended attribute. */ - err = ntfs_get_ea(inode, name, name_len, buffer, size, NULL); - -@@ -897,6 +975,22 @@ static noinline int ntfs_setxattr(const struct xattr_handler *handler, - goto out; - } - -+#ifdef CONFIG_NTFS3_FS_POSIX_ACL -+ if ((name_len == sizeof(XATTR_NAME_POSIX_ACL_ACCESS) - 1 && -+ !memcmp(name, XATTR_NAME_POSIX_ACL_ACCESS, -+ sizeof(XATTR_NAME_POSIX_ACL_ACCESS))) || -+ (name_len == sizeof(XATTR_NAME_POSIX_ACL_DEFAULT) - 1 && -+ !memcmp(name, XATTR_NAME_POSIX_ACL_DEFAULT, -+ sizeof(XATTR_NAME_POSIX_ACL_DEFAULT)))) { -+ err = ntfs_xattr_set_acl( -+ mnt_userns, inode, -+ name_len == sizeof(XATTR_NAME_POSIX_ACL_ACCESS) - 1 -+ ? ACL_TYPE_ACCESS -+ : ACL_TYPE_DEFAULT, -+ value, size); -+ goto out; -+ } -+#endif - /* Deal with NTFS extended attribute. */ - err = ntfs_set_ea(inode, name, name_len, value, size, flags); - --- -2.25.1 - -From 2d44667c306e7806848a3478820f87343feb5421 Mon Sep 17 00:00:00 2001 -From: Konstantin Komarov -Date: Fri, 22 Oct 2021 18:35:43 +0300 -Subject: [PATCH 4/9] fs/ntfs3: Update i_ctime when xattr is added - -Ctime wasn't updated after setfacl command. -This commit fixes xfstest generic/307 -Fixes: be71b5cba2e6 ("fs/ntfs3: Add attrib operations") - -Signed-off-by: Konstantin Komarov ---- - fs/ntfs3/xattr.c | 3 +++ - 1 file changed, 3 insertions(+) - -diff --git a/fs/ntfs3/xattr.c b/fs/ntfs3/xattr.c -index 56e774d0f56a..af818300493d 100644 ---- a/fs/ntfs3/xattr.c -+++ b/fs/ntfs3/xattr.c -@@ -995,6 +995,9 @@ static noinline int ntfs_setxattr(const struct xattr_handler *handler, - err = ntfs_set_ea(inode, name, name_len, value, size, flags); - - out: -+ inode->i_ctime = current_time(inode); -+ mark_inode_dirty(inode); -+ - return err; - } - --- -2.25.1 - From 3a2154b25a9f461a1848371b3e8f6f316434ae1f Mon Sep 17 00:00:00 2001 From: Konstantin Komarov Date: Fri, 22 Oct 2021 18:30:22 +0300 -Subject: [PATCH 5/9] fs/ntfs3: Optimize locking in ntfs_save_wsl_perm +Subject: fs/ntfs3: Optimize locking in ntfs_save_wsl_perm Right now in ntfs_save_wsl_perm we lock/unlock 4 times. This commit fixes this situation. @@ -267,10 +15,10 @@ Signed-off-by: Konstantin Komarov 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/fs/ntfs3/xattr.c b/fs/ntfs3/xattr.c -index af818300493d..94a277615b62 100644 +index af818300493dc..94a277615b629 100644 --- a/fs/ntfs3/xattr.c +++ b/fs/ntfs3/xattr.c -@@ -259,7 +259,7 @@ static int ntfs_get_ea(struct inode *inode, const char *name, size_t name_len, +@@ -259,7 +259,7 @@ out: static noinline int ntfs_set_ea(struct inode *inode, const char *name, size_t name_len, const void *value, @@ -289,7 +37,7 @@ index af818300493d..94a277615b62 100644 run_init(&ea_run); -@@ -467,7 +468,8 @@ static noinline int ntfs_set_ea(struct inode *inode, const char *name, +@@ -467,7 +468,8 @@ update_ea: mark_inode_dirty(&ni->vfs_inode); out: @@ -308,7 +56,7 @@ index af818300493d..94a277615b62 100644 if (err == -ENODATA && !size) err = 0; /* Removing non existed xattr. */ if (!err) -@@ -992,7 +994,7 @@ static noinline int ntfs_setxattr(const struct xattr_handler *handler, +@@ -992,7 +994,7 @@ set_new_fa: } #endif /* Deal with NTFS extended attribute. */ @@ -361,233 +109,5 @@ index af818300493d..94a277615b62 100644 return err; } -- -2.25.1 - -From 9186d472ee780fabf74424756c4c00545166157e Mon Sep 17 00:00:00 2001 -From: Konstantin Komarov -Date: Wed, 24 Nov 2021 15:08:19 +0300 -Subject: [PATCH 6/9] fs/ntfs3: In function ntfs_set_acl_ex do not change - inode->i_mode if called from function ntfs_init_acl - -ntfs_init_acl sets mode. ntfs_init_acl calls ntfs_set_acl_ex. -ntfs_set_acl_ex must not change this mode. -Fixes xfstest generic/444 -Fixes: be71b5cba2e6 ("fs/ntfs3: Add attrib operations") - -Reviewed-by: Joe Perches -Signed-off-by: Konstantin Komarov ---- - fs/ntfs3/xattr.c | 13 +++++++------ - 1 file changed, 7 insertions(+), 6 deletions(-) - -diff --git a/fs/ntfs3/xattr.c b/fs/ntfs3/xattr.c -index 94a277615b62..5e0e0280e70d 100644 ---- a/fs/ntfs3/xattr.c -+++ b/fs/ntfs3/xattr.c -@@ -543,7 +543,7 @@ struct posix_acl *ntfs_get_acl(struct inode *inode, int type, bool rcu) - - static noinline int ntfs_set_acl_ex(struct user_namespace *mnt_userns, - struct inode *inode, struct posix_acl *acl, -- int type) -+ int type, bool init_acl) - { - const char *name; - size_t size, name_len; -@@ -556,8 +556,9 @@ static noinline int ntfs_set_acl_ex(struct user_namespace *mnt_userns, - - switch (type) { - case ACL_TYPE_ACCESS: -- if (acl) { -- umode_t mode = inode->i_mode; -+ /* Do not change i_mode if we are in init_acl */ -+ if (acl && !init_acl) { -+ umode_t mode; - - err = posix_acl_update_mode(mnt_userns, inode, &mode, - &acl); -@@ -618,7 +619,7 @@ static noinline int ntfs_set_acl_ex(struct user_namespace *mnt_userns, - int ntfs_set_acl(struct user_namespace *mnt_userns, struct inode *inode, - struct posix_acl *acl, int type) - { -- return ntfs_set_acl_ex(mnt_userns, inode, acl, type); -+ return ntfs_set_acl_ex(mnt_userns, inode, acl, type, false); - } - - static int ntfs_xattr_get_acl(struct user_namespace *mnt_userns, -@@ -699,7 +700,7 @@ int ntfs_init_acl(struct user_namespace *mnt_userns, struct inode *inode, - - if (default_acl) { - err = ntfs_set_acl_ex(mnt_userns, inode, default_acl, -- ACL_TYPE_DEFAULT); -+ ACL_TYPE_DEFAULT, true); - posix_acl_release(default_acl); - } else { - inode->i_default_acl = NULL; -@@ -710,7 +711,7 @@ int ntfs_init_acl(struct user_namespace *mnt_userns, struct inode *inode, - else { - if (!err) - err = ntfs_set_acl_ex(mnt_userns, inode, acl, -- ACL_TYPE_ACCESS); -+ ACL_TYPE_ACCESS, true); - posix_acl_release(acl); - } - --- -2.25.1 - -From 3880f2b816a7e4ca889b7e8a42e6c62c5706ed36 Mon Sep 17 00:00:00 2001 -From: Konstantin Komarov -Date: Mon, 25 Oct 2021 18:31:28 +0300 -Subject: [PATCH 7/9] fs/ntfs3: Fix fiemap + fix shrink file size (to remove - preallocated space) - -Two problems: -1. ntfs3_setattr can't truncate preallocated space; -2. if allocated fragment "cross" valid size, then fragment splits into two parts: -- normal part; -- unwritten part (here we must return FIEMAP_EXTENT_LAST). -Before this commit we returned FIEMAP_EXTENT_LAST for whole fragment. -Fixes xfstest generic/092 -Fixes: 4342306f0f0d ("fs/ntfs3: Add file operations and implementation") - -Signed-off-by: Konstantin Komarov ---- - fs/ntfs3/file.c | 2 +- - fs/ntfs3/frecord.c | 10 +++++++--- - 2 files changed, 8 insertions(+), 4 deletions(-) - -diff --git a/fs/ntfs3/file.c b/fs/ntfs3/file.c -index 3ac0482c6880..6242708980d0 100644 ---- a/fs/ntfs3/file.c -+++ b/fs/ntfs3/file.c -@@ -761,7 +761,7 @@ int ntfs3_setattr(struct user_namespace *mnt_userns, struct dentry *dentry, - } - inode_dio_wait(inode); - -- if (attr->ia_size < oldsize) -+ if (attr->ia_size <= oldsize) - err = ntfs_truncate(inode, attr->ia_size); - else if (attr->ia_size > oldsize) - err = ntfs_extend(inode, attr->ia_size, 0, NULL); -diff --git a/fs/ntfs3/frecord.c b/fs/ntfs3/frecord.c -index 6f47a9c17f89..18842998c8fa 100644 ---- a/fs/ntfs3/frecord.c -+++ b/fs/ntfs3/frecord.c -@@ -1964,10 +1964,8 @@ int ni_fiemap(struct ntfs_inode *ni, struct fiemap_extent_info *fieinfo, - - vcn += clen; - -- if (vbo + bytes >= end) { -+ if (vbo + bytes >= end) - bytes = end - vbo; -- flags |= FIEMAP_EXTENT_LAST; -- } - - if (vbo + bytes <= valid) { - ; -@@ -1977,6 +1975,9 @@ int ni_fiemap(struct ntfs_inode *ni, struct fiemap_extent_info *fieinfo, - /* vbo < valid && valid < vbo + bytes */ - u64 dlen = valid - vbo; - -+ if (vbo + dlen >= end) -+ flags |= FIEMAP_EXTENT_LAST; -+ - err = fiemap_fill_next_extent(fieinfo, vbo, lbo, dlen, - flags); - if (err < 0) -@@ -1995,6 +1996,9 @@ int ni_fiemap(struct ntfs_inode *ni, struct fiemap_extent_info *fieinfo, - flags |= FIEMAP_EXTENT_UNWRITTEN; - } - -+ if (vbo + bytes >= end) -+ flags |= FIEMAP_EXTENT_LAST; -+ - err = fiemap_fill_next_extent(fieinfo, vbo, lbo, bytes, flags); - if (err < 0) - break; --- -2.25.1 - -From 114346978cf61de02832cc3cc68432a3de70fb38 Mon Sep 17 00:00:00 2001 -From: Konstantin Komarov -Date: Mon, 25 Oct 2021 18:34:06 +0300 -Subject: [PATCH 8/9] fs/ntfs3: Check new size for limits - -We must check size before trying to allocate. -Size can be set for example by "ulimit -f". -Fixes xfstest generic/228 -Fixes: 4342306f0f0d ("fs/ntfs3: Add file operations and implementation") - -Reviewed-by: Kari Argillander -Signed-off-by: Konstantin Komarov ---- - fs/ntfs3/file.c | 8 +++++++- - 1 file changed, 7 insertions(+), 1 deletion(-) - -diff --git a/fs/ntfs3/file.c b/fs/ntfs3/file.c -index 6242708980d0..f8360f9bfaf0 100644 ---- a/fs/ntfs3/file.c -+++ b/fs/ntfs3/file.c -@@ -661,7 +661,13 @@ static long ntfs_fallocate(struct file *file, int mode, loff_t vbo, loff_t len) - /* - * Normal file: Allocate clusters, do not change 'valid' size. - */ -- err = ntfs_set_size(inode, max(end, i_size)); -+ loff_t new_size = max(end, i_size); -+ -+ err = inode_newsize_ok(inode, new_size); -+ if (err) -+ goto out; -+ -+ err = ntfs_set_size(inode, new_size); - if (err) - goto out; - --- -2.25.1 - -From 52e00ea6b26e45fb8159e3b57cdde8d3f9bdd8e9 Mon Sep 17 00:00:00 2001 -From: Konstantin Komarov -Date: Mon, 25 Oct 2021 18:48:38 +0300 -Subject: [PATCH 9/9] fs/ntfs3: Update valid size if -EIOCBQUEUED - -Update valid size if write is still in I/O queue. -Fixes xfstest generic/240 -Fixes: 82cae269cfa9 ("fs/ntfs3: Add initialization of super block") - -Signed-off-by: Konstantin Komarov ---- - fs/ntfs3/inode.c | 8 ++++++-- - 1 file changed, 6 insertions(+), 2 deletions(-) - -diff --git a/fs/ntfs3/inode.c b/fs/ntfs3/inode.c -index 859951d785cb..879952254071 100644 ---- a/fs/ntfs3/inode.c -+++ b/fs/ntfs3/inode.c -@@ -757,6 +757,7 @@ static ssize_t ntfs_direct_IO(struct kiocb *iocb, struct iov_iter *iter) - loff_t vbo = iocb->ki_pos; - loff_t end; - int wr = iov_iter_rw(iter) & WRITE; -+ size_t iter_count = iov_iter_count(iter); - loff_t valid; - ssize_t ret; - -@@ -770,10 +771,13 @@ static ssize_t ntfs_direct_IO(struct kiocb *iocb, struct iov_iter *iter) - wr ? ntfs_get_block_direct_IO_W - : ntfs_get_block_direct_IO_R); - -- if (ret <= 0) -+ if (ret > 0) -+ end = vbo + ret; -+ else if (wr && ret == -EIOCBQUEUED) -+ end = vbo + iter_count; -+ else - goto out; - -- end = vbo + ret; - valid = ni->i_valid; - if (wr) { - if (end > valid && !S_ISBLK(inode->i_mode)) { --- -2.25.1 +cgit 1.2.3-1.el7