1 Star 0 Fork 49

happy_orange/systemd

forked from src-anolis-os/systemd 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
10017-util-introduce-explicit_bzero_safe-for-explicit-mem.patch 1.77 KB
一键复制 编辑 原始数据 按行查看 历史
From 17037ec625fca9e9a473a33954d011065f0088e3 Mon Sep 17 00:00:00 2001
From: Guorui Yu <GuoRui.Yu@linux.alibaba.com>
Date: Fri, 23 Jun 2023 13:01:24 +0800
Subject: [PATCH] util: introduce explicit_bzero_safe for explicit memset
(cherry picked from commit f441ae81ef70e9bdfddbb9e0a276bbb8ca2151d4)
Signed-off-by: Guorui Yu <GuoRui.Yu@linux.alibaba.com>
---
src/basic/util.c | 18 ++++++++++++++++++
src/basic/util.h | 11 +++++++++++
2 files changed, 29 insertions(+)
diff --git a/src/basic/util.c b/src/basic/util.c
index 548e3652cc..bdfaca4aed 100644
--- a/src/basic/util.c
+++ b/src/basic/util.c
@@ -684,3 +684,21 @@ void disable_coredumps(void) {
if (r < 0)
log_debug_errno(r, "Failed to turn off coredumps, ignoring: %m");
}
+
+#if !HAVE_EXPLICIT_BZERO
+/*
+ * The pointer to memset() is volatile so that compiler must de-reference the pointer and can't assume that
+ * it points to any function in particular (such as memset(), which it then might further "optimize"). This
+ * approach is inspired by openssl's crypto/mem_clr.c.
+ */
+typedef void *(*memset_t)(void *,int,size_t);
+
+static volatile memset_t memset_func = memset;
+
+void* explicit_bzero_safe(void *p, size_t l) {
+ if (l > 0)
+ memset_func(p, '\0', l);
+
+ return p;
+}
+#endif
diff --git a/src/basic/util.h b/src/basic/util.h
index 195f02cf5f..ab3314f82e 100644
--- a/src/basic/util.h
+++ b/src/basic/util.h
@@ -240,3 +240,14 @@ int version(void);
int str_verscmp(const char *s1, const char *s2);
void disable_coredumps(void);
+
+#if HAVE_EXPLICIT_BZERO
+static inline void* explicit_bzero_safe(void *p, size_t l) {
+ if (l > 0)
+ explicit_bzero(p, l);
+
+ return p;
+}
+#else
+void *explicit_bzero_safe(void *p, size_t l);
+#endif
--
2.39.1
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/happy_orange/systemd.git
git@gitee.com:happy_orange/systemd.git
happy_orange
systemd
systemd
a8

搜索帮助

0d507c66 1850385 C8b1a773 1850385