From: Pavel Tikhomirov <ptikhomi...@virtuozzo.com>

Move the nr_files check before accessing files[0] to avoid potential
null pointer dereference when nr_files is 0.

This improves safety by failing fast when there are no files to sync.

Part of rework for ext4_sync_files function.

Fixes: 26337aacaafa9 ("ext4: add mfsync support")
https://virtuozzo.atlassian.net/browse/VSTOR-107255
Signed-off-by: Pavel Tikhomirov <ptikhomi...@virtuozzo.com>

Feature: ext4: optimized sync of a set of files - mfsync()
---
 fs/ext4/fsync.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/fs/ext4/fsync.c b/fs/ext4/fsync.c
index 0a210181f20ab..f31086efb7977 100644
--- a/fs/ext4/fsync.c
+++ b/fs/ext4/fsync.c
@@ -186,14 +186,14 @@ int ext4_sync_files(struct file **files, unsigned int 
*flags, unsigned int nr_fi
        int need_barrier = 0;
        int ret;
 
+       if (!nr_files)
+               return 0;
        sb = files[0]->f_mapping->host->i_sb;
        ret = ext4_emergency_state(sb);
        if (unlikely(ret))
                return ret;
 
        J_ASSERT(ext4_journal_current_handle() == NULL);
-       if (!nr_files)
-               return 0;
 
        journal = EXT4_SB(sb)->s_journal;
        if (sb_rdonly(sb)) {
-- 
2.43.0

_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel

Reply via email to