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: <1431676290-1230-14-git-send-email-wangnan0@huawei.com>
Date:	Fri, 15 May 2015 07:51:06 +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>,
	<adrian.hunter@...el.com>, <dsahern@...il.com>, <ast@...mgrid.com>,
	<daniel@...earbox.net>, <brendan.d.gregg@...il.com>,
	<masami.hiramatsu.pt@...achi.com>
CC:	<linux-kernel@...r.kernel.org>, <lizefan@...wei.com>,
	<pi3orama@....com>, <wangnan0@...wei.com>
Subject: [RFC PATCH v2 13/37] tools lib bpf: collect config section in object.

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