From: Pavel Emelyanov <xemul@parallels.com>
To: Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Cc: Cyrill Gorcunov <gorcunov@openvz.org>,
Glauber Costa <glommer@parallels.com>,
Andi Kleen <andi@firstfloor.org>, Tejun Heo <tj@kernel.org>,
Andrew Morton <akpm@linux-foundation.org>,
Matt Helsley <matthltc@us.ibm.com>
Subject: [PATCH 1/4] Routine for generating an safe ID for kernel pointer
Date: Tue, 15 Nov 2011 15:36:33 +0400 [thread overview]
Message-ID: <4EC24EC1.7060203@parallels.com> (raw)
In-Reply-To: <4EC24E9E.8040502@parallels.com>
The routine XORs the given pointer with a random value thus producing
an ID (32 or 64 bit, depending on the arch) which can be shown even to
unprivileged user space processes without risking of leaking kernel
information.
It implies that it gets called when the random pool is ready for providing
a random long value.
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
---
include/linux/gen_object_ids.h | 12 ++++++++++++
mm/Kconfig | 7 +++++++
mm/Makefile | 1 +
mm/gen_object_ids.c | 21 +++++++++++++++++++++
4 files changed, 41 insertions(+), 0 deletions(-)
create mode 100644 include/linux/gen_object_ids.h
create mode 100644 mm/gen_object_ids.c
diff --git a/include/linux/gen_object_ids.h b/include/linux/gen_object_ids.h
new file mode 100644
index 0000000..17981ae
--- /dev/null
+++ b/include/linux/gen_object_ids.h
@@ -0,0 +1,12 @@
+#ifndef __GEN_OBJECT_IDS_H__
+#define __GEN_OBJECT_IDS_H__
+
+#ifdef CONFIG_GENERIC_OBJECT_IDS
+unsigned long gen_object_id(void *ptr);
+#else
+static inline unsigned long gen_object_id(void *ptr)
+{
+ return 0;
+}
+#endif
+#endif
diff --git a/mm/Kconfig b/mm/Kconfig
index f2f1ca1..1480cbf 100644
--- a/mm/Kconfig
+++ b/mm/Kconfig
@@ -370,3 +370,10 @@ config CLEANCACHE
in a negligible performance hit.
If unsure, say Y to enable cleancache
+
+config GENERIC_OBJECT_IDS
+ bool "Enable generic object ids infrastructure"
+ default n
+ help
+ Turn on the (quite simple) funtionality that can generate IDs for
+ kernel objects which is safe to export to the userspace.
diff --git a/mm/Makefile b/mm/Makefile
index 836e416..155797a 100644
--- a/mm/Makefile
+++ b/mm/Makefile
@@ -50,3 +50,4 @@ obj-$(CONFIG_HWPOISON_INJECT) += hwpoison-inject.o
obj-$(CONFIG_DEBUG_KMEMLEAK) += kmemleak.o
obj-$(CONFIG_DEBUG_KMEMLEAK_TEST) += kmemleak-test.o
obj-$(CONFIG_CLEANCACHE) += cleancache.o
+obj-$(CONFIG_GENERIC_OBJECT_IDS) += gen_object_ids.o
diff --git a/mm/gen_object_ids.c b/mm/gen_object_ids.c
new file mode 100644
index 0000000..a75119b
--- /dev/null
+++ b/mm/gen_object_ids.c
@@ -0,0 +1,21 @@
+#include <linux/gen_object_ids.h>
+#include <linux/spinlock.h>
+#include <linux/random.h>
+
+static unsigned long ptr_poison __read_mostly;
+static DEFINE_SPINLOCK(ptr_poison_lock);
+
+unsigned long gen_object_id(void *ptr)
+{
+ if (!ptr)
+ return 0;
+
+ if (unlikely(!ptr_poison)) {
+ spin_lock(&ptr_poison_lock);
+ if (!ptr_poison)
+ get_random_bytes(&ptr_poison, sizeof(ptr_poison));
+ spin_unlock(&ptr_poison_lock);
+ }
+
+ return ((unsigned long)ptr) ^ ptr_poison;
+}
--
1.5.5.6
next prev parent reply other threads:[~2011-11-15 11:36 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-11-15 11:35 [PATCH 0/4] Checkpoint/Restore: Show in proc IDs of objects that can be shared between tasks Pavel Emelyanov
2011-11-15 11:36 ` Pavel Emelyanov [this message]
2011-11-15 11:38 ` [PATCH 1/4] Routine for generating an safe ID for kernel pointer Pekka Enberg
2011-11-15 11:44 ` Pavel Emelyanov
2011-11-15 11:51 ` Pekka Enberg
2011-11-15 15:13 ` Eric Dumazet
2011-11-15 15:20 ` Tejun Heo
2011-11-15 11:36 ` [PATCH 2/4] proc: Show namespaces IDs in /proc/pid/ns/* files Pavel Emelyanov
2011-11-15 11:37 ` [PATCH 3/4] proc: Show open file ID in /proc/pid/fdinfo/* Pavel Emelyanov
2011-11-16 5:44 ` [PATCH 0/4] Checkpoint/Restore: Show in proc IDs of objects that can be shared between tasks Matt Helsley
2011-11-16 6:19 ` Cyrill Gorcunov
2011-11-16 8:25 ` Pavel Emelyanov
2011-11-18 23:25 ` Matt Helsley
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=4EC24EC1.7060203@parallels.com \
--to=xemul@parallels.com \
--cc=akpm@linux-foundation.org \
--cc=andi@firstfloor.org \
--cc=glommer@parallels.com \
--cc=gorcunov@openvz.org \
--cc=linux-kernel@vger.kernel.org \
--cc=matthltc@us.ibm.com \
--cc=tj@kernel.org \
/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;
as well as URLs for NNTP newsgroup(s).