Blame SOURCES/0001-Fix-for-kmem-s-S-option-on-Linux-5.7-and-later-kerne.patch

f27a4c
From 647a5c33e1c94054d7b63168cd6c12901591cb77 Mon Sep 17 00:00:00 2001
f27a4c
From: Lianbo Jiang <lijiang@redhat.com>
f27a4c
Date: Thu, 27 May 2021 18:02:11 +0800
f27a4c
Subject: [PATCH] Fix for "kmem -s|-S" option on Linux 5.7 and later kernels
f27a4c
f27a4c
Linux 5.7 and later kernels that contain kernel commit 1ad53d9fa3f6
f27a4c
("slub: improve bit diffusion for freelist ptr obfuscation") changed
f27a4c
the calculation formula in the freelist_ptr(), which added a swab()
f27a4c
call to mix bits a little more.  When kernel is configured with the
f27a4c
"CONFIG_SLAB_FREELIST_HARDENED=y", without the patch, the "kmem -s|-S"
f27a4c
options display wrong statistics and state whether slab objects are
f27a4c
in use or free and can print the following errors:
f27a4c
f27a4c
  crash> kmem -s
f27a4c
  CACHE             OBJSIZE  ALLOCATED     TOTAL  SLABS  SSIZE  NAME
f27a4c
  87201e00              528          0         0      0     8k  xfs_dqtrx
f27a4c
  87201f00              496          0         0      0     8k  xfs_dquot
f27a4c
  kmem: xfs_buf: slab: 37202e6e900 invalid freepointer: b844bab900001d70
f27a4c
  kmem: xfs_buf: slab: 3720250fd80 invalid freepointer: b8603f9400001370
f27a4c
  ...
f27a4c
f27a4c
Signed-off-by: Lianbo Jiang <lijiang@redhat.com>
f27a4c
---
f27a4c
 memory.c | 9 +++++++--
f27a4c
 1 file changed, 7 insertions(+), 2 deletions(-)
f27a4c
f27a4c
diff --git a/memory.c b/memory.c
f27a4c
index 8c6bbe409922..a3cf8a86728d 100644
f27a4c
--- a/memory.c
f27a4c
+++ b/memory.c
f27a4c
@@ -20,6 +20,7 @@
f27a4c
 #include <sys/mman.h>
f27a4c
 #include <ctype.h>
f27a4c
 #include <netinet/in.h>
f27a4c
+#include <byteswap.h>
f27a4c
 
f27a4c
 struct meminfo {           /* general purpose memory information structure */
f27a4c
         ulong cache;       /* used by the various memory searching/dumping */
f27a4c
@@ -19336,10 +19337,14 @@ count_free_objects(struct meminfo *si, ulong freelist)
f27a4c
 static ulong
f27a4c
 freelist_ptr(struct meminfo *si, ulong ptr, ulong ptr_addr)
f27a4c
 {
f27a4c
-	if (VALID_MEMBER(kmem_cache_random))
f27a4c
+	if (VALID_MEMBER(kmem_cache_random)) {
f27a4c
 		/* CONFIG_SLAB_FREELIST_HARDENED */
f27a4c
+
f27a4c
+		if (THIS_KERNEL_VERSION >= LINUX(5,7,0))
f27a4c
+			ptr_addr = (sizeof(long) == 8) ? bswap_64(ptr_addr)
f27a4c
+						       : bswap_32(ptr_addr);
f27a4c
 		return (ptr ^ si->random ^ ptr_addr);
f27a4c
-	else
f27a4c
+	} else
f27a4c
 		return ptr;
f27a4c
 }
f27a4c
 
f27a4c
-- 
f27a4c
2.30.2
f27a4c