FAILED: patch "[PATCH] exfat: preserve benign secondary entries during rename and" failed to apply to 6.18-stable tree
Subsystems (2)
[email protected]
maintainerThe patch below does not apply to the 6.18-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.18.y
git checkout FETCH_HEAD
git cherry-pick -x 942296784b2a9439651750c42f540bf2579b330f
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2026071544-outsider-rental-f09b@gregkh' --subject-prefix 'PATCH 6.18.y' 'HEAD^..'
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From 942296784b2a9439651750c42f540bf2579b330f Mon Sep 17 00:00:00 2001
From: Rochan Avlur <[email protected]>
Date: Thu, 28 May 2026 07:21:37 -0700
Subject: [PATCH] exfat: preserve benign secondary entries during rename and
move
Commit 8258ef28001a ("exfat: handle unreconized benign secondary entries") added cluster freeing for benign secondary entries inside exfat_remove_entries(). However, exfat_remove_entries() is also called from the rename and move paths (exfat_rename_file and exfat_move_file), where the old entry set is being relocated rather than deleted. This causes benign secondary entries such as vendor extension entries to be silently destroyed on rename or cross-directory move, violating the exFAT spec requirement (section 8.2) that implementations preserve unrecognized benign secondary entries.
Fix this by adding a free_benign parameter to exfat_remove_entries() so callers can suppress cluster freeing during relocation, and extending exfat_init_ext_entry() to copy trailing benign secondary entries from the old entry set into the new one internally. Also clean up the error paths to delete newly allocated entries on failure.
fs/exfat/dir.c +44 -6
@@ -470,32 +470,70 @@ static void exfat_free_benign_secondary_clusters(struct inode *inode,exfat_free_cluster (inode, &dir); } +/* +* exfat_init_ext_entry - initialize extension entries in a directory entry set +* @es: target entry set +* @num_entries: number of entries excluding benign secondary entries +* @p_uniname: filename to store +* @old_es: optional source entry set with benign secondary entries, or NULL +* @num_extra: number of benign secondary entries to copy from @old_es +* +* Set up the file, stream extension, and filename entries in @es, optionally +* preserving @num_extra benign secondary entries from @old_es. @es and @old_es +* may refer to the same entry set; excess entries are marked as deleted. +*/ void exfat_init_ext_entry (struct exfat_entry_set_cache *es,int num_entries, -struct exfat_uni_name *p_uniname) +struct exfat_uni_name *p_uniname, +struct exfat_entry_set_cache *old_es,int num_extra) { -int i; +int i, src_start =0 , old_num;unsigned short *uniname = p_uniname->name;struct exfat_dentry *ep; - es->num_entries = num_entries; +if (WARN_ON (num_extra <0 || (num_extra && (!old_es || + old_es->num_entries <ES_IDX_FIRST_FILENAME + num_extra)))) + num_extra =0 ; + +/* +* Save old entry count and source position before modifying +* es->num_entries, since old_es and es may point to the same +* entry set. +*/ + old_num = es->num_entries; +if (old_es && num_extra >0 ) + src_start = old_es->num_entries - num_extra; + + es->num_entries = num_entries + num_extra; ep =exfat_get_dentry_cached (es,ES_IDX_FILE ); - ep->dentry.file.num_ext = (unsigned char )(num_entries -1 ); + ep->dentry.file.num_ext = (unsigned char )(num_entries -1 + num_extra); ep =exfat_get_dentry_cached (es,ES_IDX_STREAM ); ep->dentry.stream.name_len = p_uniname->name_len; ep->dentry.stream.name_hash =cpu_to_le16 (p_uniname->name_hash); +if (old_es && num_extra >0 ) { +for (i =0 ; i < num_extra; i++) + *exfat_get_dentry_cached (es, num_entries + i) = + *exfat_get_dentry_cached (old_es, src_start + i); + } +for (i =ES_IDX_FIRST_FILENAME ; i < num_entries; i++) { ep =exfat_get_dentry_cached (es, i);exfat_init_name_entry (ep, uniname); uniname +=EXFAT_FILE_NAME_LEN ; } +/* Mark excess old entries as deleted (in-place shrink) */ +for (i = num_entries + num_extra; i < old_num; i++) { + ep =exfat_get_dentry_cached (es, i); +exfat_set_entry_type (ep,TYPE_DELETED ); + } +exfat_update_dir_chksum (es); }void exfat_remove_entries (struct inode *inode,struct exfat_entry_set_cache *es, -int order) +int order,bool free_benign) {int i;struct exfat_dentry *ep;
@@ -503,7 +541,7 @@ void exfat_remove_entries(struct inode *inode, struct exfat_entry_set_cache *es,for (i = order; i < es->num_entries; i++) { ep =exfat_get_dentry_cached (es, i); -if (exfat_get_entry_type (ep) &TYPE_BENIGN_SEC ) +if (free_benign && (exfat_get_entry_type (ep) &TYPE_BENIGN_SEC ))exfat_free_benign_secondary_clusters (inode, ep);exfat_set_entry_type (ep,TYPE_DELETED );
fs/exfat/exfat_fs.h +3 -2
@@ -592,9 +592,10 @@ void exfat_init_dir_entry(struct exfat_entry_set_cache *es, unsigned int type, unsigned int start_clu, unsigned long long size, struct timespec64 *ts);void exfat_init_ext_entry (struct exfat_entry_set_cache *es,int num_entries, -struct exfat_uni_name *p_uniname); +struct exfat_uni_name *p_uniname, +struct exfat_entry_set_cache *old_es,int num_extra);void exfat_remove_entries (struct inode *inode,struct exfat_entry_set_cache *es, -int order); +int order,bool free_benign);void exfat_update_dir_chksum (struct exfat_entry_set_cache *es);int exfat_calc_num_entries (struct exfat_uni_name *p_uniname); int exfat_find_dir_entry(struct super_block *sb, struct exfat_inode_info *ei,
fs/exfat/namei.c +69 -20
184 lines not on this page · raw message
PATCH 1/1 exfat: preserve benign secondary entries during rename and move
Commit 8258ef28001a ("exfat: handle unreconized benign secondary entries") added cluster freeing for benign secondary entries inside exfat_remove_entries(). However, exfat_remove_entries() is also called from the rename and move paths (exfat_rename_file and exfat_move_file), where the old entry set is being relocated rather than deleted. This causes benign secondary entries such as vendor extension entries to be silently destroyed on rename or cross-directory move, violating the exFAT spec requirement (section 8.2) that implementations preserve unrecognized benign secondary entries.
Fix this by adding a free_benign parameter to exfat_remove_entries() so callers can suppress cluster freeing during relocation, and extending exfat_init_ext_entry() to copy trailing benign secondary entries from the old entry set into the new one internally. Also clean up the error paths to delete newly allocated entries on failure.
--- fs/exfat/dir.c | 49 ++++++++++++++++++++++--- fs/exfat/exfat_fs.h | 5 ++- fs/exfat/namei.c | 89 +++++++++++++++++++++++++++++++++++---------- 3 files changed, 116 insertions(+), 27 deletions(-)
fs/exfat/dir.c +44 -5
@@ -481,31 +481,70 @@ static void exfat_free_benign_secondary_clusters(struct inode *inode,exfat_free_cluster (inode, &dir); } +/* +* exfat_init_ext_entry - initialize extension entries in a directory entry set +* @es: target entry set +* @num_entries: number of entries excluding benign secondary entries +* @p_uniname: filename to store +* @old_es: optional source entry set with benign secondary entries, or NULL +* @num_extra: number of benign secondary entries to copy from @old_es +* +* Set up the file, stream extension, and filename entries in @es, optionally +* preserving @num_extra benign secondary entries from @old_es. @es and @old_es +* may refer to the same entry set; excess entries are marked as deleted. +*/ void exfat_init_ext_entry (struct exfat_entry_set_cache *es,int num_entries, -struct exfat_uni_name *p_uniname) +struct exfat_uni_name *p_uniname, +struct exfat_entry_set_cache *old_es,int num_extra) { -int i; +int i, src_start =0 , old_num;unsigned short *uniname = p_uniname->name;struct exfat_dentry *ep; +if (WARN_ON (num_extra <0 || (num_extra && (!old_es || + old_es->num_entries <ES_IDX_FIRST_FILENAME + num_extra)))) + num_extra =0 ; + +/* +* Save old entry count and source position before modifying +* es->num_entries, since old_es and es may point to the same +* entry set. +*/ + old_num = es->num_entries; +if (old_es && num_extra >0 ) + src_start = old_es->num_entries - num_extra; + + es->num_entries = num_entries + num_extra; ep =exfat_get_dentry_cached (es,ES_IDX_FILE ); - ep->dentry.file.num_ext = (unsigned char )(num_entries -1 ); + ep->dentry.file.num_ext = (unsigned char )(num_entries -1 + num_extra); ep =exfat_get_dentry_cached (es,ES_IDX_STREAM ); ep->dentry.stream.name_len = p_uniname->name_len; ep->dentry.stream.name_hash =cpu_to_le16 (p_uniname->name_hash); +if (old_es && num_extra >0 ) { +for (i =0 ; i < num_extra; i++) + *exfat_get_dentry_cached (es, num_entries + i) = + *exfat_get_dentry_cached (old_es, src_start + i); + } +for (i =ES_IDX_FIRST_FILENAME ; i < num_entries; i++) { ep =exfat_get_dentry_cached (es, i);exfat_init_name_entry (ep, uniname); uniname +=EXFAT_FILE_NAME_LEN ; } +/* Mark excess old entries as deleted (in-place shrink) */ +for (i = num_entries + num_extra; i < old_num; i++) { + ep =exfat_get_dentry_cached (es, i); +exfat_set_entry_type (ep,TYPE_DELETED ); + } +exfat_update_dir_chksum (es); }void exfat_remove_entries (struct inode *inode,struct exfat_entry_set_cache *es, -int order) +int order,bool free_benign) {int i;struct exfat_dentry *ep;
@@ -513,7 +552,7 @@ void exfat_remove_entries(struct inode *inode, struct exfat_entry_set_cache *es,for (i = order; i < es->num_entries; i++) { ep =exfat_get_dentry_cached (es, i); -if (exfat_get_entry_type (ep) &TYPE_BENIGN_SEC ) +if (free_benign && (exfat_get_entry_type (ep) &TYPE_BENIGN_SEC ))exfat_free_benign_secondary_clusters (inode, ep);exfat_set_entry_type (ep,TYPE_DELETED );
fs/exfat/exfat_fs.h +3 -2
@@ -496,9 +496,10 @@ void exfat_init_dir_entry(struct exfat_entry_set_cache *es, unsigned int type, unsigned int start_clu, unsigned long long size, struct timespec64 *ts);void exfat_init_ext_entry (struct exfat_entry_set_cache *es,int num_entries, -struct exfat_uni_name *p_uniname); +struct exfat_uni_name *p_uniname, +struct exfat_entry_set_cache *old_es,int num_extra);void exfat_remove_entries (struct inode *inode,struct exfat_entry_set_cache *es, -int order); +int order,bool free_benign);void exfat_update_dir_chksum (struct exfat_entry_set_cache *es);int exfat_calc_num_entries (struct exfat_uni_name *p_uniname); int exfat_find_dir_entry(struct super_block *sb, struct exfat_inode_info *ei,
fs/exfat/namei.c +69 -20
184 lines not on this page · raw message
Signature · 1 line
2.45.2
Re: [PATCH 6.18.y] exfat: preserve benign secondary entries during rename and move
Quoted 5 lines
Commit
8258ef28001a("exfat: handle unreconized benign secondary entries") added cluster freeing for benign secondary entries insideexfat_remove_entries(). However,exfat_remove_entries()is also called from the rename and move paths (exfat_rename_fileandexfat_move_file), where the old entry set is being relocated rather than deleted.
Queued for 6.18, thanks.
Signature · 2 lines
Thanks, Sasha