Openwall GNU/*/Linux - a small security-enhanced Linux distro for servers
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Date: Sat, 15 Jul 2017 19:55:41 +0000
From: Nathan McSween <nwmcsween@...il.com>
To: musl@...ts.openwall.com
Cc: Nathan McSween <nwmcsween@...il.com>
Subject: [RFC PATCH 5/5] string: add memsset a 'secure' memset and bsd explicit_bzero

---
 src/string/explicit_bzero.c |  9 +++++++++
 src/string/memsset.c        | 13 +++++++++++++
 2 files changed, 22 insertions(+)
 create mode 100644 src/string/explicit_bzero.c
 create mode 100644 src/string/memsset.c

diff --git a/src/string/explicit_bzero.c b/src/string/explicit_bzero.c
new file mode 100644
index 00000000..497dd2bc
--- /dev/null
+++ b/src/string/explicit_bzero.c
@@ -0,0 +1,9 @@
+#define _BSD_SOURCE
+#include <string.h>
+
+void *__memsset(void *, int, size_t);
+
+void explicit_bzero(void *d, size_t n)
+{
+	__memsset(d, 0, n);
+}
diff --git a/src/string/memsset.c b/src/string/memsset.c
new file mode 100644
index 00000000..d4ab72a4
--- /dev/null
+++ b/src/string/memsset.c
@@ -0,0 +1,13 @@
+#include <string.h>
+
+#define hidden __attribute__((visibility("hidden")))
+
+hidden
+void *__memsset(void *d, int i, size_t n)
+{
+	memset(d, i, n);
+
+	__asm__ __volatile__("" : "=r" (d): "0" (d) : "memory");
+
+	return d;
+}
-- 
2.13.2

Powered by blists - more mailing lists

Your e-mail address:

Powered by Openwall GNU/*/Linux - Powered by OpenVZ