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>] [day] [month] [year] [list]
Message-Id: <20230120004034.145647-1-ebiggers@kernel.org>
Date:   Thu, 19 Jan 2023 16:40:34 -0800
From:   Eric Biggers <ebiggers@...nel.org>
To:     linux-ext4@...r.kernel.org
Subject: [e2fsprogs PATCH] e2fsck: use inline functions for kernel slab functions

From: Eric Biggers <ebiggers@...gle.com>

The macros that e2fsck uses to implement kmalloc et al. use only some of
their arguments, so unlike standard function calls, they can cause
compiler warnings like:

./../e2fsck/revoke.c:141:8: warning: variable 'gfp_mask' set but not used [-Wunused-but-set-variable]

Fix this by providing a proper definition for each function, making sure
to match the function prototypes used in the kernel.

Remove the kmem_cache_t typedef, as it doesn't exist in the kernel.

Signed-off-by: Eric Biggers <ebiggers@...gle.com>
---
 e2fsck/jfs_user.h | 53 ++++++++++++++++++++++++++++++++---------------
 1 file changed, 36 insertions(+), 17 deletions(-)

diff --git a/e2fsck/jfs_user.h b/e2fsck/jfs_user.h
index 969cd1b92..6f81d8cdc 100644
--- a/e2fsck/jfs_user.h
+++ b/e2fsck/jfs_user.h
@@ -82,16 +82,9 @@ struct kdev_s {
 #define buffer_req(bh) 1
 #define do_readahead(journal, start) do {} while (0)
 
-typedef struct kmem_cache {
-	int	object_length;
-} kmem_cache_t;
-
-#define kmem_cache_alloc(cache, flags) malloc((cache)->object_length)
-#define kmem_cache_free(cache, obj) free(obj)
-#define kmem_cache_create(name, len, a, b, c) do_cache_create(len)
-#define kmem_cache_destroy(cache) do_cache_destroy(cache)
-#define kmalloc(len, flags) malloc(len)
-#define kfree(p) free(p)
+struct kmem_cache {
+	unsigned int	object_size;
+};
 
 #define cond_resched()	do { } while (0)
 
@@ -107,8 +100,15 @@ typedef struct kmem_cache {
  * functions.
  */
 #ifdef NO_INLINE_FUNCS
-extern kmem_cache_t *do_cache_create(int len);
-extern void do_cache_destroy(kmem_cache_t *cache);
+extern struct kmem_cache *kmem_cache_create(const char *name,
+					    unsigned int size,
+					    unsigned int align,
+					    unsigned int flags,
+					    void (*ctor)(void *));
+extern void kmem_cache_destroy(struct kmem_cache *s);
+extern void *kmem_cache_alloc(struct kmem_cache *cachep, gfp_t flags);
+extern void kmem_cache_free(struct kmem_cache *s, void *objp);
+extern void kfree(const void *objp);
 extern size_t journal_tag_bytes(journal_t *journal);
 extern __u32 __hash_32(__u32 val);
 extern __u32 hash_32(__u32 val, unsigned int bits);
@@ -139,19 +139,38 @@ extern void jbd2_descriptor_block_csum_set(journal_t *j,
 #endif /* __STDC_VERSION__ >= 199901L */
 #endif /* E2FSCK_INCLUDE_INLINE_FUNCS */
 
-_INLINE_ kmem_cache_t *do_cache_create(int len)
+_INLINE_ struct kmem_cache *kmem_cache_create(const char *name,
+					      unsigned int size,
+					      unsigned int align,
+					      unsigned int flags,
+					      void (*ctor)(void *))
 {
-	kmem_cache_t *new_cache;
+	struct kmem_cache *new_cache;
 
 	new_cache = malloc(sizeof(*new_cache));
 	if (new_cache)
-		new_cache->object_length = len;
+		new_cache->object_size = size;
 	return new_cache;
 }
 
-_INLINE_ void do_cache_destroy(kmem_cache_t *cache)
+_INLINE_ void kmem_cache_destroy(struct kmem_cache *s)
+{
+	free(s);
+}
+
+_INLINE_ void *kmem_cache_alloc(struct kmem_cache *cachep, gfp_t flags)
+{
+	return malloc(cachep->object_size);
+}
+
+_INLINE_ void kmem_cache_free(struct kmem_cache *s, void *objp)
+{
+	free(objp);
+}
+
+_INLINE_ void kfree(const void *objp)
 {
-	free(cache);
+	free((void *)objp);
 }
 
 /* generic hashing taken from the Linux kernel */

base-commit: 6695555e50a374f897965300568253f242a0b13b
-- 
2.39.0

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ