mm: kasan: initial memory quarantine implementation
[cascardo/linux.git] / mm / kasan / kasan.h
index 30a2f0b..7f7ac51 100644 (file)
@@ -62,6 +62,7 @@ struct kasan_global {
 enum kasan_state {
        KASAN_STATE_INIT,
        KASAN_STATE_ALLOC,
+       KASAN_STATE_QUARANTINE,
        KASAN_STATE_FREE
 };
 
@@ -79,9 +80,14 @@ struct kasan_alloc_meta {
        u32 reserved;
 };
 
+struct qlist_node {
+       struct qlist_node *next;
+};
 struct kasan_free_meta {
-       /* Allocator freelist pointer, unused by KASAN. */
-       void **freelist;
+       /* This field is used while the object is in the quarantine.
+        * Otherwise it might be used for the allocator freelist.
+        */
+       struct qlist_node quarantine_link;
        struct kasan_track track;
 };
 
@@ -105,4 +111,15 @@ static inline bool kasan_report_enabled(void)
 void kasan_report(unsigned long addr, size_t size,
                bool is_write, unsigned long ip);
 
+#ifdef CONFIG_SLAB
+void quarantine_put(struct kasan_free_meta *info, struct kmem_cache *cache);
+void quarantine_reduce(void);
+void quarantine_remove_cache(struct kmem_cache *cache);
+#else
+static inline void quarantine_put(struct kasan_free_meta *info,
+                               struct kmem_cache *cache) { }
+static inline void quarantine_reduce(void) { }
+static inline void quarantine_remove_cache(struct kmem_cache *cache) { }
+#endif
+
 #endif