Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Wed, 20 Sep 2017 13:45:10 -0700
From: Kees Cook <>
Cc: Kees Cook <>,
	David Windsor <>,
	Alexander Viro <>,,,,
Subject: [PATCH v3 04/31] dcache: Define usercopy region in dentry_cache slab cache

From: David Windsor <>

When a dentry name is short enough, it can be stored directly in the
dentry itself (instead in a separate kmalloc allocation). These dentry
short names, stored in struct dentry.d_iname and therefore contained in
the dentry_cache slab cache, need to be coped to userspace.

cache object allocation:
            dentry = kmem_cache_alloc(dentry_cache, ...);
            dentry-> = dentry->d_iname;

example usage trace:

        (called via by dir_emit)
        filldir(..., const char *name, ...):
            copy_to_user(..., name, namlen)

            next = next_positive(dentry, p, 1)
            dir_emit(..., next->, ...)

In support of usercopy hardening, this patch defines a region in the
dentry_cache slab cache in which userspace copy operations are allowed.

This region is known as the slab cache's usercopy region. Slab caches can
now check that each copy operation involving cache-managed memory falls
entirely within the slab's usercopy region.

This patch is modified from Brad Spengler/PaX Team's PAX_USERCOPY
whitelisting code in the last public patch of grsecurity/PaX based on my
understanding of the code. Changes or omissions from the original code are
mine and don't reflect the original grsecurity/PaX code.

Signed-off-by: David Windsor <>
[kees: adjust hunks for kmalloc-specific things moved later]
[kees: adjust commit log, provide usage trace]
Cc: Alexander Viro <>
Signed-off-by: Kees Cook <>
 fs/dcache.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/fs/dcache.c b/fs/dcache.c
index f90141387f01..5f5e7c1fcf4b 100644
--- a/fs/dcache.c
+++ b/fs/dcache.c
@@ -3603,8 +3603,9 @@ static void __init dcache_init(void)
 	 * but it is probably not worth it because of the cache nature
 	 * of the dcache.
-	dentry_cache = KMEM_CACHE(dentry,
+	dentry_cache = KMEM_CACHE_USERCOPY(dentry,
+		d_iname);
 	/* Hash may have been set up in dcache_init_early */
 	if (!hashdist)

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.