From 4ceb343966960c79b6b6ed29208df7e8b38cf28d Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Sat, 3 Nov 2018 17:06:01 +0000 Subject: [PATCH] scst, scst_user: Add support for usercopy hardening Avoid that with CONFIG_HARDENED_USERCOPY enabled warnings appear about kernel memory exposure attempts when using scst_user. git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@7601 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scst/src/dev_handlers/scst_user.c | 4 ++-- scst/src/scst_main.c | 9 ++++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/scst/src/dev_handlers/scst_user.c b/scst/src/dev_handlers/scst_user.c index d213c691a..911796c3a 100644 --- a/scst/src/dev_handlers/scst_user.c +++ b/scst/src/dev_handlers/scst_user.c @@ -4212,8 +4212,8 @@ static int __init init_scst_user(void) goto out; } - user_cmd_cachep = KMEM_CACHE(scst_user_cmd, - SCST_SLAB_FLAGS|SLAB_HWCACHE_ALIGN); + user_cmd_cachep = KMEM_CACHE_USERCOPY(scst_user_cmd, + SCST_SLAB_FLAGS | SLAB_HWCACHE_ALIGN, user_cmd); if (user_cmd_cachep == NULL) { res = -ENOMEM; goto out_dev_cache; diff --git a/scst/src/scst_main.c b/scst/src/scst_main.c index 8d3183a65..7660e288a 100644 --- a/scst/src/scst_main.c +++ b/scst/src/scst_main.c @@ -2586,6 +2586,13 @@ static int __init init_scst(void) sizeof(struct s)); \ (p); \ }) +#define INIT_CACHEP_ALIGN_USERCOPY(p, s, f) ({ \ + (p) = KMEM_CACHE_USERCOPY(s, SCST_SLAB_FLAGS | \ + SLAB_HWCACHE_ALIGN, f); \ + TRACE_MEM("Slab create: %s at %p size %zd", #s, (p), \ + sizeof(struct s)); \ + (p); \ + }) res = -ENOMEM; if (!INIT_CACHEP(scst_mgmt_cachep, scst_mgmt_cmd)) @@ -2601,7 +2608,7 @@ static int __init init_scst(void) } if (!INIT_CACHEP(scst_aen_cachep, scst_aen)) /* read-mostly */ goto out_destroy_sense_cache; - if (!INIT_CACHEP_ALIGN(scst_cmd_cachep, scst_cmd)) + if (!INIT_CACHEP_ALIGN_USERCOPY(scst_cmd_cachep, scst_cmd, cdb)) goto out_destroy_aen_cache; /* Big enough with read-mostly head and tail */ if (!INIT_CACHEP(scst_sess_cachep, scst_session))