statmount: Fix the null-ptr-deref in do_statmount()
PATCH 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_OR_NULL().
--- fs/namespace.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
fs/namespace.c +4 -2
@@ -5678,13 +5678,15 @@ 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 (!ns) +if (IS_ERR_OR_NULL (ns)) {/* * We can't set mount point and mnt_ns_id since we don't have a * ns for the mount. This can happen if the mount is unmounted -* with MNT_DETACH. +* with MNT_DETACH or if it's an internal mount. */ s->mask &= ~(STATMOUNT_MNT_POINT |STATMOUNT_MNT_NS_ID ); + ns =NULL ; + } }else {/* Has the namespace already been emptied? */ if (mnt_ns_id &&mnt_ns_empty (ns))
Signature · 1 line
2.34.1
Quoted 25 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_OR_NULL().Fixes 0e5032237ee5 ("statmount: accept fd as a parameter")Reported-by [email protected]Tested-by [email protected]Signed-off-by Qing Wang <[email protected]>--- fs/namespace.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)fs/namespace.c +1
-1@@ -5678,13 +5678,15 @@ 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 (!ns) +if (IS_ERR_OR_NULL (ns)) {/* * We can't set mount point and mnt_ns_id since we don't have a
fs/namespace.c static int do_statmount(struct kstatmount *s, u64 mnt_id, u64 mnt_ns_id, · line 5692
Quoted 10 lines
fs/namespace.c +3
-1* ns for the mount. This can happen if the mount is unmounted -* with MNT_DETACH. +* with MNT_DETACH or if it's an internal mount. */ s->mask &= ~(STATMOUNT_MNT_POINT |STATMOUNT_MNT_NS_ID ); + ns =NULL ; + } }else {/* Has the namespace already been emptied? */ if (mnt_ns_id &&mnt_ns_empty (ns))
Hey!
I think the fix should be the following instead, AFAIU we don't want a call to an internal mount to succeed.
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 -EINVAL ;if (!ns)/* * We can't set mount point and mnt_ns_id since we don't have a
Thanks,
Bhavik
Quoted 20 lines · Bhavik Sachdev
Hey!
I think the fix should be the following instead, AFAIU we don't want a call to an internal mount to succeed.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 =3D mnt_file->f_path.mnt; ns =3D real_mount(s->mnt)->mnt_ns; +if (IS_ERR (ns)) +return -EINVAL ;if (!ns)/* * We can't set mount point and
mnt_ns_idsince we =
don't have a
Quoted 2 lines
Thanks,
Bhavik
I had considered returning an error code before but finally decided to not. Thank you for your suggestion, I agree with it and resend the patch v3 [0].
[0] https://lore.kernel.org/all/[email protected]/T/
Look forward to your review.
---
Thanks,
Qing