Commit 98dabd9c authored by Julian Pastarmov's avatar Julian Pastarmov Committed by Commit Bot

[SC] Fix disk encryption check for non dm disks

The current logic simply returned UNKNOWN for all cases that were
not a dm disk or we had trouble learning what is the uuid of that
disk.

With this change anything that is not a dm disk will return that
encryption is disabled. It also now checks the result of the stat
command and returns UNKNOWN if it fails as this prevents us from
doing the further interrogation.

BUG=1125634
TEST=unit_tests:EnterpriseReportingPrivateGetDeviceInfoTest.GetDeviceInfo

Change-Id: I83e3b825f1033e14c3819d5adbe35fc0ee1be1c9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2396377
Commit-Queue: Julian Pastarmov <pastarmovj@chromium.org>
Reviewed-by: default avatarOwen Min <zmin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#804917}
parent c927698e
...@@ -108,8 +108,9 @@ enterprise_reporting_private::SettingValue GetScreenlockSecured() { ...@@ -108,8 +108,9 @@ enterprise_reporting_private::SettingValue GetScreenlockSecured() {
// root device identifier, then locate its parent and get its type. // root device identifier, then locate its parent and get its type.
enterprise_reporting_private::SettingValue GetDiskEncrypted() { enterprise_reporting_private::SettingValue GetDiskEncrypted() {
struct stat info; struct stat info;
// First figure out the device identifier. // First figure out the device identifier. Fail fast if this fails.
stat("/", &info); if (stat("/", &info) != 0)
return enterprise_reporting_private::SETTING_VALUE_UNKNOWN;
int dev_major = major(info.st_dev); int dev_major = major(info.st_dev);
// The parent identifier will have the same major and minor 0. If and only if // The parent identifier will have the same major and minor 0. If and only if
// it is a dm device can it also be an encrypted device (as evident from the // it is a dm device can it also be an encrypted device (as evident from the
...@@ -117,16 +118,19 @@ enterprise_reporting_private::SettingValue GetDiskEncrypted() { ...@@ -117,16 +118,19 @@ enterprise_reporting_private::SettingValue GetDiskEncrypted() {
base::FilePath dev_uuid( base::FilePath dev_uuid(
base::StringPrintf("/sys/dev/block/%d:0/dm/uuid", dev_major)); base::StringPrintf("/sys/dev/block/%d:0/dm/uuid", dev_major));
std::string uuid; std::string uuid;
if (base::PathExists(dev_uuid) && if (base::PathExists(dev_uuid)) {
base::ReadFileToStringWithMaxSize(dev_uuid, &uuid, 1024)) { if (base::ReadFileToStringWithMaxSize(dev_uuid, &uuid, 1024)) {
// The device uuid starts with the driver type responsible for it. If it is // The device uuid starts with the driver type responsible for it. If it
// the "crypt" driver then it is an encrypted device. // is the "crypt" driver then it is an encrypted device.
bool is_encrypted = bool is_encrypted = base::StartsWith(
base::StartsWith(uuid, "crypt-", base::CompareCase::INSENSITIVE_ASCII); uuid, "crypt-", base::CompareCase::INSENSITIVE_ASCII);
return is_encrypted ? enterprise_reporting_private::SETTING_VALUE_ENABLED return is_encrypted
: enterprise_reporting_private::SETTING_VALUE_DISABLED; ? enterprise_reporting_private::SETTING_VALUE_ENABLED
: enterprise_reporting_private::SETTING_VALUE_DISABLED;
}
return enterprise_reporting_private::SETTING_VALUE_UNKNOWN;
} }
return enterprise_reporting_private::SETTING_VALUE_UNKNOWN; return enterprise_reporting_private::SETTING_VALUE_DISABLED;
} }
std::vector<std::string> GetMacAddresses() { std::vector<std::string> GetMacAddresses() {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment