+ kasan-preassign-tags-to-objects-with-ctors-or-slab_typesafe_by_rcu.patch added to -mm tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The patch titled
     Subject: kasan: preassign tags to objects with ctors or SLAB_TYPESAFE_BY_RCU
has been added to the -mm tree.  Its filename is
     kasan-preassign-tags-to-objects-with-ctors-or-slab_typesafe_by_rcu.patch

This patch should soon appear at
    http://ozlabs.org/~akpm/mmots/broken-out/kasan-preassign-tags-to-objects-with-ctors-or-slab_typesafe_by_rcu.patch
and later at
    http://ozlabs.org/~akpm/mmotm/broken-out/kasan-preassign-tags-to-objects-with-ctors-or-slab_typesafe_by_rcu.patch

Before you just go and hit "reply", please:
   a) Consider who else should be cc'ed
   b) Prefer to cc a suitable mailing list as well
   c) Ideally: find the original patch on the mailing list and do a
      reply-to-all to that, adding suitable additional cc's

*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***

The -mm tree is included into linux-next and is updated
there every 3-4 working days

------------------------------------------------------
From: Andrey Konovalov <andreyknvl@xxxxxxxxxx>
Subject: kasan: preassign tags to objects with ctors or SLAB_TYPESAFE_BY_RCU

An object constructor can initialize pointers within this objects based on
the address of the object. Since the object address might be tagged, we
need to assign a tag before calling constructor.

The implemented approach is to assign tags to objects with constructors
when a slab is allocated and call constructors once as usual. The
downside is that such object would always have the same tag when it is
reallocated, so we won't catch use-after-frees on it.

Also pressign tags for objects from SLAB_TYPESAFE_BY_RCU caches, since
they can be validy accessed after having been freed.

Link: http://lkml.kernel.org/r/b2c17b6674f1737f981ffa6dca7fdfc059a88435.1543337629.git.andreyknvl@xxxxxxxxxx
Signed-off-by: Andrey Konovalov <andreyknvl@xxxxxxxxxx>
Reviewed-by: Andrey Ryabinin <aryabinin@xxxxxxxxxxxxx>
Reviewed-by: Dmitry Vyukov <dvyukov@xxxxxxxxxx>
Cc: Mark Rutland <mark.rutland@xxxxxxx>
Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
---


--- a/mm/slab.c~kasan-preassign-tags-to-objects-with-ctors-or-slab_typesafe_by_rcu
+++ a/mm/slab.c
@@ -2574,7 +2574,7 @@ static void cache_init_objs(struct kmem_
 
 	for (i = 0; i < cachep->num; i++) {
 		objp = index_to_obj(cachep, page, i);
-		kasan_init_slab_obj(cachep, objp);
+		objp = kasan_init_slab_obj(cachep, objp);
 
 		/* constructor could break poison info */
 		if (DEBUG == 0 && cachep->ctor) {
--- a/mm/slub.c~kasan-preassign-tags-to-objects-with-ctors-or-slab_typesafe_by_rcu
+++ a/mm/slub.c
@@ -1451,16 +1451,17 @@ static inline bool slab_free_freelist_ho
 #endif
 }
 
-static void setup_object(struct kmem_cache *s, struct page *page,
+static void *setup_object(struct kmem_cache *s, struct page *page,
 				void *object)
 {
 	setup_object_debug(s, page, object);
-	kasan_init_slab_obj(s, object);
+	object = kasan_init_slab_obj(s, object);
 	if (unlikely(s->ctor)) {
 		kasan_unpoison_object_data(s, object);
 		s->ctor(object);
 		kasan_poison_object_data(s, object);
 	}
+	return object;
 }
 
 /*
@@ -1568,16 +1569,16 @@ static bool shuffle_freelist(struct kmem
 	/* First entry is used as the base of the freelist */
 	cur = next_freelist_entry(s, page, &pos, start, page_limit,
 				freelist_count);
+	cur = setup_object(s, page, cur);
 	page->freelist = cur;
 
 	for (idx = 1; idx < page->objects; idx++) {
-		setup_object(s, page, cur);
 		next = next_freelist_entry(s, page, &pos, start, page_limit,
 			freelist_count);
+		next = setup_object(s, page, next);
 		set_freepointer(s, cur, next);
 		cur = next;
 	}
-	setup_object(s, page, cur);
 	set_freepointer(s, cur, NULL);
 
 	return true;
@@ -1599,7 +1600,7 @@ static struct page *allocate_slab(struct
 	struct page *page;
 	struct kmem_cache_order_objects oo = s->oo;
 	gfp_t alloc_gfp;
-	void *start, *p;
+	void *start, *p, *next;
 	int idx, order;
 	bool shuffle;
 
@@ -1651,13 +1652,16 @@ static struct page *allocate_slab(struct
 
 	if (!shuffle) {
 		for_each_object_idx(p, idx, s, start, page->objects) {
-			setup_object(s, page, p);
-			if (likely(idx < page->objects))
-				set_freepointer(s, p, p + s->size);
-			else
+			if (likely(idx < page->objects)) {
+				next = p + s->size;
+				next = setup_object(s, page, next);
+				set_freepointer(s, p, next);
+			} else
 				set_freepointer(s, p, NULL);
 		}
-		page->freelist = fixup_red_left(s, start);
+		start = fixup_red_left(s, start);
+		start = setup_object(s, page, start);
+		page->freelist = start;
 	}
 
 	page->inuse = page->objects;
_

Patches currently in -mm which might be from andreyknvl@xxxxxxxxxx are

kasan-mm-change-hooks-signatures.patch
kasan-slub-handle-pointer-tags-in-early_kmem_cache_node_alloc.patch
kasan-move-common-generic-and-tag-based-code-to-commonc.patch
kasan-rename-source-files-to-reflect-the-new-naming-scheme.patch
kasan-add-config_kasan_generic-and-config_kasan_sw_tags.patch
kasan-arm64-adjust-shadow-size-for-tag-based-mode.patch
kasan-rename-kasan_zero_page-to-kasan_early_shadow_page.patch
kasan-initialize-shadow-to-0xff-for-tag-based-mode.patch
arm64-move-untagged_addr-macro-from-uaccessh-to-memoryh.patch
kasan-add-tag-related-helper-functions.patch
kasan-arm64-untag-address-in-_virt_addr_is_linear.patch
kasan-preassign-tags-to-objects-with-ctors-or-slab_typesafe_by_rcu.patch
kasan-arm64-fix-up-fault-handling-logic.patch
kasan-arm64-enable-top-byte-ignore-for-the-kernel.patch
kasan-mm-perform-untagged-pointers-comparison-in-krealloc.patch
kasan-split-out-generic_reportc-from-reportc.patch
kasan-add-bug-reporting-routines-for-tag-based-mode.patch
mm-move-obj_to_index-to-include-linux-slab_defh.patch
kasan-add-hooks-implementation-for-tag-based-mode.patch
kasan-arm64-add-brk-handler-for-inline-instrumentation.patch
kasan-mm-arm64-tag-non-slab-memory-allocated-via-pagealloc.patch
kasan-add-__must_check-annotations-to-kasan-hooks.patch
kasan-arm64-select-have_arch_kasan_sw_tags.patch
kasan-update-documentation.patch
kasan-add-spdx-license-identifier-mark-to-source-files.patch




[Index of Archives]     [Kernel Archive]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]

  Powered by Linux