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
This commit is contained in:
Bart Van Assche
2018-11-03 17:06:01 +00:00
parent 133b012f82
commit 4ceb343966
2 changed files with 10 additions and 3 deletions

View File

@@ -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;

View File

@@ -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))