1 Star 0 Fork 78

Nic/ceph

forked from openEuler-RISC-V/ceph 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
0010-fix-CVE-2022-3650.patch 2.38 KB
一键复制 编辑 原始数据 按行查看 历史
王增亮 提交于 2022-12-06 04:04 . update 0010-fix-CVE-2022-3650.patch.
From f4035e49ee4745cd384d48a2334be793ce8df461 Mon Sep 17 00:00:00 2001
From: wangzengliang1 <wangzengliang1@huawei.com>
Date: Mon, 5 Dec 2022 15:10:45 +0800
Subject: [PATCH] fix
ceph-crash: drop privleges to run as "ceph" user, rather than root
If privileges cannot be dropped, log an error and exit. This commit
also catches and logs exceptions when scraping the crash path, without
which ceph-crash would just exit if it encountered an error.
Fixes: CVE-2022-3650
Fixes: https://tracker.ceph.com/issues/57967
Signed-off-by: Tim Serong <tserong@suse.com>
---
src/ceph-crash.in | 28 ++++++++++++++++++++++++++--
1 file changed, 26 insertions(+), 2 deletions(-)
diff --git a/src/ceph-crash.in b/src/ceph-crash.in
index c549dc1..ad5823e 100644
--- a/src/ceph-crash.in
+++ b/src/ceph-crash.in
@@ -3,8 +3,10 @@
# vim: ts=4 sw=4 smarttab expandtab
import argparse
+import grp
import logging
import os
+import pwd
import signal
import socket
import subprocess
@@ -45,7 +47,8 @@ def post_crash(path):
stderr=subprocess.PIPE,
)
f = open(os.path.join(path, 'meta'), 'rb')
- stdout, stderr = pr.communicate(input=f.read())
+ (_, stderr) = pr.communicate(input=f.read())
+ stderr = stderr.decode()
rc = pr.wait()
f.close()
if rc != 0:
@@ -80,7 +83,25 @@ def handler(signum, frame):
print('*** Interrupted with signal %d ***' % signum)
sys.exit(0)
+def drop_privs():
+ if os.getuid() == 0:
+ try:
+ ceph_uid = pwd.getpwnam("ceph").pw_uid
+ ceph_gid = grp.getgrnam("ceph").gr_gid
+ os.setgroups([])
+ os.setgid(ceph_gid)
+ os.setuid(ceph_uid)
+ except Exception as e:
+ log.error(f"Unable to drop privileges: {e}")
+ sys.exit(1)
+
+
def main():
+
+
+ # run as unprivileged ceph user
+ drop_privs()
+
# exit code 0 on SIGINT, SIGTERM
signal.signal(signal.SIGINT, handler)
signal.signal(signal.SIGTERM, handler)
@@ -96,7 +117,10 @@ def main():
log.info("monitoring path %s, delay %ds" % (args.path, args.delay * 60.0))
while True:
- scrape_path(args.path)
+ try:
+ scrape_path(args.path)
+ except Exception as e:
+ log.error(f"Error scraping {args.path}: {e}")
if args.delay == 0:
sys.exit(0)
time.sleep(args.delay * 60)
--
2.13.0.windows.1
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/dominic_z/ceph.git
git@gitee.com:dominic_z/ceph.git
dominic_z
ceph
ceph
master

搜索帮助