[lkml]   [2017]   [Sep]   [20]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
Patch in this message
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)
 \ /
  Last update: 2017-09-21 19:24    [W:0.135 / U:6.124 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site