]> git.dujemihanovic.xyz Git - linux.git/commitdiff
ext4: use handle to mark fc as ineligible in __track_dentry_update()
authorLuis Henriques (SUSE) <luis.henriques@linux.dev>
Mon, 23 Sep 2024 10:49:08 +0000 (11:49 +0100)
committerTheodore Ts'o <tytso@mit.edu>
Fri, 4 Oct 2024 21:35:54 +0000 (17:35 -0400)
Calling ext4_fc_mark_ineligible() with a NULL handle is racy and may result
in a fast-commit being done before the filesystem is effectively marked as
ineligible.  This patch fixes the calls to this function in
__track_dentry_update() by adding an extra parameter to the callback used in
ext4_fc_track_template().

Suggested-by: Jan Kara <jack@suse.cz>
Signed-off-by: Luis Henriques (SUSE) <luis.henriques@linux.dev>
Reviewed-by: Jan Kara <jack@suse.cz>
Link: https://patch.msgid.link/20240923104909.18342-2-luis.henriques@linux.dev
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Cc: stable@kernel.org
fs/ext4/fast_commit.c

index eaa5f5b51f500bf6de3ccd97f1f75c64bfa3907b..b33664f6ce2abdc16a0b0b165a833ebb6eda0092 100644 (file)
@@ -379,7 +379,7 @@ void ext4_fc_mark_ineligible(struct super_block *sb, int reason, handle_t *handl
  */
 static int ext4_fc_track_template(
        handle_t *handle, struct inode *inode,
-       int (*__fc_track_fn)(struct inode *, void *, bool),
+       int (*__fc_track_fn)(handle_t *handle, struct inode *, void *, bool),
        void *args, int enqueue)
 {
        bool update = false;
@@ -396,7 +396,7 @@ static int ext4_fc_track_template(
                ext4_fc_reset_inode(inode);
                ei->i_sync_tid = tid;
        }
-       ret = __fc_track_fn(inode, args, update);
+       ret = __fc_track_fn(handle, inode, args, update);
        mutex_unlock(&ei->i_fc_lock);
 
        if (!enqueue)
@@ -420,7 +420,8 @@ struct __track_dentry_update_args {
 };
 
 /* __track_fn for directory entry updates. Called with ei->i_fc_lock. */
-static int __track_dentry_update(struct inode *inode, void *arg, bool update)
+static int __track_dentry_update(handle_t *handle, struct inode *inode,
+                                void *arg, bool update)
 {
        struct ext4_fc_dentry_update *node;
        struct ext4_inode_info *ei = EXT4_I(inode);
@@ -435,14 +436,14 @@ static int __track_dentry_update(struct inode *inode, void *arg, bool update)
 
        if (IS_ENCRYPTED(dir)) {
                ext4_fc_mark_ineligible(sb, EXT4_FC_REASON_ENCRYPTED_FILENAME,
-                                       NULL);
+                                       handle);
                mutex_lock(&ei->i_fc_lock);
                return -EOPNOTSUPP;
        }
 
        node = kmem_cache_alloc(ext4_fc_dentry_cachep, GFP_NOFS);
        if (!node) {
-               ext4_fc_mark_ineligible(sb, EXT4_FC_REASON_NOMEM, NULL);
+               ext4_fc_mark_ineligible(sb, EXT4_FC_REASON_NOMEM, handle);
                mutex_lock(&ei->i_fc_lock);
                return -ENOMEM;
        }
@@ -454,7 +455,7 @@ static int __track_dentry_update(struct inode *inode, void *arg, bool update)
                node->fcd_name.name = kmalloc(dentry->d_name.len, GFP_NOFS);
                if (!node->fcd_name.name) {
                        kmem_cache_free(ext4_fc_dentry_cachep, node);
-                       ext4_fc_mark_ineligible(sb, EXT4_FC_REASON_NOMEM, NULL);
+                       ext4_fc_mark_ineligible(sb, EXT4_FC_REASON_NOMEM, handle);
                        mutex_lock(&ei->i_fc_lock);
                        return -ENOMEM;
                }
@@ -576,7 +577,8 @@ void ext4_fc_track_create(handle_t *handle, struct dentry *dentry)
 }
 
 /* __track_fn for inode tracking */
-static int __track_inode(struct inode *inode, void *arg, bool update)
+static int __track_inode(handle_t *handle, struct inode *inode, void *arg,
+                        bool update)
 {
        if (update)
                return -EEXIST;
@@ -614,7 +616,8 @@ struct __track_range_args {
 };
 
 /* __track_fn for tracking data updates */
-static int __track_range(struct inode *inode, void *arg, bool update)
+static int __track_range(handle_t *handle, struct inode *inode, void *arg,
+                        bool update)
 {
        struct ext4_inode_info *ei = EXT4_I(inode);
        ext4_lblk_t oldstart;