mirror of
				https://github.com/torvalds/linux.git
				synced 2025-11-04 10:40:15 +02:00 
			
		
		
		
	mm/hugetlbfs: fix error handling when setting up mounts
It is assumed that the hugetlbfs_vfsmount[] array will contain either a
valid vfsmount pointer or NULL for each hstate after initialization.
Changes made while converting to use fs_context broke this assumption.
While fixing the hugetlbfs_vfsmount issue, it was discovered that
init_hugetlbfs_fs never did correctly clean up when encountering a vfs
mount error.
It was found during code inspection.  A small memory allocation failure
would be the most likely cause of taking a error path with the bug.
This is unlikely to happen as this is early init code.
Link: http://lkml.kernel.org/r/94b6244d-2c24-e269-b12c-e3ba694b242d@oracle.com
Reported-by: Chengguang Xu <cgxu519@mykernel.net>
Fixes: 32021982a3 ("hugetlbfs: Convert to fs_context")
Signed-off-by: Mike Kravetz <mike.kravetz@oracle.com>
Cc: David Howells <dhowells@redhat.com>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
			
			
This commit is contained in:
		
							parent
							
								
									552546366a
								
							
						
					
					
						commit
						8fc312b32b
					
				
					 1 changed files with 22 additions and 9 deletions
				
			
		| 
						 | 
					@ -1461,28 +1461,41 @@ static int __init init_hugetlbfs_fs(void)
 | 
				
			||||||
					sizeof(struct hugetlbfs_inode_info),
 | 
										sizeof(struct hugetlbfs_inode_info),
 | 
				
			||||||
					0, SLAB_ACCOUNT, init_once);
 | 
										0, SLAB_ACCOUNT, init_once);
 | 
				
			||||||
	if (hugetlbfs_inode_cachep == NULL)
 | 
						if (hugetlbfs_inode_cachep == NULL)
 | 
				
			||||||
		goto out2;
 | 
							goto out;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	error = register_filesystem(&hugetlbfs_fs_type);
 | 
						error = register_filesystem(&hugetlbfs_fs_type);
 | 
				
			||||||
	if (error)
 | 
						if (error)
 | 
				
			||||||
		goto out;
 | 
							goto out_free;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* default hstate mount is required */
 | 
				
			||||||
 | 
						mnt = mount_one_hugetlbfs(&hstates[default_hstate_idx]);
 | 
				
			||||||
 | 
						if (IS_ERR(mnt)) {
 | 
				
			||||||
 | 
							error = PTR_ERR(mnt);
 | 
				
			||||||
 | 
							goto out_unreg;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						hugetlbfs_vfsmount[default_hstate_idx] = mnt;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* other hstates are optional */
 | 
				
			||||||
	i = 0;
 | 
						i = 0;
 | 
				
			||||||
	for_each_hstate(h) {
 | 
						for_each_hstate(h) {
 | 
				
			||||||
 | 
							if (i == default_hstate_idx)
 | 
				
			||||||
 | 
								continue;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		mnt = mount_one_hugetlbfs(h);
 | 
							mnt = mount_one_hugetlbfs(h);
 | 
				
			||||||
		if (IS_ERR(mnt) && i == 0) {
 | 
							if (IS_ERR(mnt))
 | 
				
			||||||
			error = PTR_ERR(mnt);
 | 
								hugetlbfs_vfsmount[i] = NULL;
 | 
				
			||||||
			goto out;
 | 
							else
 | 
				
			||||||
		}
 | 
								hugetlbfs_vfsmount[i] = mnt;
 | 
				
			||||||
		hugetlbfs_vfsmount[i] = mnt;
 | 
					 | 
				
			||||||
		i++;
 | 
							i++;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return 0;
 | 
						return 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 out:
 | 
					 out_unreg:
 | 
				
			||||||
 | 
						(void)unregister_filesystem(&hugetlbfs_fs_type);
 | 
				
			||||||
 | 
					 out_free:
 | 
				
			||||||
	kmem_cache_destroy(hugetlbfs_inode_cachep);
 | 
						kmem_cache_destroy(hugetlbfs_inode_cachep);
 | 
				
			||||||
 out2:
 | 
					 out:
 | 
				
			||||||
	return error;
 | 
						return error;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
fs_initcall(init_hugetlbfs_fs)
 | 
					fs_initcall(init_hugetlbfs_fs)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue