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]
Date:	Sun, 17 May 2015 10:56:39 +0000
From:	Wang Nan <wangnan0@...wei.com>
To:	<paulus@...ba.org>, <a.p.zijlstra@...llo.nl>, <mingo@...hat.com>,
	<acme@...nel.org>, <namhyung@...nel.org>, <jolsa@...nel.org>,
	<dsahern@...il.com>, <ast@...mgrid.com>, <daniel@...earbox.net>,
	<brendan.d.gregg@...il.com>, <masami.hiramatsu.pt@...achi.com>
CC:	<lizefan@...wei.com>, <linux-kernel@...r.kernel.org>,
	<pi3orama@....com>
Subject: [RFC PATCH v3 14/37] bpf tools: Collect config string from 'config' section

A 'config' section is allowed to enable eBPF object file to pass
something to user. libbpf doesn't use config string.

To make further processing easiler, this patch converts '\0' in the
whole config strings into '\n'

Signed-off-by: Wang Nan <wangnan0@...wei.com>
---
 tools/lib/bpf/libbpf.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 48 insertions(+)

diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index 6ee5f3c..43b22a5 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -84,6 +84,7 @@ struct bpf_object {
 	u32 kern_version;
 	void *maps_buf;
 	size_t maps_buf_sz;
+	char *config_str;
 
 	/*
 	 * Information when doing elf related work. Only valid if fd
@@ -267,6 +268,48 @@ static int bpf_obj_maps_init(struct bpf_object *obj, void *data,
 	return 0;
 }
 
+static int bpf_obj_config_init(struct bpf_object *obj, void *data,
+			       size_t size)
+{
+	char *config_str;
+	char *p, *pend;
+
+	if (size == 0) {
+		pr_debug("bpf: config section in %s empty\n",
+			 obj->path);
+		return 0;
+	}
+	if (obj->config_str) {
+		pr_warning("bpf: multiple config section in %s\n",
+			   obj->path);
+		return -EEXIST;
+	}
+
+	config_str = malloc(size + 1);
+	if (!config_str) {
+		pr_warning("bpf: malloc config string failed\n");
+		return -ENOMEM;
+	}
+
+	memcpy(config_str, data, size);
+
+	/*
+	 * It is possible that config section contains multiple
+	 * Make it a big string by converting all '\0' to '\n' and
+	 * append final '\0'.
+	 */
+	pend = config_str + size;
+	for (p = config_str; p < pend; p++)
+		*p == '\0' ? *p = '\n' : 0 ;
+	*pend = '\0';
+
+	obj->config_str = config_str;
+	pr_debug("--- CONFIG STRING IN %s: ---\n%s\n",
+		 obj->path, config_str);
+	pr_debug("----------------------------\n");
+	return 0;
+}
+
 static int bpf_obj_elf_collect(struct bpf_object *obj)
 {
 	Elf *elf = obj->elf.elf;
@@ -324,6 +367,9 @@ static int bpf_obj_elf_collect(struct bpf_object *obj)
 		else if (strcmp(name, "maps") == 0)
 			err = bpf_obj_maps_init(obj, data->d_buf,
 						data->d_size);
+		else if (strcmp(name, "config") == 0)
+			err = bpf_obj_config_init(obj, data->d_buf,
+						  data->d_size);
 		if (err)
 			goto out;
 	}
@@ -387,5 +433,7 @@ void bpf_close_object(struct bpf_object *obj)
 		free(obj->path);
 	if (obj->maps_buf)
 		free(obj->maps_buf);
+	if (obj->config_str)
+		free(obj->config_str);
 	free(obj);
 }
-- 
1.8.3.4

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