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] [day] [month] [year] [list]
Date:   Fri, 4 Mar 2022 01:22:58 +0200
From:   Andy Shevchenko <andy.shevchenko@...il.com>
To:     Sakari Ailus <sakari.ailus@...ux.intel.com>
Cc:     Andy Shevchenko <andriy.shevchenko@...ux.intel.com>,
        ACPI Devel Maling List <linux-acpi@...r.kernel.org>,
        Linux Kernel Mailing List <linux-kernel@...r.kernel.org>,
        Daniel Scally <djrscally@...il.com>,
        Heikki Krogerus <heikki.krogerus@...ux.intel.com>,
        Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
        "Rafael J. Wysocki" <rafael@...nel.org>,
        Nuno Sá <nuno.sa@...log.com>
Subject: Re: [PATCH v1 1/1] device property: Allow error pointer for fwnode_handle_{get,put}()

On Thu, Mar 3, 2022 at 11:34 PM Sakari Ailus
<sakari.ailus@...ux.intel.com> wrote:
> On Thu, Mar 03, 2022 at 05:06:10PM +0200, Andy Shevchenko wrote:
> > Some of the fwnode APIs might return an error pointer instead of NULL
> > or valid fwnode handle. The result of such API call may be considered
> > optional and hence the test for it is usually done in a form of
> >
> >       fwnode = fwnode_find_reference(...);
> >       if (IS_ERR_OR_NULL(fwnode))
> >               ...error handling...
> >
> > Nevertheless the resulting fwnode may have bumped reference count and
> > hence caller of the above API is obliged to call fwnode_handle_put().
> > Since fwnode may be not valid either as NULL or error pointer the check
> > has to be performed there. This approach uglifies the code and adds
> > a point of making a mistake, i.e. forgetting about error point case.
> >
> > To prevent this allow error pointer for fwnode_handle_get() and
> > fwnode_handle_put().

Thanks for the review, my comments below.

...

> I guess fwnode_find_reference() is the only fwnode API function returning
> errors as pointers? If you changed it returning NULL on error, you'd lose
> the error codes.
>
> But I think this is a problem beyond fwnode_handle_{get,put}: fwnode
> obtained this way could be passed to any fwnode function and they should
> just work correctly with that.
>
> How about moving the check to fwnode_has_op()? That function is responsible
> for checking the fwnode is valid and has the op in question.

Yes, I was thinking about it (and I even have a local followup), so
this version of the fix is (semi-)RFC. Moreover, we (wrongly!) do
check in many already, but only _after_ trying to dereference error
pointers.

Letme prepare v2 tomorrow.

> It also seems the explicit fwnode_has_op() call is redundant in
> fwnode_handle_put() as fwnode_call_void_op() already calls fwnode_has_op().

Then call_ptr_op should have the same check as well.

-- 
With Best Regards,
Andy Shevchenko

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ