This has served its purpose and is no longer used. All usercopy violations appear to have been handled by now, any remaining instances (or new bugs) will cause copies to be rejected. This isn't a direct revert of commit 2d891fbc3bb6 ("usercopy: Allow strict enforcement of whitelists"); since usercopy_fallback is effectively 0, the fallback handling is removed too. This also removes the usercopy_fallback module parameter on slab_common.
Unified · Split
| @@ -275,7 +275,6 @@ CONFIG_NLS_UTF8=y · 274 unmodified lines | ||
| 275 | 275 | CONFIG_ENCRYPTED_KEYS=y |
| 276 | 276 | CONFIG_SECURITY=y |
| 277 | 277 | CONFIG_HARDENED_USERCOPY=y |
| 278 | −# CONFIG_HARDENED_USERCOPY_FALLBACK is not set | |
| 279 | 278 | CONFIG_HARDENED_USERCOPY_PAGESPAN=y |
| 280 | 279 | CONFIG_FORTIFY_SOURCE=y |
| 281 | 280 | CONFIG_SECURITY_LOCKDOWN_LSM=y |
| @@ -142,8 +142,6 @@ struct mem_cgroup; · 141 unmodified lines | ||
| 142 | 142 | void __init kmem_cache_init(void); |
| 143 | 143 | bool slab_is_available(void); |
| 144 | 144 | |
| 145 | −extern bool usercopy_fallback; | |
| 146 | − | |
| 147 | 145 | struct kmem_cache *kmem_cache_create(const char *name, unsigned int size, |
| 148 | 146 | unsigned int align, slab_flags_t flags, |
| 149 | 147 | void (*ctor)(void *)); |
| @@ -4204,19 +4204,6 @@ void __check_heap_object(const void *ptr, unsigned long n, struct page *page, · 4203 unmodified lines | ||
| 4204 | 4204 | n <= cachep->useroffset - offset + cachep->usersize) |
| 4205 | 4205 | return; |
| 4206 | 4206 | |
| 4207 | − /* | |
| 4208 | − * If the copy is still within the allocated object, produce | |
| 4209 | − * a warning instead of rejecting the copy. This is intended | |
| 4210 | − * to be a temporary method to find any missing usercopy | |
| 4211 | − * whitelists. | |
| 4212 | − */ | |
| 4213 | − if (usercopy_fallback && | |
| 4214 | − offset <= cachep->object_size && | |
| 4215 | − n <= cachep->object_size - offset) { | |
| 4216 | − usercopy_warn("SLAB object", cachep->name, to_user, offset, n); | |
| 4217 | − return; | |
| 4218 | − } | |
| 4219 | − | |
| 4220 | 4207 | usercopy_abort("SLAB object", cachep->name, to_user, offset, n); |
| 4221 | 4208 | } |
| 4222 | 4209 | #endif /* CONFIG_HARDENED_USERCOPY */ |
| @@ -37,14 +37,6 @@ LIST_HEAD(slab_caches); · 36 unmodified lines | ||
| 37 | 37 | DEFINE_MUTEX(slab_mutex); |
| 38 | 38 | struct kmem_cache *kmem_cache; |
| 39 | 39 | |
| 40 | −#ifdef CONFIG_HARDENED_USERCOPY | |
| 41 | −bool usercopy_fallback __ro_after_init = | |
| 42 | − IS_ENABLED(CONFIG_HARDENED_USERCOPY_FALLBACK); | |
| 43 | −module_param(usercopy_fallback, bool, 0400); | |
| 44 | −MODULE_PARM_DESC(usercopy_fallback, | |
| 45 | − "WARN instead of reject usercopy whitelist violations"); | |
| 46 | −#endif | |
| 47 | − | |
| 48 | 40 | static LIST_HEAD(slab_caches_to_rcu_destroy); |
| 49 | 41 | static void slab_caches_to_rcu_destroy_workfn(struct work_struct *work); |
| 50 | 42 | static DECLARE_WORK(slab_caches_to_rcu_destroy_work, |
| @@ -4489,7 +4489,6 @@ void __check_heap_object(const void *ptr, unsigned long n, struct page *page, · 4488 unmodified lines | ||
| 4489 | 4489 | { |
| 4490 | 4490 | struct kmem_cache *s; |
| 4491 | 4491 | unsigned int offset; |
| 4492 | − size_t object_size; | |
| 4493 | 4492 | bool is_kfence = is_kfence_address(ptr); |
| 4494 | 4493 | |
| 4495 | 4494 | ptr = kasan_reset_tag(ptr); |
| @@ -4522,19 +4521,6 @@ void __check_heap_object(const void *ptr, unsigned long n, struct page *page, · 26 unmodified lines | ||
| 4522 | 4521 | n <= s->useroffset - offset + s->usersize) |
| 4523 | 4522 | return; |
| 4524 | 4523 | |
| 4525 | − /* | |
| 4526 | − * If the copy is still within the allocated object, produce | |
| 4527 | − * a warning instead of rejecting the copy. This is intended | |
| 4528 | − * to be a temporary method to find any missing usercopy | |
| 4529 | − * whitelists. | |
| 4530 | − */ | |
| 4531 | − object_size = slab_ksize(s); | |
| 4532 | − if (usercopy_fallback && | |
| 4533 | − offset <= object_size && n <= object_size - offset) { | |
| 4534 | − usercopy_warn("SLUB object", s->name, to_user, offset, n); | |
| 4535 | − return; | |
| 4536 | − } | |
| 4537 | − | |
| 4538 | 4524 | usercopy_abort("SLUB object", s->name, to_user, offset, n); |
| 4539 | 4525 | } |
| 4540 | 4526 | #endif /* CONFIG_HARDENED_USERCOPY */ |
| @@ -163,20 +163,6 @@ config HARDENED_USERCOPY · 162 unmodified lines | ||
| 163 | 163 | or are part of the kernel text. This kills entire classes |
| 164 | 164 | of heap overflow exploits and similar kernel memory exposures. |
| 165 | 165 | |
| 166 | −config HARDENED_USERCOPY_FALLBACK | |
| 167 | − bool "Allow usercopy whitelist violations to fallback to object size" | |
| 168 | − depends on HARDENED_USERCOPY | |
| 169 | − default y | |
| 170 | − help | |
| 171 | − This is a temporary option that allows missing usercopy whitelists | |
| 172 | − to be discovered via a WARN() to the kernel log, instead of | |
| 173 | − rejecting the copy, falling back to non-whitelisted hardened | |
| 174 | − usercopy that checks the slab allocation size instead of the | |
| 175 | − whitelist size. This option will be removed once it seems like | |
| 176 | − all missing usercopy whitelists have been identified and fixed. | |
| 177 | − Booting with "slab_common.usercopy_fallback=Y/N" can change | |
| 178 | − this setting. | |
| 179 | − | |
| 180 | 166 | config HARDENED_USERCOPY_PAGESPAN |
| 181 | 167 | bool "Refuse to copy allocations that span multiple pages" |
| 182 | 168 | depends on HARDENED_USERCOPY |