Skip to contentSkip to conversation

statmount: Fix the null-ptr-deref in do_statmount()

PATCH Applied Qing Wang 4 participants 4 messages Feb 13 – Feb 16 VFS

lore
Share & tools
lore

Qing Wang

author
#0 lore raw

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.

Fixes 0e5032237ee5 ("statmount: accept fd as a parameter")
Reported-by [email protected]
---
 fs/namespace.c | 2 ++
 1 file changed, 2 insertions(+)
fs/namespace.c +2 -0
index a67cbe42746d..90700df65f0d 100644
@@ -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
Reviewed-by on v3 1/1
#1 lore raw
Quoted 17 lines · Qing Wang

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.

Fixes 0e5032237ee5 ("statmount: accept fd as a parameter")
Reported-by [email protected]
---
 fs/namespace.c | 2 ++
 1 file changed, 2 insertions(+)
fs/namespace.c +0 -0
index a67cbe42746d..90700df65f0d 100644

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.

maintainer Applied
#2 lore raw
In reply to Qing Wang
Quoted 5 lines · Qing Wang

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.

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
Reviewed-by on v3 1/1
#3 lore raw
In reply to Qing Wang
Quoted 18 lines · Qing Wang

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.

Fixes 0e5032237ee5 ("statmount: accept fd as a parameter")
Reported-by [email protected]
---
 fs/namespace.c | 2 ++
 1 file changed, 2 insertions(+)
fs/namespace.c +0 -0
index a67cbe42746d..90700df65f0d 100644

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 -1
                if (!ns)
                        /*
                         * We can't set mount point and mnt_ns_id since we don't have a
--

2.34.1