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: <YsQluCvLLRXSo3Oc@kroah.com>
Date:   Tue, 5 Jul 2022 13:51:20 +0200
From:   Greg Kroah-Hartman <gregkh@...uxfoundation.org>
To:     Hsin-Yi Wang <hsinyi@...omium.org>
Cc:     "Rafael J . Wysocki" <rafael@...nel.org>,
        Kevin Hilman <khilman@...nel.org>,
        Ulf Hansson <ulf.hansson@...aro.org>,
        Len Brown <len.brown@...el.com>, Pavel Machek <pavel@....cz>,
        Thierry Strudel <tstrudel@...gle.com>,
        linux-pm@...r.kernel.org, linux-kernel@...r.kernel.org,
        AngeloGioacchino Del Regno 
        <angelogioacchino.delregno@...labora.com>,
        Pin-yen Lin <treapking@...omium.org>
Subject: Re: [PATCH] PM: domains: Ensure genpd_debugfs_dir exists before
 remove

On Tue, Jul 05, 2022 at 07:06:41PM +0800, Hsin-Yi Wang wrote:
> On Tue, Jul 5, 2022 at 6:38 PM Greg Kroah-Hartman
> <gregkh@...uxfoundation.org> wrote:
> >
> > On Tue, Jul 05, 2022 at 05:49:47PM +0800, Hsin-Yi Wang wrote:
> > > genpd_debug_remove() may be indirectly called from others while
> > > genpd_debugfs_dir is not yet set. Make sure genpd_debugfs_dir exists
> > > before remove the sub components, otherwise components under
> > > /sys/kernel/debug may be accidentally removed.
> > >
> > > Fixes: 718072ceb211 ("PM: domains: create debugfs nodes when adding power domains")
> > > Signed-off-by: Hsin-Yi Wang <hsinyi@...omium.org>
> > > ---
> > > An example:
> > > scpsys_probe() in drivers/soc/mediatek/mtk-pm-domains.c indirectly calls
> > > genpd_debug_remove() on probe fail, causing /sys/kernel/debug/usb to be
> > > removed.
> > > ---
> > >  drivers/base/power/domain.c | 3 +++
> > >  1 file changed, 3 insertions(+)
> > >
> > > diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
> > > index 3e86772d5fac5..5a2e0232862e0 100644
> > > --- a/drivers/base/power/domain.c
> > > +++ b/drivers/base/power/domain.c
> > > @@ -222,6 +222,9 @@ static void genpd_debug_remove(struct generic_pm_domain *genpd)
> > >  {
> > >       struct dentry *d;
> > >
> > > +     if (!genpd_debugfs_dir)
> > > +             return;
> > > +
> > >       d = debugfs_lookup(genpd->name, genpd_debugfs_dir);
> > >       debugfs_remove(d);
> >
> > Why not just change this to be:
> >         debugfs_remove(debugfs_lookup(genpd->name, debugfs_lookup("pm_genpd", NULL)));
> If pm_genpd hasn't been created yet,  debugfs_lookup("pm_genpd", NULL)
> will return null.

And how is this codepath being called if pm_genpd is not created yet?
Surely you are not relying on the presence of a debugfs file to
determine that?

> If genpd->name also exists under root debugfs, it will still be
> deleted unintentionally, since NULL represents root debugfs.
> Eg. one of the genpd->name is "usb", which is supposed to be added as
> /sys/kernel/debug/pm_genpd/usb later. But pm_genpd is not yet created,
> /sys/kernel/debug/usb will be removed.

Ah, that's a bad name to pick :)

But still, don't paper over this problem, please solve the root issue of
never relying on the creation of a debugfs file to determine functional
logic.

thanks,

greg k-h

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ