Skip to contentSkip to conversation

ceph: fix variable dereferenced before check in ceph_umount_begin()

PATCH Superseded Viacheslav Dubeyko 6 participants 9 messages Mar 28, 2025 – Jun 2, 2025

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Viacheslav Dubeyko

author maintainer
#0 lore raw

PATCH 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);
}

This patch moves pointer check before the first
dereference of the pointer.

---
 fs/ceph/super.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
fs/ceph/super.c +3 -1
index f3951253e393..6cbc33c56e0e 100644
@@ -1032,9 +1032,11 @@ 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;
+
+	doutc(fsc->client, "starting forced umount\n");
+
 	fsc->mount_state = CEPH_MOUNT_SHUTDOWN;
 	__ceph_umount_begin(fsc);
 }
Signature · 1 line
2.48.0
#1 lore raw
Quoted 6 lines · Viacheslav Dubeyko

This patch moves pointer check before the first
dereference of the pointer.

Ooh, that's not good. Need to figure out a way to defeat the proofpoint garbage.

fs/ceph/super.c void ceph_umount_begin(struct super_block *sb) · line 1038

Quoted 13 lines
fs/ceph/super.c +2 -1
index f3951253e393..6cbc33c56e0e 100644
@@ -1032,9 +1032,11 @@ 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;
+
+	doutc(fsc->client, "starting forced umount\n");

I don't think we should be checking fsc against NULL. I don't see a way that sb->s_fs_info can be set to NULL, do you?

#2 lore raw
Quoted 11 lines · Matthew Wilcox
Quoted 6 lines · Viacheslav Dubeyko

This patch moves pointer check before the first
dereference of the pointer.

Ooh, that's not good. Need to figure out a way to defeat the proofpoint garbage.

Yeah, this is not good.

Quoted 8 lines
Quoted 8 lines
fs/ceph/super.c +0 -0
index f3951253e393..6cbc33c56e0e 100644
@@ -1032,9 +1032,11 @@ void ceph_umount_begin(struct super_block *sb)
 {
 	struct ceph_fs_client *fsc = ceph_sb_to_fs_client(sb);
 
Quoted 8 lines

fs/ceph/super.c void ceph_umount_begin(struct super_block *sb) · line 1038

Quoted 5 lines
fs/ceph/super.c +2 -1
-	doutc(fsc->client, "starting forced umount\n");
 	if (!fsc)
 		return;
+
+	doutc(fsc->client, "starting forced umount\n");

I don't think we should be checking fsc against NULL. I don't see a way that sb->s_fs_info can be set to NULL, do you?

I assume because forced umount could happen anytime, potentially, we could have sb->s_fs_info not set. But, frankly speaking, I started to worry about fsc-

Quoted 1 line

client:

struct ceph_fs_client {
	struct super_block *sb;

	struct list_head metric_wakeup;

	struct ceph_mount_options *mount_options;
	struct ceph_client *client;
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^
        We are trying to access the client pointer in debug output. 

<skipped>
};

So, maybe, we need to add fsc->client check here too.

Thanks,
Slava.

#3 lore raw
Quoted 32 lines · Viacheslav Dubeyko
Quoted 11 lines · Matthew Wilcox
Quoted 6 lines · Viacheslav Dubeyko

This patch moves pointer check before the first
dereference of the pointer.

Ooh, that's not good. Need to figure out a way to defeat the proofpoint garbage.

Yeah, this is not good.

Quoted 8 lines
Quoted 8 lines
fs/ceph/super.c +0 -0
index f3951253e393..6cbc33c56e0e 100644
@@ -1032,9 +1032,11 @@ void ceph_umount_begin(struct super_block *sb)
 {
 	struct ceph_fs_client *fsc = ceph_sb_to_fs_client(sb);
 
Quoted 8 lines

fs/ceph/super.c void ceph_umount_begin(struct super_block *sb) · line 1038

Quoted 5 lines
fs/ceph/super.c +2 -1
-	doutc(fsc->client, "starting forced umount\n");
 	if (!fsc)
 		return;
+
+	doutc(fsc->client, "starting forced umount\n");

I don't think we should be checking fsc against NULL. I don't see a way that sb->s_fs_info can be set to NULL, do you?

Quoted 2 lines

I assume because forced umount could happen anytime, potentially, we could have sb->s_fs_info not set. But, frankly speaking, I started to worry about fsc-

No, it must be set. The VFS guarantees that the superblock is still alive when it calls into ceph via ->umount_begin().

#4 lore raw
Quoted 33 lines · Christian Brauner
Quoted 32 lines · Viacheslav Dubeyko
Quoted 11 lines · Matthew Wilcox
Quoted 6 lines · Viacheslav Dubeyko

This patch moves pointer check before the first
dereference of the pointer.

Ooh, that's not good. Need to figure out a way to defeat the proofpoint garbage.

Yeah, this is not good.

Quoted 16 lines

fs/ceph/super.c void ceph_umount_begin(struct super_block *sb) · line 1038

Quoted 13 lines
fs/ceph/super.c +2 -1
index f3951253e393..6cbc33c56e0e 100644
@@ -1032,9 +1032,11 @@ 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;
+
+	doutc(fsc->client, "starting forced umount\n");

I don't think we should be checking fsc against NULL. I don't see a way that sb->s_fs_info can be set to NULL, do you?

Quoted 5 lines
Quoted 2 lines

I assume because forced umount could happen anytime, potentially, we could have sb->s_fs_info not set. But, frankly speaking, I started to worry about fsc-

No, it must be set. The VFS guarantees that the superblock is still alive when it calls into ceph via ->umount_begin().

So, if we have the guarantee of fsc pointer validity, then we need to change this checking of fsc->client pointer. Or, probably, completely remove this check here?

Thanks,
Slava.

#5 lore raw
Quoted 37 lines · Viacheslav Dubeyko
Quoted 36 lines · Christian Brauner
Quoted 34 lines · Viacheslav Dubeyko
Quoted 11 lines · Matthew Wilcox
Quoted 6 lines · Viacheslav Dubeyko

This patch moves pointer check before the first
dereference of the pointer.

Ooh, that's not good. Need to figure out a way to defeat the proofpoint garbage.

Yeah, this is not good.

Quoted 8 lines
Quoted 8 lines
fs/ceph/super.c +0 -0
index f3951253e393..6cbc33c56e0e 100644
@@ -1032,9 +1032,11 @@ void ceph_umount_begin(struct super_block *sb)
 {
 	struct ceph_fs_client *fsc = ceph_sb_to_fs_client(sb);
 
Quoted 8 lines

fs/ceph/super.c void ceph_umount_begin(struct super_block *sb) · line 1038

Quoted 5 lines
fs/ceph/super.c +2 -1
-	doutc(fsc->client, "starting forced umount\n");
 	if (!fsc)
 		return;
+
+	doutc(fsc->client, "starting forced umount\n");

I don't think we should be checking fsc against NULL. I don't see a way that sb->s_fs_info can be set to NULL, do you?

I assume because forced umount could happen anytime, potentially, we could have sb->s_fs_info not set. But, frankly speaking, I started to worry about fsc-

Quoted 6 lines
Quoted 2 lines

No, it must be set. The VFS guarantees that the superblock is still alive when it calls into ceph via ->umount_begin().

So, if we have the guarantee of fsc pointer validity, then we need to change this checking of fsc->client pointer. Or, probably, completely remove this check here?

If the fsc->client pointer can be NULLed before the mount is shut down then yes. If it can't then the check can be removed completely.

maintainer
#6 lore raw
Quoted 42 lines · Christian Brauner
Quoted 40 lines · Viacheslav Dubeyko
Quoted 38 lines · Christian Brauner
Quoted 32 lines · Viacheslav Dubeyko
Quoted 11 lines · Matthew Wilcox
Quoted 6 lines · Viacheslav Dubeyko

This patch moves pointer check before the first
dereference of the pointer.

Ooh, that's not good. Need to figure out a way to defeat the proofpoint garbage.

Yeah, this is not good.

Quoted 8 lines
Quoted 8 lines
fs/ceph/super.c +0 -0
index f3951253e393..6cbc33c56e0e 100644
@@ -1032,9 +1032,11 @@ void ceph_umount_begin(struct super_block *sb)
 {
      struct ceph_fs_client *fsc = ceph_sb_to_fs_client(sb);
 
Quoted 8 lines

fs/ceph/super.c void ceph_umount_begin(struct super_block *sb) · line 1038

Quoted 5 lines
fs/ceph/super.c +2 -1
-     doutc(fsc->client, "starting forced umount\n");
      if (!fsc)
              return;
+
+     doutc(fsc->client, "starting forced umount\n");

I don't think we should be checking fsc against NULL. I don't see a way that sb->s_fs_info can be set to NULL, do you?

Quoted 2 lines

I assume because forced umount could happen anytime, potentially, we could have sb->s_fs_info not set. But, frankly speaking, I started to worry about fsc-

No, it must be set. The VFS guarantees that the superblock is still alive when it calls into ceph via ->umount_begin().

Quoted 6 lines
Quoted 3 lines

So, if we have the guarantee of fsc pointer validity, then we need to change this checking of fsc->client pointer. Or, probably, completely remove this check here?

If the fsc->client pointer can be NULLed before the mount is shut down then yes. If it can't then the check can be removed completely.

Hi Slava,

Have you had a chance to follow up on this? Given the VFS guarantee confirmed by Christian we don't need to check fsc and I don't think fsc->client is ever NULLed -- the client is created right after fsc is allocated in create_fs_client() and destroyed right before fsc is freed in destroy_fs_client(). It seems like the check can just be removed.

Thanks,

Ilya

#7 lore raw
Quoted 50 lines · Ilya Dryomov
Quoted 42 lines · Christian Brauner
Quoted 40 lines · Viacheslav Dubeyko
Quoted 38 lines · Christian Brauner
Quoted 32 lines · Viacheslav Dubeyko
Quoted 11 lines · Matthew Wilcox
Quoted 6 lines · Viacheslav Dubeyko

This patch moves pointer check before the first
dereference of the pointer.

Ooh, that's not good. Need to figure out a way to defeat the proofpoint garbage.

Yeah, this is not good.

Quoted 8 lines
Quoted 8 lines
fs/ceph/super.c +0 -0
index f3951253e393..6cbc33c56e0e 100644
@@ -1032,9 +1032,11 @@ void ceph_umount_begin(struct super_block *sb)
 {
      struct ceph_fs_client *fsc = ceph_sb_to_fs_client(sb);
 
Quoted 8 lines

fs/ceph/super.c void ceph_umount_begin(struct super_block *sb) · line 1038

Quoted 5 lines
fs/ceph/super.c +2 -1
-     doutc(fsc->client, "starting forced umount\n");
      if (!fsc)
              return;
+
+     doutc(fsc->client, "starting forced umount\n");

I don't think we should be checking fsc against NULL. I don't see a way that sb->s_fs_info can be set to NULL, do you?

Quoted 2 lines

I assume because forced umount could happen anytime, potentially, we could have sb->s_fs_info not set. But, frankly speaking, I started to worry about fsc-

No, it must be set. The VFS guarantees that the superblock is still alive when it calls into ceph via ->umount_begin().

Quoted 6 lines
Quoted 3 lines

So, if we have the guarantee of fsc pointer validity, then we need to change this checking of fsc->client pointer. Or, probably, completely remove this check here?

If the fsc->client pointer can be NULLed before the mount is shut down then yes. If it can't then the check can be removed completely.

Quoted 8 lines

Hi Slava,

Have you had a chance to follow up on this? Given the VFS guarantee confirmed by Christian we don't need to check fsc and I don't think fsc->client is ever NULLed -- the client is created right after fsc is allocated in create_fs_client() and destroyed right before fsc is freed in destroy_fs_client(). It seems like the check can just be removed.

Yeah, makes sense to me. I can rework it.

Thanks,
Slava.

#8 lore raw
In reply to Matthew Wilcox
Quoted 10 lines · Matthew Wilcox
Quoted 6 lines · Viacheslav Dubeyko

This patch moves pointer check before the first
dereference of the pointer.

Ooh, that's not good. Need to figure out a way to defeat the proofpoint garbage.

Option 1 for procmail users:
https://github.com/wjshamblin/proofpoint_rewrite

Option 2: Copy the tag from lore.
https://lore.kernel.org/all/?q=ceph_umount_begin

regards,
dan carpenter