ceph: fix variable dereferenced before check in ceph_umount_begin()
Subsystems (2)
Viacheslav Dubeyko
maintainerPATCH 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
@@ -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
Quoted 6 lines · Viacheslav Dubeyko
This patch moves pointer check before the first
dereference of the pointer.Reported-by kernel test robot <[email protected]>Reported-by Dan Carpenter <[email protected]>
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@@ -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 11 lines · Matthew Wilcox
Quoted 6 lines · Viacheslav Dubeyko
This patch moves pointer check before the first
dereference of the pointer.Reported-by kernel test robot <[email protected]>Reported-by Dan Carpenter <[email protected]>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@@ -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_infocan 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.
Christian Brauner
maintainerQuoted 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.Reported-by kernel test robot <[email protected]>Reported-by Dan Carpenter <[email protected]>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@@ -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_infocan be set to NULL, do you?
Quoted 2 lines
I assume because forced umount could happen anytime, potentially, we could have
sb->s_fs_infonot 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 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.Reported-by kernel test robot <[email protected]>Reported-by Dan Carpenter <[email protected]>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@@ -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_infocan 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_infonot 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.
Christian Brauner
maintainerQuoted 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.Reported-by kernel test robot <[email protected]>Reported-by Dan Carpenter <[email protected]>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@@ -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_infocan be set to NULL, do you?I assume because forced umount could happen anytime, potentially, we could have
sb->s_fs_infonot 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->clientpointer. 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.
Ilya Dryomov
maintainerQuoted 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.Reported-by kernel test robot <[email protected]>Reported-by Dan Carpenter <[email protected]>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@@ -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_infocan be set to NULL, do you?Quoted 2 lines
I assume because forced umount could happen anytime, potentially, we could have
sb->s_fs_infonot 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->clientpointer. Or, probably, completely remove this check here?If the
fsc->clientpointer 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
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.Reported-by kernel test robot <[email protected]>Reported-by Dan Carpenter <[email protected]>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@@ -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_infocan be set to NULL, do you?Quoted 2 lines
I assume because forced umount could happen anytime, potentially, we could have
sb->s_fs_infonot 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->clientpointer. Or, probably, completely remove this check here?If the
fsc->clientpointer 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->clientis ever NULLed -- the client is created right after fsc is allocated increate_fs_client()and destroyed right before fsc is freed indestroy_fs_client(). It seems like the check can just be removed.
Yeah, makes sense to me. I can rework it.
Thanks,
Slava.
Quoted 10 lines · Matthew Wilcox
Quoted 6 lines · Viacheslav Dubeyko
This patch moves pointer check before the first
dereference of the pointer.Reported-by kernel test robot <[email protected]>Reported-by Dan Carpenter <[email protected]>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