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 11:14:08 -0800
From:   Drew Fustini <drew@...gleboard.org>
To:     Dan Carpenter <dan.carpenter@...cle.com>
Cc:     Geert Uytterhoeven <geert@...ux-m68k.org>, kbuild@...ts.01.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

On Wed, Feb 10, 2021 at 10:05:29PM +0300, Dan Carpenter wrote:
> On Wed, Feb 10, 2021 at 07:39:16PM +0100, Geert Uytterhoeven wrote:
> > 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.
> > 
> 
> Then why not use vanilla kmalloc()?

Yes, I believe that is the correct approach.  The problem was due to my
misunderstanding of when devm_*() was appropriate.  In this case, I
should have been using the vanilla allocation as the buffers used in
this debugfs write operation are not tied to the lifetime of the pin
controller device.  The are just allocated for internal use inside the
write function.

thanks,
drew

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ