Skip to contentSkip to conversation

ceph: fix variable dereferenced before check in ceph_umount_begin()

PATCH In review Viacheslav Dubeyko 3 participants 3 messages Jun 2, 2025 – Jun 6, 2025

Subsystems (2)
lore
Share & tools
lore

Viacheslav Dubeyko

author maintainer
#0 lore raw

PATCH v2 1/1 ceph: fix variable dereferenced before check in ceph_umount_begin()

From: Viacheslav Dubeyko <[email protected]>

smatch warnings:
fs/ceph/super.c:1042 ceph_umount_begin() warn: variable dereferenced before check 'fsc' (see line 1041)

vim +/fsc +1042 fs/ceph/super.c

void ceph_umount_begin(struct super_block *sb)

{
	struct ceph_fs_client *fsc = ceph_sb_to_fs_client(sb);

	doutc(fsc->client, "starting forced umount\n");
              ^^^^^^^^^^^

Dereferenced

	if (!fsc)
            ^^^^

Checked too late.

		return;
	fsc->mount_state = CEPH_MOUNT_SHUTDOWN;
	__ceph_umount_begin(fsc);
}

The VFS guarantees that the superblock is still alive when it calls into ceph via ->umount_begin(). Finally, we don't need to check the fsc and it should be valid. This patch simply removes the fsc check.

---
 fs/ceph/super.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
fs/ceph/super.c +1 -2
index f3951253e393..68a6d434093f 100644
@@ -1033,8 +1033,7 @@ void ceph_umount_begin(struct super_block *sb)
 	struct ceph_fs_client *fsc = ceph_sb_to_fs_client(sb);
 
 	doutc(fsc->client, "starting forced umount\n");
-	if (!fsc)
-		return;
+
 	fsc->mount_state = CEPH_MOUNT_SHUTDOWN;
 	__ceph_umount_begin(fsc);
 }
Signature · 1 line
2.49.0
maintainer
#1 lore raw

Reviewed by: Alex Markuze <[email protected]>

Quoted 56 lines · Viacheslav Dubeyko

From: Viacheslav Dubeyko <[email protected]>

smatch warnings:
fs/ceph/super.c:1042 ceph_umount_begin() warn: variable dereferenced before check 'fsc' (see line 1041)

vim +/fsc +1042 fs/ceph/super.c

void ceph_umount_begin(struct super_block *sb)

{
        struct ceph_fs_client *fsc = ceph_sb_to_fs_client(sb);

        doutc(fsc->client, "starting forced umount\n");
              ^^^^^^^^^^^

Dereferenced

        if (!fsc)
            ^^^^

Checked too late.

                return;
        fsc->mount_state = CEPH_MOUNT_SHUTDOWN;
        __ceph_umount_begin(fsc);
}

The VFS guarantees that the superblock is still alive when it calls into ceph via ->umount_begin(). Finally, we don't need to check the fsc and it should be valid. This patch simply removes the fsc check.

---
 fs/ceph/super.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
fs/ceph/super.c +1 -3
index f3951253e393..68a6d434093f 100644
@@ -1033,8 +1033,7 @@ void ceph_umount_begin(struct super_block *sb)
        struct ceph_fs_client *fsc = ceph_sb_to_fs_client(sb);
 
        doutc(fsc->client, "starting forced umount\n");
-       if (!fsc)
-               return;
+
        fsc->mount_state = CEPH_MOUNT_SHUTDOWN;
        __ceph_umount_begin(fsc);
 }
--

2.49.0

maintainer
#2 lore raw
Quoted 50 lines · Alex Markuze

Reviewed by: Alex Markuze <[email protected]>

Quoted 46 lines · Viacheslav Dubeyko

From: Viacheslav Dubeyko <[email protected]>

smatch warnings:
fs/ceph/super.c:1042 ceph_umount_begin() warn: variable dereferenced before check 'fsc' (see line 1041)

vim +/fsc +1042 fs/ceph/super.c

void ceph_umount_begin(struct super_block *sb)

{
        struct ceph_fs_client *fsc = ceph_sb_to_fs_client(sb);

        doutc(fsc->client, "starting forced umount\n");
              ^^^^^^^^^^^

Dereferenced

        if (!fsc)
            ^^^^

Checked too late.

                return;
        fsc->mount_state = CEPH_MOUNT_SHUTDOWN;
        __ceph_umount_begin(fsc);
}

The VFS guarantees that the superblock is still alive when it calls into ceph via ->umount_begin(). Finally, we don't need to check the fsc and it should be valid. This patch simply removes the fsc check.

---
 fs/ceph/super.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
fs/ceph/super.c +0 -0
index f3951253e393..68a6d434093f 100644
@@ -1033,8 +1033,7 @@ void ceph_umount_begin(struct super_block *sb)
        struct ceph_fs_client *fsc = ceph_sb_to_fs_client(sb);
 
Quoted 11 lines
Quoted 10 lines
fs/ceph/super.c +1 -3
        doutc(fsc->client, "starting forced umount\n");
-       if (!fsc)
-               return;
+
        fsc->mount_state = CEPH_MOUNT_SHUTDOWN;
        __ceph_umount_begin(fsc);
 }
--

2.49.0

Applied with the Closes tag amended (Proofpoint URL).

Thanks,

Ilya