lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <4f981027146713e6f31ef3c12375658c9e76c317.1425310176.git.tom.zanussi@linux.intel.com>
Date:	Mon,  2 Mar 2015 10:01:03 -0600
From:	Tom Zanussi <tom.zanussi@...ux.intel.com>
To:	rostedt@...dmis.org
Cc:	masami.hiramatsu.pt@...achi.com, namhyung@...nel.org,
	andi@...stfloor.org, ast@...mgrid.com,
	linux-kernel@...r.kernel.org,
	Tom Zanussi <tom.zanussi@...ux.intel.com>
Subject: [PATCH 10/15] bpf: Make tracing_map use kmalloc/kfree_notrace()

We need to prevent any kmallocs that could be invoked from within a
tracepoint handler from being traced, in order to prevent recursion.

For tracing maps, this means the allocation of the map elements (maps
themselves along with their associated buckets, etc, are never
allocated in the context of a tracepoint handler, so we don't need to
worry about them).

We also want the matching kfrees to remain untraced as well.

With this, we should be able to use maps when tracing kmalloc, which
otherwise would lock up the machine.

Signed-off-by: Tom Zanussi <tom.zanussi@...ux.intel.com>
---
 kernel/bpf/hashtab.c | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)

diff --git a/kernel/bpf/hashtab.c b/kernel/bpf/hashtab.c
index 6f349ad..308ef47 100644
--- a/kernel/bpf/hashtab.c
+++ b/kernel/bpf/hashtab.c
@@ -200,6 +200,15 @@ find_first_elem:
 	return -ENOENT;
 }
 
+/* Use this instead of kfree_rcu() for notrace-kfreeing
+ * kmalloc_notrace()'d elements, to avoid creating a
+ * kfree_rcu_notrace() */
+static void kfree_htab_elem(struct rcu_head *head)
+{
+	struct htab_elem *elem = container_of(head, struct htab_elem, rcu);
+	kfree_notrace(elem);
+}
+
 /* Called from syscall or from eBPF program */
 static int htab_map_update_elem(struct bpf_map *map, void *key, void *value,
 				u64 map_flags)
@@ -218,7 +227,7 @@ static int htab_map_update_elem(struct bpf_map *map, void *key, void *value,
 	WARN_ON_ONCE(!rcu_read_lock_held());
 
 	/* allocate new element outside of lock */
-	l_new = kmalloc(htab->elem_size, GFP_ATOMIC);
+	l_new = kmalloc_notrace(htab->elem_size, GFP_ATOMIC);
 	if (!l_new)
 		return -ENOMEM;
 
@@ -262,7 +271,7 @@ static int htab_map_update_elem(struct bpf_map *map, void *key, void *value,
 	hlist_add_head_rcu(&l_new->hash_node, head);
 	if (l_old) {
 		hlist_del_rcu(&l_old->hash_node);
-		kfree_rcu(l_old, rcu);
+		call_rcu(&l_old->rcu, kfree_htab_elem);
 	} else {
 		htab->count++;
 	}
@@ -271,7 +280,7 @@ static int htab_map_update_elem(struct bpf_map *map, void *key, void *value,
 	return 0;
 err:
 	spin_unlock_irqrestore(&htab->lock, flags);
-	kfree(l_new);
+	kfree_notrace(l_new);
 	return ret;
 }
 
@@ -311,7 +320,7 @@ static int htab_map_delete_elem(struct bpf_map *map, void *key)
 		free_client_elem(htab, l);
 		hlist_del_rcu(&l->hash_node);
 		htab->count--;
-		kfree_rcu(l, rcu);
+		call_rcu(&l->rcu, kfree_htab_elem);
 		ret = 0;
 	}
 
@@ -332,7 +341,7 @@ static void delete_all_elements(struct bpf_htab *htab)
 			free_client_elem(htab, l);
 			hlist_del_rcu(&l->hash_node);
 			htab->count--;
-			kfree(l);
+			kfree_notrace(l);
 		}
 	}
 }
-- 
1.9.3

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ