Skip to content

Commit

Permalink
[lipstick] Revert broken window model protection. Contributes to JB#...
Browse files Browse the repository at this point in the history
On this setup calledFromDBus() was always returning false.

This reverts commit 24ed407.
  • Loading branch information
pvuorela committed Jan 3, 2019
1 parent 8f897ee commit 8c55e94
Show file tree
Hide file tree
Showing 11 changed files with 58 additions and 106 deletions.
2 changes: 1 addition & 1 deletion src/compositor/windowmodel.cpp
Expand Up @@ -173,7 +173,7 @@ void WindowModel::refresh()
void WindowModel::launchProcess(const QString &binaryName)
{
LipstickCompositor *c = LipstickCompositor::instance();
if (!m_complete || !c || !isPrivileged())
if (!m_complete || !c)
return;

QStringList binaryParts = binaryName.split(QRegExp(QRegExp("\\s+")));
Expand Down
5 changes: 1 addition & 4 deletions src/compositor/windowmodel.h
Expand Up @@ -18,16 +18,13 @@

#include "lipstickdbus.h"
#include "lipstickglobal.h"
#include "privilegeddbuscontext.h"

#include <QQmlParserStatus>
#include <QAbstractListModel>

class LipstickCompositor;
class LipstickCompositorWindow;
class LIPSTICK_EXPORT WindowModel : public QAbstractListModel,
public QQmlParserStatus,
public PrivilegedDBusContext
public QQmlParserStatus
{
Q_OBJECT
Q_INTERFACES(QQmlParserStatus)
Expand Down
26 changes: 26 additions & 0 deletions src/notifications/notificationmanager.cpp
Expand Up @@ -138,6 +138,7 @@ NotificationManager *NotificationManager::instance(bool owner)

NotificationManager::NotificationManager(QObject *parent, bool owner) :
QObject(parent),
QDBusContext(),
m_previousNotificationID(0),
m_categoryDefinitionStore(new CategoryDefinitionStore(CATEGORY_DEFINITION_FILE_DIRECTORY, MAX_CATEGORY_DEFINITION_FILES, this)),
m_androidPriorityStore(new AndroidPriorityStore(ANDROID_PRIORITY_DEFINITION_PATH, this)),
Expand Down Expand Up @@ -1063,6 +1064,31 @@ void NotificationManager::execSQL(const QString &command, const QVariantList &ar
m_databaseCommitTimer.start();
}

uint NotificationManager::callerProcessId() const
{
if (calledFromDBus()) {
return connection().interface()->servicePid(message().service()).value();
} else {
return QCoreApplication::applicationPid();
}
}

bool NotificationManager::isPrivileged() const
{
if (!calledFromDBus()) {
return true;
}

uint pid = callerProcessId();
QFileInfo info(QString("/proc/%1").arg(pid));
if (info.group() != QLatin1String("privileged") && info.owner() != QLatin1String("root")) {
QString errorString = QString("PID %1 is not in privileged group").arg(pid);
sendErrorReply(QDBusError::AccessDenied, errorString);
return false;
}
return true;
}

void NotificationManager::invokeAction(const QString &action)
{
LipstickNotification *notification = qobject_cast<LipstickNotification *>(sender());
Expand Down
7 changes: 4 additions & 3 deletions src/notifications/notificationmanager.h
Expand Up @@ -23,8 +23,6 @@
#include <QSet>
#include <QDBusContext>

#include <privilegeddbuscontext.h>

class AndroidPriorityStore;
class CategoryDefinitionStore;
class QSqlDatabase;
Expand All @@ -39,7 +37,7 @@ class QSqlDatabase;
* The service is registered as org.freedesktop.Notifications on the D-Bus
* session bus in the path /org/freedesktop/Notifications.
*/
class LIPSTICK_EXPORT NotificationManager : public QObject, public PrivilegedDBusContext
class LIPSTICK_EXPORT NotificationManager : public QObject, public QDBusContext
{
Q_OBJECT

Expand Down Expand Up @@ -384,6 +382,9 @@ private slots:
*/
void execSQL(const QString &command, const QVariantList &args = QVariantList());

uint callerProcessId() const;
bool isPrivileged() const;

//! The singleton notification manager instance
static NotificationManager *s_instance;

Expand Down
51 changes: 0 additions & 51 deletions src/privilegeddbuscontext.cpp

This file was deleted.

40 changes: 0 additions & 40 deletions src/privilegeddbuscontext.h

This file was deleted.

22 changes: 22 additions & 0 deletions src/shutdownscreen.cpp
Expand Up @@ -29,6 +29,7 @@

ShutdownScreen::ShutdownScreen(QObject *parent) :
QObject(parent),
QDBusContext(),
m_window(0),
m_systemState(new MeeGo::QmSystemState(this))
{
Expand Down Expand Up @@ -119,3 +120,24 @@ void ShutdownScreen::setShutdownMode(const QString &mode)
m_shutdownMode = mode;
applySystemState(MeeGo::QmSystemState::Shutdown);
}

bool ShutdownScreen::isPrivileged()
{
if (!calledFromDBus()) {
// Local function calls are always privileged
return true;
}

// Get the PID of the calling process
pid_t pid = connection().interface()->servicePid(message().service());

// The /proc/<pid> directory is owned by EUID:EGID of the process
QFileInfo info(QString("/proc/%1").arg(pid));
if (info.group() != "privileged" && info.owner() != "root") {
sendErrorReply(QDBusError::AccessDenied,
QString("PID %1 is not in privileged group").arg(pid));
return false;
}

return true;
}
5 changes: 3 additions & 2 deletions src/shutdownscreen.h
Expand Up @@ -20,11 +20,10 @@
#include <QDBusContext>
#include "lipstickglobal.h"
#include <qmsystemstate.h>
#include <privilegeddbuscontext.h>

class HomeWindow;

class LIPSTICK_EXPORT ShutdownScreen : public QObject, protected PrivilegedDBusContext
class LIPSTICK_EXPORT ShutdownScreen : public QObject, protected QDBusContext
{
Q_OBJECT
Q_PROPERTY(bool windowVisible READ windowVisible WRITE setWindowVisible NOTIFY windowVisibleChanged)
Expand Down Expand Up @@ -87,6 +86,8 @@ private slots:
#ifdef UNIT_TEST
friend class Ut_ShutdownScreen;
#endif

bool isPrivileged();
};

#endif // SHUTDOWNSCREEN_H
4 changes: 1 addition & 3 deletions src/src.pro
Expand Up @@ -54,8 +54,7 @@ PUBLICHEADERS += \
qmsystem2/system_global.h \
vpnagent.h \
connectivitymonitor.h \
connectionselector.h \
privilegeddbuscontext.h
connectionselector.h

INSTALLS += publicheaderfiles dbus_policy
publicheaderfiles.files = $$PUBLICHEADERS
Expand Down Expand Up @@ -138,7 +137,6 @@ SOURCES += \
qmsystem2/qmsystemstate.cpp \
qmsystem2/qmthermal.cpp \
qmsystem2/qmipcinterface.cpp \
privilegeddbuscontext.cpp \

CONFIG += link_pkgconfig mobility qt warn_on depend_includepath qmake_cache target_qt
CONFIG -= link_prl
Expand Down
1 change: 0 additions & 1 deletion tests/ut_notificationmanager/ut_notificationmanager.pro
Expand Up @@ -8,7 +8,6 @@ PKGCONFIG += mlite5
# unit test and unit
SOURCES += \
ut_notificationmanager.cpp \
$$SRCDIR/privilegeddbuscontext.cpp \
$$NOTIFICATIONSRCDIR/notificationmanager.cpp \
$$NOTIFICATIONSRCDIR/lipsticknotification.cpp \
$$STUBSDIR/stubbase.cpp \
Expand Down
1 change: 0 additions & 1 deletion tests/ut_shutdownscreen/ut_shutdownscreen.pro
Expand Up @@ -9,7 +9,6 @@ PKGCONFIG += dsme_dbus_if thermalmanager_dbus_if usb_moded
# unit test and unit
SOURCES += \
$$SRCDIR/shutdownscreen.cpp \
$$SRCDIR/privilegeddbuscontext.cpp \
$$NOTIFICATIONSRCDIR/lipsticknotification.cpp \
$$STUBSDIR/stubbase.cpp \
$$STUBSDIR/homewindow.cpp \
Expand Down

0 comments on commit 8c55e94

Please sign in to comment.