lkml.org 
[lkml]   [2022]   [Jun]   [6]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH v3 1/3] mm/shmem: check return value of shmem_init_inodecache
On Mon, Jun 06, 2022 at 11:45:28AM +0800, Chen Wandun wrote:
> It will result in null pointer access if shmem_init_inodecache fail,
> so check return value of shmem_init_inodecache
>
> Signed-off-by: Chen Wandun <chenwandun@huawei.com>
> ---
> mm/shmem.c | 11 +++++++++--
> 1 file changed, 9 insertions(+), 2 deletions(-)
>
> diff --git a/mm/shmem.c b/mm/shmem.c
> index 12d45a03f7fc..7419ab219b97 100644
> --- a/mm/shmem.c
> +++ b/mm/shmem.c
> @@ -3775,11 +3775,16 @@ static void shmem_init_inode(void *foo)
> inode_init_once(&info->vfs_inode);
> }
>
> -static void shmem_init_inodecache(void)
> +static int shmem_init_inodecache(void)
> {
> shmem_inode_cachep = kmem_cache_create("shmem_inode_cache",
> sizeof(struct shmem_inode_info),
> 0, SLAB_PANIC|SLAB_ACCOUNT, shmem_init_inode);

NACK, we cannot dereference a NULL pointer since SLAB_PANIC is passed
to kmem_cache_create().

> +
> + if (!shmem_inode_cachep)
> + return -ENOMEM;
> +
> + return 0;
> }
>
> static void shmem_destroy_inodecache(void)
> @@ -3923,7 +3928,9 @@ void __init shmem_init(void)
> {
> int error;
>
> - shmem_init_inodecache();
> + error = shmem_init_inodecache();
> + if (error)
> + goto out2;
>
> error = register_filesystem(&shmem_fs_type);
> if (error) {
> --
> 2.25.1
>
>

\
 
 \ /
  Last update: 2022-06-06 11:43    [W:0.191 / U:0.300 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site