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]
Date:   Wed, 10 Feb 2021 19:39:16 +0100
From:   Geert Uytterhoeven <geert@...ux-m68k.org>
To:     Dan Carpenter <dan.carpenter@...cle.com>
Cc:     kbuild@...ts.01.org, Drew Fustini <drew@...gleboard.org>,
        Linus Walleij <linus.walleij@...aro.org>,
        "open list:GPIO SUBSYSTEM" <linux-gpio@...r.kernel.org>,
        Linux Kernel Mailing List <linux-kernel@...r.kernel.org>,
        Tony Lindgren <tony@...mide.com>,
        Andy Shevchenko <andy.shevchenko@...il.com>,
        Alexandre Belloni <alexandre.belloni@...tlin.com>,
        Pantelis Antoniou <pantelis.antoniou@...sulko.com>,
        Jason Kridner <jkridner@...gleboard.org>,
        Robert Nelson <robertcnelson@...gleboard.org>,
        kbuild test robot <lkp@...el.com>, kbuild-all@...ts.01.org
Subject: Re: [PATCH v2 2/2] pinctrl: pinmux: Add pinmux-select debugfs file

Hi Dan,

On Wed, Feb 10, 2021 at 7:21 PM Dan Carpenter <dan.carpenter@...cle.com> wrote:
> 99b2f99aa41aa7 Drew Fustini  2021-02-09  694    buf = devm_kzalloc(pctldev->dev, PINMUX_MAX_NAME * 2, GFP_KERNEL);
> 99b2f99aa41aa7 Drew Fustini  2021-02-09  695    if (!buf)
> 99b2f99aa41aa7 Drew Fustini  2021-02-09  696            return -ENOMEM;
> 99b2f99aa41aa7 Drew Fustini  2021-02-09  697
> 99b2f99aa41aa7 Drew Fustini  2021-02-09  698    fname = devm_kzalloc(pctldev->dev, PINMUX_MAX_NAME, GFP_KERNEL);
> 99b2f99aa41aa7 Drew Fustini  2021-02-09  699    if (!fname) {
> 99b2f99aa41aa7 Drew Fustini  2021-02-09  700            ret = -ENOMEM;
> 99b2f99aa41aa7 Drew Fustini  2021-02-09  701            goto free_buf;
>
> The gotos are out of order.  They should be in mirror/reverse order of
> the allocations:
>
> free_gmane:
>         devm_kfree(pctldev->dev, gname);
> free_fname:
>         devm_kfree(pctldev->dev, fname);
> free_buf:
>         devm_kfree(pctldev->dev, buf);
>
> But also why do we need to use devm_kfree() at all?  I thought the whole
> point of devm_ functions was that they are garbage collected
> automatically for you.  Can we not just delete all error handling and
> return -ENOMEM here?

No, because the lifetime of the objects allocated here does not match the
lifetime of dev.  If they're not freed here, they will only be freed when the
device is unbound.  As the user can access the sysfs files at will, he can
OOM the system.

Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@...ux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ