From: Cyrill Gorcunov <gorcunov@openvz.org>
To: linux-kernel@vger.kernel.org
Cc: Pavel Emelyanov <xemul@parallels.com>,
Glauber Costa <glommer@parallels.com>,
Andi Kleen <andi@firstfloor.org>, Tejun Heo <tj@kernel.org>,
Matt Helsley <matthltc@us.ibm.com>,
Pekka Enberg <penberg@kernel.org>,
Eric Dumazet <eric.dumazet@gmail.com>,
Vasiliy Kulikov <segoon@openwall.com>,
Andrew Morton <akpm@linux-foundation.org>,
Cyrill Gorcunov <gorcunov@openvz.org>
Subject: [patch 1/4] Add routine for generating an ID for kernel pointer
Date: Thu, 22 Dec 2011 16:56:40 +0400 [thread overview]
Message-ID: <20111222131139.457264003@openvz.org> (raw)
In-Reply-To: <20111222125639.360640574@openvz.org>
[-- Attachment #1: 1-introduce-gen_obj_id --]
[-- Type: text/plain, Size: 4078 bytes --]
The routine XORs the given pointer with a random value
producing an ID (32 or 64 bit, depending on the arch).
Since it's a valuable information -- only CAP_SYS_ADMIN
is allowed to obtain it.
Based-on-patch-from: Pavel Emelyanov <xemul@parallels.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
CC: Glauber Costa <glommer@parallels.com>
CC: Andi Kleen <andi@firstfloor.org>
CC: Tejun Heo <tj@kernel.org>
CC: Matt Helsley <matthltc@us.ibm.com>
CC: Pekka Enberg <penberg@kernel.org>
CC: Eric Dumazet <eric.dumazet@gmail.com>
CC: Vasiliy Kulikov <segoon@openwall.com>
CC: Andrew Morton <akpm@linux-foundation.org>
---
include/linux/mm.h | 10 ++++++++++
mm/Kconfig | 16 ++++++++++++++++
mm/util.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 75 insertions(+)
Index: linux-2.6.git/include/linux/mm.h
===================================================================
--- linux-2.6.git.orig/include/linux/mm.h
+++ linux-2.6.git/include/linux/mm.h
@@ -1640,5 +1640,15 @@ extern void copy_user_huge_page(struct p
unsigned int pages_per_huge_page);
#endif /* CONFIG_TRANSPARENT_HUGEPAGE || CONFIG_HUGETLBFS */
+enum {
+ GEN_OBJ_ID_TYPES,
+};
+
+#ifdef CONFIG_GENERIC_OBJECT_IDS
+unsigned long gen_obj_id(void *ptr, int type);
+#else
+static inline unsigned long gen_obj_id(void *ptr, int type) { return 0; }
+#endif
+
#endif /* __KERNEL__ */
#endif /* _LINUX_MM_H */
Index: linux-2.6.git/mm/Kconfig
===================================================================
--- linux-2.6.git.orig/mm/Kconfig
+++ linux-2.6.git/mm/Kconfig
@@ -373,3 +373,19 @@ config CLEANCACHE
in a negligible performance hit.
If unsure, say Y to enable cleancache
+
+config GENERIC_OBJECT_IDS
+ bool "Enable generic object ids infrastructure"
+ depends on CHECKPOINT_RESTORE
+ default n
+ help
+ Turn on the functionality that can generate IDs for kernel
+ objects, which are exported to userspace via /proc filesystem.
+
+ It is useful if you need to examinate kernel objects and test
+ if they are shared between several tasks. These IDs should never
+ be used for anything but the "sameness" test. Besides, the IDs are
+ dynamic and valid only while object is alive, once it get freed or
+ kernel is rebooted -- the IDs will be changed.
+
+ If unsure, say N here.
Index: linux-2.6.git/mm/util.c
===================================================================
--- linux-2.6.git.orig/mm/util.c
+++ linux-2.6.git/mm/util.c
@@ -4,6 +4,8 @@
#include <linux/export.h>
#include <linux/err.h>
#include <linux/sched.h>
+#include <linux/random.h>
+#include <linux/capability.h>
#include <asm/uaccess.h>
#include "internal.h"
@@ -307,3 +309,50 @@ EXPORT_TRACEPOINT_SYMBOL(kmalloc_node);
EXPORT_TRACEPOINT_SYMBOL(kmem_cache_alloc_node);
EXPORT_TRACEPOINT_SYMBOL(kfree);
EXPORT_TRACEPOINT_SYMBOL(kmem_cache_free);
+
+#ifdef CONFIG_GENERIC_OBJECT_IDS
+static unsigned long gen_obj_cookie[GEN_OBJ_ID_TYPES] __read_mostly;
+
+unsigned long gen_obj_id(void *ptr, int type)
+{
+ if (!capable(CAP_SYS_ADMIN) || !ptr)
+ return 0;
+
+ BUG_ON(type >= GEN_OBJ_ID_TYPES);
+
+ /*
+ * Note the simple XOR is used here not in a sake
+ * of security by any means, but rather to break
+ * an "impression" that such IDs means something
+ * other than a number which can be used for comparison
+ * with another number generated by this helper only.
+ */
+ return ((unsigned long)ptr) ^ gen_obj_cookie[type];
+}
+
+static __init int gen_obj_cookie_init(void)
+{
+#if BITS_PER_LONG == 64
+ const unsigned long emergency_cookie = 0xefcdab8967452301;
+#else
+ const unsigned long emergency_cookie = 0x98badcf9;
+#endif
+ int i;
+
+ for (i = 0; i < GEN_OBJ_ID_TYPES; i++) {
+ get_random_bytes(&gen_obj_cookie[i],
+ sizeof(unsigned long));
+ /*
+ * In 'impossible' case of random-bytes = 0
+ * we still would have non-zero value.
+ */
+ gen_obj_cookie[i] =
+ (gen_obj_cookie[i] & __PAGE_OFFSET) +
+ (emergency_cookie & ~__PAGE_OFFSET);
+ }
+
+ return 0;
+}
+
+late_initcall(gen_obj_cookie_init);
+#endif
next prev parent reply other threads:[~2011-12-22 13:12 UTC|newest]
Thread overview: 45+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-12-22 12:56 [patch 0/4] kernel generic object IDs series Cyrill Gorcunov
2011-12-22 12:56 ` Cyrill Gorcunov [this message]
2011-12-28 16:51 ` [patch 1/4] Add routine for generating an ID for kernel pointer Alan Cox
2011-12-28 17:05 ` Cyrill Gorcunov
2011-12-28 17:21 ` Alan Cox
2011-12-28 17:35 ` Cyrill Gorcunov
2011-12-28 19:48 ` Cyrill Gorcunov
2011-12-22 12:56 ` [patch 2/4] proc: Show namespaces IDs in /proc/pid/ns/* files Cyrill Gorcunov
2011-12-22 12:56 ` [patch 3/4] proc: Show open file ID in /proc/pid/fdinfo/* Cyrill Gorcunov
2011-12-22 13:24 ` [patch 0/4] kernel generic object IDs series Cyrill Gorcunov
2011-12-27 11:15 ` Cyrill Gorcunov
2011-12-23 12:47 [patch 0/4] generic object ids, v2 Cyrill Gorcunov
2011-12-23 12:47 ` [patch 1/4] Add routine for generating an ID for kernel pointer Cyrill Gorcunov
2011-12-27 23:23 ` Andrew Morton
2011-12-28 7:42 ` Cyrill Gorcunov
2011-12-28 9:42 ` Andrew Morton
2011-12-28 9:43 ` Cyrill Gorcunov
2011-12-28 9:47 ` Pavel Emelyanov
2011-12-28 10:41 ` Cyrill Gorcunov
2011-12-27 23:33 ` Andrew Morton
2011-12-28 0:48 ` Randy Dunlap
2011-12-28 7:24 ` Cyrill Gorcunov
2011-12-27 23:54 ` Valdis.Kletnieks
2011-12-28 0:02 ` Andrew Morton
2011-12-28 7:22 ` Cyrill Gorcunov
2011-12-28 16:06 ` Tejun Heo
2011-12-28 16:18 ` Cyrill Gorcunov
2011-12-28 16:26 ` Tejun Heo
2011-12-28 16:40 ` Cyrill Gorcunov
2011-12-28 16:45 ` Tejun Heo
2011-12-28 16:53 ` Cyrill Gorcunov
2011-12-28 17:01 ` Tejun Heo
2011-12-28 17:14 ` Cyrill Gorcunov
2011-12-29 14:24 ` Cyrill Gorcunov
2011-12-29 16:14 ` Tejun Heo
2011-12-29 16:24 ` Cyrill Gorcunov
2011-12-30 0:23 ` Herbert Xu
2011-12-30 7:36 ` Cyrill Gorcunov
2011-12-30 20:31 ` KOSAKI Motohiro
2011-12-30 20:48 ` Cyrill Gorcunov
2011-12-30 23:51 ` KOSAKI Motohiro
2011-12-31 7:51 ` Cyrill Gorcunov
2012-01-02 12:18 ` bastien ROUCARIES
2012-01-02 21:14 ` Cyrill Gorcunov
2011-12-31 4:55 ` Kyle Moffett
2011-12-31 7:57 ` Cyrill Gorcunov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20111222131139.457264003@openvz.org \
--to=gorcunov@openvz.org \
--cc=akpm@linux-foundation.org \
--cc=andi@firstfloor.org \
--cc=eric.dumazet@gmail.com \
--cc=glommer@parallels.com \
--cc=linux-kernel@vger.kernel.org \
--cc=matthltc@us.ibm.com \
--cc=penberg@kernel.org \
--cc=segoon@openwall.com \
--cc=tj@kernel.org \
--cc=xemul@parallels.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®