[PATCH v3 03/57] locking: Introduce __cleanup() based infrastructure
Kees Cook
keescook at chromium.org
Tue Jun 13 19:46:29 UTC 2023
On Tue, Jun 13, 2023 at 12:55:22PM +0200, Peter Zijlstra wrote:
> On Mon, Jun 12, 2023 at 11:07:16AM +0200, Peter Zijlstra wrote:
>
> > --- /dev/null
> > +++ b/include/linux/cleanup.h
> > @@ -0,0 +1,167 @@
> > +/* SPDX-License-Identifier: GPL-2.0 */
> > +#ifndef __LINUX_GUARDS_H
> > +#define __LINUX_GUARDS_H
> > +
> > +#include <linux/compiler.h>
> > +
> > +/*
> > + * DEFINE_FREE(name, type, free):
> > + * simple helper macro that defines the required wrapper for a __free()
> > + * based cleanup function. @free is an expression using '_T' to access
> > + * the variable.
> > + *
> > + * __free(name):
> > + * variable attribute to add a scoped based cleanup to the variable.
> > + *
>
> no_free_ptr(var):
> like a non-atomic xchg(var, NULL), such that the cleanup
> function will be inhibited -- provided it sanely deals with a
> NULL value.
>
> > + * return_ptr(p):
> > + * returns p while inhibiting the __free().
> > + *
> > + * Ex.
> > + *
> > + * DEFINE_FREE(kfree, void *, if (_T) kfree(_T))
> > + *
> > + * struct obj *p = kmalloc(...);
>
> That should obviously have been:
>
> struct obj *p __free(kfree) = kmalloc(...);
Okay, good. I noticed that too. :)
I also didn't see any users of the kfree helpers (maybe I missed them?)
Maybe add at least one conversion just to have an example conversion for
it too?
-Kees
--
Kees Cook
More information about the Linux-security-module-archive
mailing list