statmount: Fix the null-ptr-deref in do_statmount()
PATCH v3 1/1 statmount: Fix the null-ptr-deref in do_statmount()
If the mount is internal, it's mnt_ns will be MNT_NS_INTERNAL, which is defined as ERR_PTR(-EINVAL). So, in the do_statmount(), need to check ns of mount by IS_ERR() and return.
--- fs/namespace.c | 2 ++ 1 file changed, 2 insertions(+)
fs/namespace.c +2 -0
@@ -5678,6 +5678,8 @@ static int do_statmount(struct kstatmount *s, u64 mnt_id, u64 mnt_ns_id, s->mnt = mnt_file->f_path.mnt; ns =real_mount (s->mnt)->mnt_ns; +if (IS_ERR (ns)) +return PTR_ERR (ns);if (!ns)/* * We can't set mount point and mnt_ns_id since we don't have a
Signature · 1 line
2.34.1
Quoted 17 lines · Qing Wang
If the mount is internal, it's
mnt_nswill beMNT_NS_INTERNAL, which is defined asERR_PTR(-EINVAL). So, in thedo_statmount(), need to check ns of mount byIS_ERR()and return.Fixes 0e5032237ee5 ("statmount: accept fd as a parameter")Reported-by [email protected]Signed-off-by Qing Wang <[email protected]>--- fs/namespace.c | 2 ++ 1 file changed, 2 insertions(+)fs/namespace.c +0
-0
fs/namespace.c static int do_statmount(struct kstatmount *s, u64 mnt_id, u64 mnt_ns_id, · line 5685
Quoted 8 lines
fs/namespace.c +2
-0@@ -5678,6 +5678,8 @@ static int do_statmount(struct kstatmount *s, u64 mnt_id, u64 mnt_ns_id, s->mnt = mnt_file->f_path.mnt; ns =real_mount (s->mnt)->mnt_ns; +if (IS_ERR (ns)) +return PTR_ERR (ns);if (!ns)/* * We can't set mount point and mnt_ns_id since we don't have a
Looks good to me.
Quoted 5 lines · Qing Wang
If the mount is internal, it's
mnt_nswill beMNT_NS_INTERNAL, which is defined asERR_PTR(-EINVAL). So, in thedo_statmount(), need to check ns of mount byIS_ERR()and return.
Applied to the vfs.fixes branch of the vfs/vfs.git tree. Patches in the vfs.fixes branch should appear in linux-next soon.
Please report any outstanding bugs that were missed during review in a new review to the original patch series allowing us to drop it.
It's encouraged to provide Acked-bys and Reviewed-bys even though the patch has now been applied. If possible patch trailers will be updated.
Note that commit hashes shown below are subject to change due to rebase, trailer updates or similar. If in doubt, please check the listed branch.
tree: https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git branch: vfs.fixes
[1/1] statmount: Fix the null-ptr-deref in do_statmount()
https://git.kernel.org/vfs/vfs/c/81f16c9778d7
Quoted 18 lines · Qing Wang
If the mount is internal, it's
mnt_nswill beMNT_NS_INTERNAL, which is defined asERR_PTR(-EINVAL). So, in thedo_statmount(), need to check ns of mount byIS_ERR()and return.Fixes 0e5032237ee5 ("statmount: accept fd as a parameter")Reported-by [email protected]Signed-off-by Qing Wang <[email protected]>--- fs/namespace.c | 2 ++ 1 file changed, 2 insertions(+)fs/namespace.c +0
-0
fs/namespace.c static int do_statmount(struct kstatmount *s, u64 mnt_id, u64 mnt_ns_id, · line 5682
Quoted 5 lines
fs/namespace.c +2
-0@@ -5678,6 +5678,8 @@ static int do_statmount(struct kstatmount *s, u64 mnt_id, u64 mnt_ns_id, s->mnt = mnt_file->f_path.mnt; ns =real_mount (s->mnt)->mnt_ns; +if (IS_ERR (ns)) +return PTR_ERR (ns);
nit: EINVAL is overused in the kernel. ENODEV seems like a better fit for this case.
Otherwise, the patch looks good to me:
Quoted 6 lines
fs/namespace.c +0
-1if (!ns)/* * We can't set mount point and mnt_ns_id since we don't have a -- 2.34.1