From 3272cd3f5fd1ee340c7440dbb4778c8350babea7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrius=20=C5=A0tikonas?= Date: Sun, 30 Oct 2016 02:31:46 +0000 Subject: [PATCH] Do not allow deactivating LUKS containers containing active LVM physical volumes. --- src/core/partition.cpp | 9 ++++++++- src/core/partition.h | 7 ++++--- src/fs/luks.cpp | 2 +- src/fs/lvm2_pv.cpp | 16 ++++++++-------- src/jobs/deactivatevolumegroupjob.cpp | 8 +++++++- 5 files changed, 28 insertions(+), 14 deletions(-) diff --git a/src/core/partition.cpp b/src/core/partition.cpp index 2e9faed..31c2e04 100644 --- a/src/core/partition.cpp +++ b/src/core/partition.cpp @@ -23,6 +23,7 @@ #include "fs/filesystem.h" #include "fs/filesystemfactory.h" +#include "fs/luks.h" #include "util/externalcommand.h" #include "util/report.h" @@ -283,7 +284,13 @@ bool Partition::canMount() const /** @return true if this Partition can be unmounted */ bool Partition::canUnmount() const { - return !roles().has(PartitionRole::Extended) && isMounted(); + return !roles().has(PartitionRole::Extended) && isMounted() && fileSystem().canUnmount(deviceNode()); +} + +void Partition::setMounted(bool b) { + m_IsMounted = b; + if (roles().has(PartitionRole::Luks)) + static_cast(m_FileSystem)->setMounted(b); } /** Tries to mount a Partition. diff --git a/src/core/partition.h b/src/core/partition.h index ba93792..3340e30 100644 --- a/src/core/partition.h +++ b/src/core/partition.h @@ -100,6 +100,8 @@ class LIBKPMCORE_EXPORT Partition : public PartitionNode friend class SetPartFlagsJob; friend class RestoreFileSystemJob; + friend class DeactivateVolumeGroupJob; + friend QTextStream& operator<<(QTextStream& stream, const Partition& p); public: @@ -254,9 +256,8 @@ protected: m_SectorSize = s; } void move(qint64 newStartSector); - void setMounted(bool b) { - m_IsMounted = b; - } + void setMounted(bool b); + void setFlag(PartitionTable::Flag f) { m_ActiveFlags |= f; } diff --git a/src/fs/luks.cpp b/src/fs/luks.cpp index a408ccf..60ed9ce 100644 --- a/src/fs/luks.cpp +++ b/src/fs/luks.cpp @@ -625,7 +625,7 @@ void luks::initLUKS(FileSystem* fs) luksFS->setCryptOpen(isCryptOpen); if (isCryptOpen) { luksFS->loadInnerFileSystem(mapperNode); - luksFS->setMounted(::isMounted(mapperNode)); //isMounted from helpers.h + luksFS->setMounted(detectMountStatus(luksFS->innerFS(), mapperNode)); } } } diff --git a/src/fs/lvm2_pv.cpp b/src/fs/lvm2_pv.cpp index 3487d55..53bd5f0 100644 --- a/src/fs/lvm2_pv.cpp +++ b/src/fs/lvm2_pv.cpp @@ -174,29 +174,29 @@ QString lvm2_pv::readUUID(const QString& deviceNode) const bool lvm2_pv::mount(Report& report, const QString& deviceNode, const QString& mountPoint) { - Q_UNUSED(report); - Q_UNUSED(deviceNode); - Q_UNUSED(mountPoint); + Q_UNUSED(report) + Q_UNUSED(deviceNode) + Q_UNUSED(mountPoint) return false; } bool lvm2_pv::unmount(Report& report, const QString& deviceNode) { - Q_UNUSED(deviceNode); - Q_UNUSED(report); + Q_UNUSED(deviceNode) + Q_UNUSED(report) return false; } bool lvm2_pv::canMount(const QString& deviceNode, const QString& mountPoint) const { - Q_UNUSED(deviceNode); - Q_UNUSED(mountPoint); + Q_UNUSED(deviceNode) + Q_UNUSED(mountPoint) return false; } bool lvm2_pv::canUnmount(const QString& deviceNode) const { - Q_UNUSED(deviceNode); + Q_UNUSED(deviceNode) return false; } diff --git a/src/jobs/deactivatevolumegroupjob.cpp b/src/jobs/deactivatevolumegroupjob.cpp index 56f7c09..3439141 100644 --- a/src/jobs/deactivatevolumegroupjob.cpp +++ b/src/jobs/deactivatevolumegroupjob.cpp @@ -18,6 +18,7 @@ #include "jobs/deactivatevolumegroupjob.h" #include "core/lvmdevice.h" +#include "core/partition.h" #include "util/report.h" @@ -38,7 +39,12 @@ bool DeactivateVolumeGroupJob::run(Report& parent) Report* report = jobStarted(parent); if (device().type() == Device::LVM_Device) { - rval = LvmDevice::deactivateVG(*report, dynamic_cast(device())); + rval = LvmDevice::deactivateVG(*report, static_cast(device())); + } + const auto lvmPVs = static_cast(device()).physicalVolumes(); + for (auto &p : lvmPVs) { + Partition *partition = const_cast(p); + partition->setMounted(false); } jobFinished(*report, rval);