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: Sat, 30 Mar 2024 17:12:18 +0100
From: Greg KH <gregkh@...uxfoundation.org>
To: Ayush Tiwari <ayushtiw0110@...il.com>
Cc: alison.schofield@...el.com, paul@...l-moore.com, mic@...ikod.net,
	fabio.maria.de.francesco@...ux.intel.com,
	linux-kernel@...r.kernel.org, outreachy@...ts.linux.dev,
	linux-security-module@...r.kernel.org
Subject: Re: [PATCH v2] landlock: Use kmem for landlock_object

On Sat, Mar 30, 2024 at 07:24:19PM +0530, Ayush Tiwari wrote:
> Use kmem_cache replace kzalloc() calls with kmem_cache_zalloc() for
> struct landlock_object and update the related dependencies to improve
> memory allocation and deallocation performance.

So it's faster?  Great, what are the measurements?

> This patch does not
> change kfree() and kfree_rcu() calls because according to kernel commit
> ae65a5211d90("mm/slab: document kfree() as allowed for
> kmem_cache_alloc() objects"), starting from kernel 6.4 with
> CONFIG_SLOB, kfree() is safe to use for such objects.

There is no CONFIG_SLOB anymore so why mention it?




> 
> Signed-off-by: Ayush Tiwari <ayushtiw0110@...il.com>
> ---
> 
> Changes in v2: Used clang-format and corrected the removal of kfree_rcu.
> Tried to use KMEM macro but due to lack of cache pointer in that macro,
> had to explicitly define landlock_object_cache, as done in security.c.
> 
>  security/landlock/object.c | 12 +++++++++++-
>  security/landlock/object.h |  2 ++
>  security/landlock/setup.c  |  1 +
>  3 files changed, 14 insertions(+), 1 deletion(-)
> 
> diff --git a/security/landlock/object.c b/security/landlock/object.c
> index 1f50612f0185..cfc367725624 100644
> --- a/security/landlock/object.c
> +++ b/security/landlock/object.c
> @@ -17,6 +17,15 @@
>  
>  #include "object.h"
>  
> +static struct kmem_cache *landlock_object_cache;
> +
> +void __init landlock_object_cache_init(void)
> +{
> +	landlock_object_cache = kmem_cache_create(
> +		"landlock_object_cache", sizeof(struct landlock_object), 0,
> +		SLAB_PANIC, NULL);

You really want SLAB_PANIC?  Why?

> +}
> +
>  struct landlock_object *
>  landlock_create_object(const struct landlock_object_underops *const underops,
>  		       void *const underobj)
> @@ -25,7 +34,8 @@ landlock_create_object(const struct landlock_object_underops *const underops,
>  
>  	if (WARN_ON_ONCE(!underops || !underobj))
>  		return ERR_PTR(-ENOENT);
> -	new_object = kzalloc(sizeof(*new_object), GFP_KERNEL_ACCOUNT);
> +	new_object =
> +		kmem_cache_zalloc(landlock_object_cache, GFP_KERNEL_ACCOUNT);

Odd indentation, why?

thanks,

greg k-h

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ