Skip to contentSkip to conversation

VFS: Fix fuseblk memory leak caused by mount concurrency

PATCH In review ChenXiaoSong 2 participants 7 messages Oct 13, 2021 – Oct 26, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 VFS: Fix fuseblk memory leak caused by mount concurrency

If two processes mount same superblock, memory leak occurs:

CPU0               |  CPU1
do_new_mount       |  do_new_mount
  fs_set_subtype   |    fs_set_subtype
    kstrdup        |
                   |      kstrdup
    memrory leak   |

Fix this by adding a write lock while calling fs_set_subtype.

Linus's tree already have refactoring patchset [1], one of them can fix this bug:
c30da2e981a7 (fuse: convert to use the new mount API)

Since we did not merge the refactoring patchset in this branch, I create this patch.

[1] https://patchwork.kernel.org/project/linux-fsdevel/patch/[email protected]/

Fixes 79c0b2df79eb (add filesystem subtype support)
Cc David Howells <[email protected]>

---
v1: Can not mount sshfs ([PATCH linux-4.19.y] VFS: Fix fuseblk memory leak caused by mount concurrency)
v2: Use write lock while writing superblock

 fs/namespace.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
fs/namespace.c +6 -3
index 2f3c6a0350a8..396ff1bcfdad 100644
@@ -2490,9 +2490,12 @@ static int do_new_mount(struct path *path, const char *fstype, int sb_flags,
 		return -ENODEV;
 
 	mnt = vfs_kern_mount(type, sb_flags, name, data);
-	if (!IS_ERR(mnt) && (type->fs_flags & FS_HAS_SUBTYPE) &&
-	    !mnt->mnt_sb->s_subtype)
-		mnt = fs_set_subtype(mnt, fstype);
+	if (!IS_ERR(mnt) && (type->fs_flags & FS_HAS_SUBTYPE)) {
+		down_write(&mnt->mnt_sb->s_umount);
+		if (!mnt->mnt_sb->s_subtype)
+			mnt = fs_set_subtype(mnt, fstype);
+		up_write(&mnt->mnt_sb->s_umount);
+	}
 
 	put_filesystem(type);
 	if (IS_ERR(mnt))
Signature · 1 line
2.25.4
maintainer
#1 lore raw
Quoted 21 lines · ChenXiaoSong

If two processes mount same superblock, memory leak occurs:

CPU0               |  CPU1
do_new_mount       |  do_new_mount
  fs_set_subtype   |    fs_set_subtype
    kstrdup        |
                   |      kstrdup
    memrory leak   |

Fix this by adding a write lock while calling fs_set_subtype.

Linus's tree already have refactoring patchset [1], one of them can fix this bug:
c30da2e981a7 (fuse: convert to use the new mount API)

Since we did not merge the refactoring patchset in this branch, I create this patch.

[1] https://patchwork.kernel.org/project/linux-fsdevel/patch/[email protected]/

Fixes 79c0b2df79eb (add filesystem subtype support)
Cc David Howells <[email protected]>
Quoted 6 lines

---
v1: Can not mount sshfs ([PATCH linux-4.19.y] VFS: Fix fuseblk memory leak caused by mount concurrency)
v2: Use write lock while writing superblock

 fs/namespace.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

As you are referring to a fuse-only patch above, why are you trying to resolve this issue in the core namespace code instead?

How does fuse have anything to do with this?

confused,

greg k-h

#2 lore raw
Quoted 32 lines · Greg KH
Quoted 21 lines · ChenXiaoSong

If two processes mount same superblock, memory leak occurs:

CPU0               |  CPU1
do_new_mount       |  do_new_mount
   fs_set_subtype   |    fs_set_subtype
     kstrdup        |
                    |      kstrdup
     memrory leak   |

Fix this by adding a write lock while calling fs_set_subtype.

Linus's tree already have refactoring patchset [1], one of them can fix this bug:
c30da2e981a7 (fuse: convert to use the new mount API)

Since we did not merge the refactoring patchset in this branch, I create this patch.

[1] https://patchwork.kernel.org/project/linux-fsdevel/patch/[email protected]/

Fixes 79c0b2df79eb (add filesystem subtype support)
Cc David Howells <[email protected]>
Quoted 6 lines

---
v1: Can not mount sshfs ([PATCH linux-4.19.y] VFS: Fix fuseblk memory leak caused by mount concurrency)
v2: Use write lock while writing superblock

  fs/namespace.c | 9 ++++++---
  1 file changed, 6 insertions(+), 3 deletions(-)

As you are referring to a fuse-only patch above, why are you trying to resolve this issue in the core namespace code instead?

Quoted 7 lines

How does fuse have anything to do with this?

confused,

greg k-h
.

Now, only fuse_fs_type and fuseblk_fs_type has FS_HAS_SUBTYPE flag in kernel code, but maybe there is a filesystem module(struct file_system_type has FS_HAS_SUBTYPE flag). And only mounting fuseblk filesystem(e.g. ntfs) will occur memory leak now.

#3 lore raw
Quoted 36 lines · chenxiaosong (A)
Quoted 35 lines · Greg KH
Quoted 22 lines · ChenXiaoSong

If two processes mount same superblock, memory leak occurs:

CPU0               |  CPU1
do_new_mount       |  do_new_mount
   fs_set_subtype   |    fs_set_subtype
     kstrdup        |
                    |      kstrdup
     memrory leak   |

Fix this by adding a write lock while calling fs_set_subtype.

Linus's tree already have refactoring patchset [1], one of them can fix this bug:
         c30da2e981a7 (fuse: convert to use the new mount API)

Since we did not merge the refactoring patchset in this branch, I create this patch.

[1] https://patchwork.kernel.org/project/linux-fsdevel/patch/[email protected]/

Fixes 79c0b2df79eb (add filesystem subtype support)
Cc David Howells <[email protected]>
Quoted 6 lines

---
v1: Can not mount sshfs ([PATCH linux-4.19.y] VFS: Fix fuseblk memory leak caused by mount concurrency)
v2: Use write lock while writing superblock

  fs/namespace.c | 9 ++++++---

  1 file changed, 6 insertions(+), 3 deletions(-)

As you are referring to a fuse-only patch above, why are you trying to resolve this issue in the core namespace code instead?

How does fuse have anything to do with this?

Quoted 7 lines
Quoted 5 lines

confused,

greg k-h
.

Now, only fuse_fs_type and fuseblk_fs_type has FS_HAS_SUBTYPE flag in kernel code, but maybe there is a filesystem module(struct file_system_type has FS_HAS_SUBTYPE flag). And only mounting fuseblk filesystem(e.g. ntfs) will occur memory leak now.

How about updating the subject as: VFS: Fix memory leak caused by mounting fs with subtype concurrency?

maintainer
#4 lore raw
Quoted 46 lines · chenxiaosong (A)
Quoted 45 lines · chenxiaosong (A)
Quoted 43 lines · Greg KH
Quoted 24 lines · ChenXiaoSong

If two processes mount same superblock, memory leak occurs:

CPU0               |  CPU1
do_new_mount       |  do_new_mount
   fs_set_subtype   |    fs_set_subtype
     kstrdup        |
                    |      kstrdup
     memrory leak   |

Fix this by adding a write lock while calling fs_set_subtype.

Linus's tree already have refactoring patchset [1], one of them can fix this bug:
         c30da2e981a7 (fuse: convert to use the new mount API)

Since we did not merge the refactoring patchset in this branch, I create this patch.

[1] https://patchwork.kernel.org/project/linux-fsdevel/patch/[email protected]/

Fixes 79c0b2df79eb (add filesystem subtype support)
Cc David Howells <[email protected]>
Quoted 7 lines

---
v1: Can not mount sshfs ([PATCH linux-4.19.y] VFS: Fix fuseblk memory leak caused by mount concurrency)
v2: Use write lock while writing superblock

  fs/namespace.c | 9 ++++++---

  1 file changed, 6 insertions(+), 3 deletions(-)

As you are referring to a fuse-only patch above, why are you trying to resolve this issue in the core namespace code instead?

How does fuse have anything to do with this?

confused,

greg k-h
.

Quoted 7 lines
Quoted 4 lines

Now, only fuse_fs_type and fuseblk_fs_type has FS_HAS_SUBTYPE flag in kernel code, but maybe there is a filesystem module(struct file_system_type has FS_HAS_SUBTYPE flag). And only mounting fuseblk filesystem(e.g. ntfs) will occur memory leak now.

How about updating the subject as: VFS: Fix memory leak caused by mounting fs with subtype concurrency?

That would be a better idea, but still, this is not obvious that this is the correct fix at all...

#5 lore raw
Quoted 52 lines · Greg KH
Quoted 51 lines · chenxiaosong (A)
Quoted 49 lines · chenxiaosong (A)
Quoted 36 lines · Greg KH
Quoted 24 lines · ChenXiaoSong

If two processes mount same superblock, memory leak occurs:

CPU0               |  CPU1
do_new_mount       |  do_new_mount
   fs_set_subtype   |    fs_set_subtype
     kstrdup        |
                    |      kstrdup
     memrory leak   |

Fix this by adding a write lock while calling fs_set_subtype.

Linus's tree already have refactoring patchset [1], one of them can fix this bug:
         c30da2e981a7 (fuse: convert to use the new mount API)

Since we did not merge the refactoring patchset in this branch, I create this patch.

[1] https://patchwork.kernel.org/project/linux-fsdevel/patch/[email protected]/

Fixes 79c0b2df79eb (add filesystem subtype support)
Cc David Howells <[email protected]>
Quoted 7 lines

---
v1: Can not mount sshfs ([PATCH linux-4.19.y] VFS: Fix fuseblk memory leak caused by mount concurrency)
v2: Use write lock while writing superblock

   fs/namespace.c | 9 ++++++---
   1 file changed, 6 insertions(+), 3 deletions(-)

As you are referring to a fuse-only patch above, why are you trying to resolve this issue in the core namespace code instead?

Quoted 7 lines

How does fuse have anything to do with this?

confused,

greg k-h
.

Now, only fuse_fs_type and fuseblk_fs_type has FS_HAS_SUBTYPE flag in kernel code, but maybe there is a filesystem module(struct file_system_type has FS_HAS_SUBTYPE flag). And only mounting fuseblk filesystem(e.g. ntfs) will occur memory leak now.

Quoted 7 lines
Quoted 2 lines

How about updating the subject as: VFS: Fix memory leak caused by mounting fs with subtype concurrency?

That would be a better idea, but still, this is not obvious that this is the correct fix at all...
.

Why is this patch not correct? Can you tell me more about it? Thanks.

maintainer
#6 lore raw
Quoted 55 lines · chenxiaosong (A)
Quoted 52 lines · Greg KH
Quoted 51 lines · chenxiaosong (A)
Quoted 49 lines · chenxiaosong (A)
Quoted 36 lines · Greg KH
Quoted 24 lines · ChenXiaoSong

If two processes mount same superblock, memory leak occurs:

CPU0               |  CPU1
do_new_mount       |  do_new_mount
   fs_set_subtype   |    fs_set_subtype
     kstrdup        |
                    |      kstrdup
     memrory leak   |

Fix this by adding a write lock while calling fs_set_subtype.

Linus's tree already have refactoring patchset [1], one of them can fix this bug:
         c30da2e981a7 (fuse: convert to use the new mount API)

Since we did not merge the refactoring patchset in this branch, I create this patch.

[1] https://patchwork.kernel.org/project/linux-fsdevel/patch/[email protected]/

Fixes 79c0b2df79eb (add filesystem subtype support)
Cc David Howells <[email protected]>
Quoted 7 lines

---
v1: Can not mount sshfs ([PATCH linux-4.19.y] VFS: Fix fuseblk memory leak caused by mount concurrency)
v2: Use write lock while writing superblock

   fs/namespace.c | 9 ++++++---
   1 file changed, 6 insertions(+), 3 deletions(-)

As you are referring to a fuse-only patch above, why are you trying to resolve this issue in the core namespace code instead?

Quoted 7 lines

How does fuse have anything to do with this?

confused,

greg k-h
.

Now, only fuse_fs_type and fuseblk_fs_type has FS_HAS_SUBTYPE flag in kernel code, but maybe there is a filesystem module(struct file_system_type has FS_HAS_SUBTYPE flag). And only mounting fuseblk filesystem(e.g. ntfs) will occur memory leak now.

Quoted 8 lines
Quoted 7 lines
Quoted 2 lines

How about updating the subject as: VFS: Fix memory leak caused by mounting fs with subtype concurrency?

That would be a better idea, but still, this is not obvious that this is the correct fix at all...
.

Why is this patch not correct? Can you tell me more about it? Thanks.

You need to prove that it is correct, and you need to get maintainers to approve it.

thanks,

greg k-h