Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions src/dde-session/impl/sessionmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -488,17 +488,12 @@ void SessionManager::RequestSuspend()
void SessionManager::SetLocked(bool lock)
{
// 仅允许dde-lock进程调用
QString cmdLine = QString("/proc/%1/cmdline").arg(connection().interface()->servicePid(message().service()).value());
QFile file(cmdLine);
uint pid = connection().interface()->servicePid(message().service()).value();

// NOTE: 如果以deepin-turbo进行加速启动,这里是不准确的,可能需要判断desktop文件的全路径,不过deepin-turbo后续应该会放弃支持
if (!file.open(QIODevice::ReadOnly)) {
qWarning() << "SetLocked: failed to read caller cmdline:" << cmdLine;
return;
}
const QString caller = QString::fromUtf8(file.readAll());
if (!caller.startsWith("/usr/bin/dde-lock") && !caller.startsWith("/usr/libexec/deepin/dde-lock")) {
qWarning() << "SetLocked: illegal caller:" << caller;
// 使用 /proc/<PID>/exe 符号链接验证调用者可执行文件路径,避免 cmdline 伪造
QString exePath = QFile::symLinkTarget(QString("/proc/%1/exe").arg(pid));
if (exePath != "/usr/bin/dde-lock" && exePath != "/usr/libexec/deepin/dde-lock") {
qWarning() << "SetLocked: illegal caller exe:" << exePath;
return;
}

Expand Down Expand Up @@ -626,7 +621,11 @@ void SessionManager::launchAutostopScripts()
const QFileInfoList &fileInfos = scriptDir.entryInfoList(QDir::Files);
for (auto info : fileInfos) {
qDebug() << "[autostop] script will be launched: " << info.absoluteFilePath();
EXEC_COMMAND("/bin/bash", QStringList() << "-c" << info.absoluteFilePath());
if (info.isExecutable()) {
EXEC_COMMAND(info.absoluteFilePath(), QStringList());
} else {
qWarning() << "[autostop] script is not executable, skipping:" << info.absoluteFilePath();
}
}
}
}
Expand Down
Loading