From: Christopher Lameter <cl@linux.com>
To: Kees Cook <keescook@chromium.org>
Cc: Andrew Morton <akpm@linux-foundation.org>,
Pekka Enberg <penberg@kernel.org>,
David Rientjes <rientjes@google.com>,
Joonsoo Kim <iamjoonsoo.kim@lge.com>,
"Paul E. McKenney" <paulmck@linux.vnet.ibm.com>,
Ingo Molnar <mingo@kernel.org>, Tejun Heo <tj@kernel.org>,
Andy Lutomirski <luto@kernel.org>,
Nicolas Pitre <nicolas.pitre@linaro.org>,
linux-mm@kvack.org, Rik van Riel <riel@redhat.com>,
Tycho Andersen <tycho@docker.com>,
Alexander Popov <alex.popov@linux.com>,
linux-kernel@vger.kernel.org,
kernel-hardening@lists.openwall.com
Subject: Re: [PATCH v4] mm: Add SLUB free list pointer obfuscation
Date: Thu, 27 Jul 2017 10:14:18 -0500 (CDT) [thread overview]
Message-ID: <alpine.DEB.2.20.1707271003370.15126@nuc-kabylake> (raw)
In-Reply-To: <20170726041250.GA76741@beast>
On Tue, 25 Jul 2017, Kees Cook wrote:
> +/*
> + * Returns freelist pointer (ptr). With hardening, this is obfuscated
> + * with an XOR of the address where the pointer is held and a per-cache
> + * random number.
> + */
> +static inline void *freelist_ptr(const struct kmem_cache *s, void *ptr,
> + unsigned long ptr_addr)
> +{
> +#ifdef CONFIG_SLAB_FREELIST_HARDENED
> + return (void *)((unsigned long)ptr ^ s->random ^ ptr_addr);
> +#else
> + return ptr;
> +#endif
> +}
Weird function. Why pass both the pointer as well as the address of the
pointer? The address of the pointer would be sufficient I think. Compiler
can optimize the refs on its own. OK ptr_addr is really the obfuscation
value. Maybe a bit confusing to call this ptr_addr and also pass this as
a long. xor_value? If it is a pointer address the it should be void ** or
so.
> static inline void *get_freepointer_safe(struct kmem_cache *s, void *object)
> {
> + unsigned long freepointer_addr;
> void *p;
>
> if (!debug_pagealloc_enabled())
> return get_freepointer(s, object);
>
> - probe_kernel_read(&p, (void **)(object + s->offset), sizeof(p));
> - return p;
> + freepointer_addr = (unsigned long)object + s->offset;
converts the void ** to unsigned long.... which requires another cast in
the following line.
> + probe_kernel_read(&p, (void **)freepointer_addr, sizeof(p));
> + return freelist_ptr(s, p, freepointer_addr);
> }
>
> static inline void set_freepointer(struct kmem_cache *s, void *object, void *fp)
> {
> - *(void **)(object + s->offset) = fp;
> + unsigned long freeptr_addr = (unsigned long)object + s->offset;
> +
> + *(void **)freeptr_addr = freelist_ptr(s, fp, freeptr_addr);
> }
>
> /* Loop over all objects in a slab */
> @@ -3563,6 +3592,9 @@ static int kmem_cache_open(struct kmem_cache *s, unsigned long flags)
> {
> s->flags = kmem_cache_flags(s->size, flags, s->name, s->ctor);
> s->reserved = 0;
> +#ifdef CONFIG_SLAB_FREELIST_HARDENED
> + s->random = get_random_long();
> +#endif
>
> if (need_reserve_slab_rcu && (s->flags & SLAB_TYPESAFE_BY_RCU))
> s->reserved = sizeof(struct rcu_head);
>
prev parent reply other threads:[~2017-07-27 15:14 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-07-26 4:12 [PATCH v4] mm: Add SLUB free list pointer obfuscation Kees Cook
2017-07-27 15:14 ` Christopher Lameter [this message]
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=alpine.DEB.2.20.1707271003370.15126@nuc-kabylake \
--to=cl@linux.com \
--cc=akpm@linux-foundation.org \
--cc=alex.popov@linux.com \
--cc=iamjoonsoo.kim@lge.com \
--cc=keescook@chromium.org \
--cc=kernel-hardening@lists.openwall.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=luto@kernel.org \
--cc=mingo@kernel.org \
--cc=nicolas.pitre@linaro.org \
--cc=paulmck@linux.vnet.ibm.com \
--cc=penberg@kernel.org \
--cc=riel@redhat.com \
--cc=rientjes@google.com \
--cc=tj@kernel.org \
--cc=tycho@docker.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;
as well as URLs for NNTP newsgroup(s).