lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAK7LNATwNj9zqH8csL0MCrHr+fqWMYMarn3T38H+yvGeJK3oKA@mail.gmail.com>
Date:   Fri, 23 Sep 2022 20:43:36 +0900
From:   Masahiro Yamada <masahiroy@...nel.org>
To:     Linux Kernel Mailing List <linux-kernel@...r.kernel.org>,
        Christoph Hellwig <hch@....de>,
        Marek Szyprowski <m.szyprowski@...sung.com>,
        Robin Murphy <robin.murphy@....com>, iommu@...ts.linux.dev
Cc:     Guenter Roeck <linux@...ck-us.net>,
        Linux Kbuild mailing list <linux-kbuild@...r.kernel.org>,
        "Martin K. Petersen" <martin.petersen@...cle.com>,
        Ming Lin <ming.l@....samsung.com>,
        Sagi Grimberg <sagi@...mberg.me>
Subject: Re: [PATCH] lib/sg_pool: change module_init(sg_pool_init) to subsys_initcall

On Fri, Sep 23, 2022 at 8:40 PM Masahiro Yamada <masahiroy@...nel.org> wrote:
>
> sg_alloc_table_chained() is called by several drivers, but if it is
> called before sg_pool_init(), it results in a NULL pointer dereference
> in sg_pool_alloc().
>
> Since commit 9b1d6c895002 ("lib: scatterlist: move SG pool code from
> SCSI driver to lib/sg_pool.c"), we rely on module_init(sg_pool_init)
> is invoked before other module_init calls but this assumption is
> fragile.
>
> I slightly changed the link order while Kbuild refactoring Kbuild,


A nit.

while Kbuild refactoring Kbuild -> while refactoring Kbuild




> then uncovered this issue. I should keep the current link order, but
> depending on a specific call order among module_init is so fragine.


fragine -> fragile.




> We usually define the init order by specifying *_initcall correctly,
> or delay the driver probing by returning -EPROBE_DEFER.
>
> Change module_initcall() to subsys_initcall(), and also delete the
> pointless module_exit() because lib/sg_pool.c is always compiled as
> built-in. (CONFIG_SG_POOL is bool)
>
> Link: https://lore.kernel.org/all/20220921043946.GA1355561@roeck-us.net/
> Link: https://lore.kernel.org/all/8e70837d-d859-dfb2-bf7f-83f8b31467bc@samsung.com/
> Fixes: 9b1d6c895002 ("lib: scatterlist: move SG pool code from SCSI driver to lib/sg_pool.c")
> Reported-by: Guenter Roeck <linux@...ck-us.net>
> Reported-by: Marek Szyprowski <m.szyprowski@...sung.com>
> Signed-off-by: Masahiro Yamada <masahiroy@...nel.org>
> ---
>
> I am sending this to DMA subsystem because I did not find
> a corresponding one for lib/sg_pool.c
>
>  lib/sg_pool.c | 16 ++--------------
>  1 file changed, 2 insertions(+), 14 deletions(-)
>
> diff --git a/lib/sg_pool.c b/lib/sg_pool.c
> index a0b1a52cd6f7..9bfe60ca3f37 100644
> --- a/lib/sg_pool.c
> +++ b/lib/sg_pool.c
> @@ -1,5 +1,5 @@
>  // SPDX-License-Identifier: GPL-2.0-only
> -#include <linux/module.h>
> +#include <linux/init.h>
>  #include <linux/scatterlist.h>
>  #include <linux/mempool.h>
>  #include <linux/slab.h>
> @@ -177,16 +177,4 @@ static __init int sg_pool_init(void)
>         return -ENOMEM;
>  }
>
> -static __exit void sg_pool_exit(void)
> -{
> -       int i;
> -
> -       for (i = 0; i < SG_MEMPOOL_NR; i++) {
> -               struct sg_pool *sgp = sg_pools + i;
> -               mempool_destroy(sgp->pool);
> -               kmem_cache_destroy(sgp->slab);
> -       }
> -}
> -
> -module_init(sg_pool_init);
> -module_exit(sg_pool_exit);
> +subsys_initcall(sg_pool_init);
> --
> 2.34.1
>


-- 
Best Regards
Masahiro Yamada

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ