fs: Fix uninitialized 'offp' in statmount_string()
Subsystems (2)
PATCH 1/1 fs: Fix uninitialized 'offp' in statmount_string()
In statmount_string(), most flags assign an output offset pointer (offp) which is later updated with the string offset. However, the STATMOUNT_MNT_UIDMAP and STATMOUNT_MNT_GIDMAP cases directly set the struct fields instead of using offp. This leaves offp uninitialized, leading to a possible uninitialized dereference when *offp is updated.
Fix it by assigning offp for UIDMAP and GIDMAP as well, keeping the code path consistent.
--- fs/namespace.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
fs/namespace.c +2 -2
@@ -5454,11 +5454,11 @@ static int statmount_string(struct kstatmount *s, u64 flag) ret =statmount_sb_source (s, seq);break ;case STATMOUNT_MNT_UIDMAP : - sm->mnt_uidmap = start; + offp = &sm->mnt_uidmap; ret =statmount_mnt_uidmap (s, seq);break ;case STATMOUNT_MNT_GIDMAP : - sm->mnt_gidmap = start; + offp = &sm->mnt_gidmap; ret =statmount_mnt_gidmap (s, seq);break ;default :
Signature · 1 line
2.20.1
Quoted 6 lines · Zhen Ni
In
statmount_string(), most flags assign an output offset pointer (offp) which is later updated with the string offset. However, theSTATMOUNT_MNT_UIDMAPandSTATMOUNT_MNT_GIDMAPcases directly set the struct fields instead of using offp. This leaves offp uninitialized, leading to a possible uninitialized dereference when *offp is updated.
Quoted 6 lines
Fix it by assigning offp for UIDMAP and GIDMAP as well, keeping the code path consistent.
Fixes 37c4a9590e1e ("statmount: allow to retrieve idmappings")Signed-off-by Zhen Ni <[email protected]>
The bug happened because of mismerge between commits 37c4a9590e1e and e52e97f09fb6 so I think we should also add:
Otherwise the patch looks good. Feel free to add:
Honza
Quoted 25 lines
--- fs/namespace.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)fs/namespace.c +2
-2@@ -5454,11 +5454,11 @@ static int statmount_string(struct kstatmount *s, u64 flag) ret =statmount_sb_source (s, seq);break ;case STATMOUNT_MNT_UIDMAP : - sm->mnt_uidmap = start; + offp = &sm->mnt_uidmap; ret =statmount_mnt_uidmap (s, seq);break ;case STATMOUNT_MNT_GIDMAP : - sm->mnt_gidmap = start; + offp = &sm->mnt_gidmap; ret =statmount_mnt_gidmap (s, seq);break ;default :Signature · 1 line
2.20.1
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
PATCH v2 1/1 fs: Fix uninitialized 'offp' in statmount_string()
In reply to Zhen NiIn statmount_string(), most flags assign an output offset pointer (offp) which is later updated with the string offset. However, the STATMOUNT_MNT_UIDMAP and STATMOUNT_MNT_GIDMAP cases directly set the struct fields instead of using offp. This leaves offp uninitialized, leading to a possible uninitialized dereference when *offp is updated.
Fix it by assigning offp for UIDMAP and GIDMAP as well, keeping the code path consistent.
---
Changes in v2:
- Add Fixes: e52e97f09fb6 ("statmount: let unset strings be empty")
--- fs/namespace.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
fs/namespace.c +2 -2
@@ -5454,11 +5454,11 @@ static int statmount_string(struct kstatmount *s, u64 flag) ret =statmount_sb_source (s, seq);break ;case STATMOUNT_MNT_UIDMAP : - sm->mnt_uidmap = start; + offp = &sm->mnt_uidmap; ret =statmount_mnt_uidmap (s, seq);break ;case STATMOUNT_MNT_GIDMAP : - sm->mnt_gidmap = start; + offp = &sm->mnt_gidmap; ret =statmount_mnt_gidmap (s, seq);break ;default :
Signature · 1 line
2.20.1
Quoted 10 lines · Zhen Ni
In
statmount_string(), most flags assign an output offset pointer (offp) which is later updated with the string offset. However, theSTATMOUNT_MNT_UIDMAPandSTATMOUNT_MNT_GIDMAPcases directly set the struct fields instead of using offp. This leaves offp uninitialized, leading to a possible uninitialized dereference when *offp is updated.Fix it by assigning offp for UIDMAP and GIDMAP as well, keeping the code path consistent.
[...]
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] fs: Fix uninitialized 'offp' in statmount_string()
https://git.kernel.org/vfs/vfs/c/0778ac7df513