Skip to content

Commit fe1eb84

Browse files
committed
refactor: Enhance coredump reporter service and refine D-Bus authorization
- Coredump Reporter Service: - Migrated coredump-reporter.service and coredump-reporter.timer installation from user-specific systemd/user to system-wide systemd/system. - Removed debian/deepin-log-viewer.postinst as the service is now managed globally. - Hardened coredump-reporter.service with User=root, ProtectSystem=strict, InaccessiblePaths for sensitive directories, and MemoryMax to improve security and resource management. - D-Bus Service Authorization: - Replaced the generic isValidInvoker function with specific checkAuth calls using action IDs (s_Action_View, s_Action_Export) in LogViewerService. - Removed the isValidInvoker function and its declaration, streamlining the authorization logic.
1 parent 4f6d4e8 commit fe1eb84

File tree

6 files changed

+18
-152
lines changed

6 files changed

+18
-152
lines changed

application/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ install(FILES configs/logconfig/deepin-log-viewer.json DESTINATION ${CMAKE_INSTA
351351
install(FILES configs/debugconfig/org.deepin.log.viewer.json DESTINATION ${CMAKE_INSTALL_PREFIX}/share/deepin-debug-config/deepin-debug-config.d/)
352352

353353
# Install coredump report service&timer
354-
install(FILES ./configs/coredump-reporter.timer ./configs/coredump-reporter.service DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/systemd/user/)
354+
install(FILES ./configs/coredump-reporter.timer ./configs/coredump-reporter.service DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/systemd/system/)
355355

356356
#安装DConfig配置
357357
set(APPID org.deepin.log.viewer)

application/configs/coredump-reporter.service

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,14 @@
22
Description=deepin-log-viewer coredump report activities
33

44
[Service]
5-
5+
Environment=HOME=/
6+
User=root
67
ExecStart=/usr/bin/deepin-log-viewer --reportcoredump
7-
CapabilityBoundingSet=~
8-
MemoryLimit=8G
9-
10-
[Install]
11-
WantedBy=multi-user.target
8+
ProtectSystem=strict
9+
InaccessiblePaths=-/etc/shadow
10+
InaccessiblePaths=-/etc/NetworkManager/system-connections
11+
InaccessiblePaths=-/etc/pam.d
12+
InaccessiblePaths=-/usr/share/uadp
13+
InaccessiblePaths=-/etc/sudoers
14+
InaccessiblePaths=-/etc/sudoers.d
15+
MemoryMax=8G

debian/deepin-log-viewer.install

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ usr/bin/logViewerAuth
33
usr/bin/logViewerTruncate
44
usr/bin/deepin-logger
55
usr/lib/deepin-daemon/log-view-service
6-
usr/lib/systemd/user/coredump-reporter.service
7-
usr/lib/systemd/user/coredump-reporter.timer
6+
usr/lib/systemd/system/coredump-reporter.service
7+
usr/lib/systemd/system/coredump-reporter.timer
88
usr/lib/systemd/system/deepin-log-viewer-daemon.service
99
usr/share/applications/deepin-log-viewer.desktop
1010
usr/share/dbus-1/system-services/com.deepin.logviewer.service

debian/deepin-log-viewer.postinst

Lines changed: 0 additions & 27 deletions
This file was deleted.

logViewerService/logviewerservice.cpp

Lines changed: 4 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -478,8 +478,7 @@ qint64 LogViewerService::findLineStartOffsetWithCaching(const QString &filePath,
478478
qint64 LogViewerService::getLineCount(const QString &filePath)
479479
{
480480
qCDebug(logService) << "Getting line count for file:" << filePath;
481-
if (!isValidInvoker()) {
482-
qCWarning(logService) << "Invalid invoker for getLineCount";
481+
if (!checkAuth(s_Action_View)) {
483482
return -1;
484483
}
485484

@@ -524,8 +523,7 @@ QString LogViewerService::executeCmd(const QString &cmd)
524523
qCDebug(logService) << "Executing command:" << cmd;
525524
QString result("");
526525

527-
if (!isValidInvoker()) {
528-
qCWarning(logService) << "Invalid invoker for executeCmd";
526+
if (!checkAuth(s_Action_Export)) {
529527
return result;
530528
}
531529

@@ -811,8 +809,7 @@ QStringList LogViewerService::getFileInfo(const QString &file, bool unzip)
811809
{
812810
qCDebug(logService) << "Getting file info for:" << file << "and unzip:" << unzip;
813811
// 判断非法调用
814-
if(!isValidInvoker()) {
815-
qCDebug(logService) << "Invalid invoker";
812+
if(!checkAuth(s_Action_View)) {
816813
return {};
817814
}
818815

@@ -933,8 +930,7 @@ QStringList LogViewerService::getOtherFileInfo(const QString &file, bool unzip)
933930
{
934931
qCDebug(logService) << "Getting other file info for:" << file << "and unzip:" << unzip;
935932
// 判断非法调用
936-
if(!isValidInvoker()) {
937-
qCDebug(logService) << "Invalid invoker";
933+
if(!checkAuth(s_Action_View)) {
938934
return {};
939935
}
940936

@@ -1177,109 +1173,6 @@ bool LogViewerService::exportLog(const QString &outDir, const QString &in, bool
11771173
return true;
11781174
}
11791175

1180-
bool LogViewerService::isValidInvoker(bool checkAuth/* = true*/)
1181-
{
1182-
qCDebug(logService) << "Checking if invoker is valid with checkAuth:" << checkAuth;
1183-
if (!calledFromDBus()) {
1184-
qCDebug(logService) << "Called not from dbus";
1185-
return false;
1186-
}
1187-
1188-
bool valid = false;
1189-
QDBusConnection conn = connection();
1190-
QDBusMessage msg = message();
1191-
1192-
//判断是否存在执行路径
1193-
uint pid = conn.interface()->servicePid(msg.service()).value();
1194-
1195-
// 判断是否存在执行路径且是否存在于可调用者名单中
1196-
QFile initNsMntFile("/proc/1/ns/mnt");
1197-
QFile senderNsMntFile(QString("/proc/%1/ns/mnt").arg(pid));
1198-
auto initNsMnt = initNsMntFile.symLinkTarget().trimmed().remove(0, QString("/proc/1/ns/mnt").length());
1199-
auto senderNsMnt = senderNsMntFile.symLinkTarget().trimmed().remove(0, QString("/proc/%1/ns/mnt").arg(pid).length());
1200-
if (initNsMnt != senderNsMnt) {
1201-
qCDebug(logService) << "Init ns mnt not equal to sender ns mnt";
1202-
sendErrorReply(QDBusError::ErrorType::Failed, "Illegal calls!!!!!");
1203-
return false;
1204-
}
1205-
1206-
//进制使用环境变量导入.so动态调用dbus接口
1207-
QProcess proc;
1208-
proc.start(QString("cat /proc/%1/maps").arg(pid));
1209-
proc.waitForStarted();
1210-
proc.waitForFinished();
1211-
QString maps = QString::fromLocal8Bit(proc.readAllStandardOutput()).trimmed();
1212-
proc.close();
1213-
QStringList libMaps = maps.split("\n", SKIP_EMPTY_PARTS);
1214-
QStringList allParts;
1215-
for (const QString &part : libMaps) {
1216-
QStringList subParts = part.split(' ');
1217-
for (const QString &subPart : subParts) {
1218-
if (!subPart.isEmpty()) {
1219-
allParts.append(subPart);
1220-
}
1221-
}
1222-
}
1223-
for (int j = 0; j < allParts.count(); ++j) {
1224-
QString libStr = allParts.at(j);
1225-
QFileInfo info(libStr);
1226-
if (info.isFile()) {
1227-
QString fileName = info.fileName();
1228-
if (fileName.contains(".so")) {
1229-
QStringList libpath = libStr.split("/", SKIP_EMPTY_PARTS);
1230-
if (libpath.count() > 2) {
1231-
QString libhead = QString("/%1/%2").arg(libpath.at(0)).arg(libpath.at(1));
1232-
if (libhead != "/usr/lib") {
1233-
sendErrorReply(QDBusError::ErrorType::Failed, "Illegal calls!");
1234-
return false;
1235-
}
1236-
}
1237-
}
1238-
}
1239-
}
1240-
1241-
QFileInfo f(QString("/proc/%1/exe").arg(pid));
1242-
if (!f.exists()) {
1243-
valid = false;
1244-
} else {
1245-
valid = true;
1246-
}
1247-
1248-
//是否存在于可调用者名单中
1249-
QStringList ValidInvokerExePathList;
1250-
QString invokerPath = f.canonicalFilePath();
1251-
QStringList findPaths;//合法调用者查找目录列表
1252-
findPaths << "/usr/bin";
1253-
ValidInvokerExePathList << QStandardPaths::findExecutable("deepin-log-viewer", findPaths);
1254-
1255-
if (valid)
1256-
valid = ValidInvokerExePathList.contains(invokerPath);
1257-
1258-
// pokit前端进程鉴权
1259-
bool bAuthValid = true;
1260-
QString strCheckAuthTip;
1261-
if (valid && checkAuth) {
1262-
qCDebug(logService) << "Checking authorization for:" << m_actionId << "and pid:" << pid;
1263-
bAuthValid = checkAuthorization(m_actionId);
1264-
valid = bAuthValid;
1265-
if (!bAuthValid) {
1266-
strCheckAuthTip = "checkAuthorization failed.";
1267-
qCWarning(logService) << strCheckAuthTip;
1268-
}
1269-
}
1270-
//非法调用
1271-
if (!valid) {
1272-
qCDebug(logService) << "Invalid invoker";
1273-
sendErrorReply(QDBusError::ErrorType::Failed,
1274-
QString("(pid: %1)[%2] is not allowed to configrate firewall. %3")
1275-
.arg(pid)
1276-
.arg((invokerPath))
1277-
.arg(strCheckAuthTip));
1278-
return false;
1279-
}
1280-
return true;
1281-
}
1282-
12831176
bool LogViewerService::checkAuth(const QString &actionId)
12841177
{
12851178
qCDebug(logService) << "Checking auth for:" << actionId;

logViewerService/logviewerservice.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,7 @@ public Q_SLOTS:
7575
QMap<QString, QString> m_commands;
7676
QMap<QString, std::pair<QString, QTextStream*>> m_logMap;
7777
QMap<QString, QList<uint64_t>> m_logLineIndex;
78-
/**
79-
* @brief isValidInvoker 检验调研者是否是日志
80-
* @return
81-
*/
82-
bool isValidInvoker(bool checkAuth = false);
78+
8379
bool checkAuth(const QString &actionId);
8480
QByteArray processCatFile(const QString &filePath);
8581
void processCmdArgs(const QString &cmdStr, const QStringList &args);

0 commit comments

Comments
 (0)