From 917713526fdc8d9c696d9a086a1a7412b6bfd0e1 Mon Sep 17 00:00:00 2001 From: Simon Sickle Date: Mon, 4 Dec 2017 23:38:40 -0600 Subject: [PATCH] Add cryptfs Signed-off-by: Simon Sickle --- BoardConfig.mk | 2 +- cryptfs_hw/Android.mk | 34 +++ cryptfs_hw/cryptfs_hw.c | 279 ++++++++++++++++++ cryptfs_hw/cryptfs_hw.h | 46 +++ .../vendor/lib64/hw/gatekeeper.msm8998.so | Bin .../root/vendor/lib64/hw/keystore.msm8998.so | Bin recovery/root/vendor/lib64/lib-sec-disp.so | Bin recovery/root/vendor/lib64/libGPreqcancel.so | Bin .../root/vendor/lib64/libGPreqcancel_svc.so | Bin recovery/root/vendor/lib64/libQSEEComAPI.so | Bin recovery/root/vendor/lib64/libSecureUILib.so | Bin recovery/root/vendor/lib64/libStDrvInt.so | Bin recovery/root/vendor/lib64/libdiag.so | Bin recovery/root/vendor/lib64/libdrmfs.so | Bin recovery/root/vendor/lib64/libdrmtime.so | Bin recovery/root/vendor/lib64/libqisl.so | Bin recovery/root/vendor/lib64/librpmb.so | Bin recovery/root/vendor/lib64/libsecureui.so | Bin .../root/vendor/lib64/libsecureui_svcsock.so | Bin recovery/root/vendor/lib64/libspl.so | Bin recovery/root/vendor/lib64/libssd.so | Bin recovery/root/vendor/lib64/libtime_genoff.so | Bin 22 files changed, 360 insertions(+), 1 deletion(-) create mode 100755 cryptfs_hw/Android.mk create mode 100755 cryptfs_hw/cryptfs_hw.c create mode 100755 cryptfs_hw/cryptfs_hw.h mode change 100755 => 100644 recovery/root/vendor/lib64/hw/gatekeeper.msm8998.so mode change 100755 => 100644 recovery/root/vendor/lib64/hw/keystore.msm8998.so mode change 100755 => 100644 recovery/root/vendor/lib64/lib-sec-disp.so mode change 100755 => 100644 recovery/root/vendor/lib64/libGPreqcancel.so mode change 100755 => 100644 recovery/root/vendor/lib64/libGPreqcancel_svc.so mode change 100755 => 100644 recovery/root/vendor/lib64/libQSEEComAPI.so mode change 100755 => 100644 recovery/root/vendor/lib64/libSecureUILib.so mode change 100755 => 100644 recovery/root/vendor/lib64/libStDrvInt.so mode change 100755 => 100644 recovery/root/vendor/lib64/libdiag.so mode change 100755 => 100644 recovery/root/vendor/lib64/libdrmfs.so mode change 100755 => 100644 recovery/root/vendor/lib64/libdrmtime.so mode change 100755 => 100644 recovery/root/vendor/lib64/libqisl.so mode change 100755 => 100644 recovery/root/vendor/lib64/librpmb.so mode change 100755 => 100644 recovery/root/vendor/lib64/libsecureui.so mode change 100755 => 100644 recovery/root/vendor/lib64/libsecureui_svcsock.so mode change 100755 => 100644 recovery/root/vendor/lib64/libspl.so mode change 100755 => 100644 recovery/root/vendor/lib64/libssd.so mode change 100755 => 100644 recovery/root/vendor/lib64/libtime_genoff.so diff --git a/BoardConfig.mk b/BoardConfig.mk index 9156c64..3da24c2 100755 --- a/BoardConfig.mk +++ b/BoardConfig.mk @@ -83,7 +83,7 @@ TW_EXCLUDE_SUPERSU := true TW_EXTRA_LANGUAGES := true TW_INCLUDE_CRYPTO := true TARGET_HW_DISK_ENCRYPTION = true -TARGET_CRYPTFS_HW_PATH := device/qcom/common/cryptfs_hw +TARGET_CRYPTFS_HW_PATH := device/oneplus/dumpling/cryptfs_hw TW_INCLUDE_NTFS_3G := true TW_INPUT_BLACKLIST := "hbtp_vm" TW_MAX_BRIGHTNESS := 255 diff --git a/cryptfs_hw/Android.mk b/cryptfs_hw/Android.mk new file mode 100755 index 0000000..5b5476f --- /dev/null +++ b/cryptfs_hw/Android.mk @@ -0,0 +1,34 @@ +ifeq ($(TARGET_HW_DISK_ENCRYPTION),true) +LOCAL_PATH:= $(call my-dir) +include $(CLEAR_VARS) + +LOCAL_PROPRIETARY_MODULE := true + +sourceFiles := \ + cryptfs_hw.c + +commonSharedLibraries := \ + libcutils \ + libutils \ + libdl \ + libhardware +commonIncludes := \ + hardware/libhardware/include/hardware/ + +LOCAL_C_INCLUDES := $(commonIncludes) +LOCAL_SRC_FILES := $(sourceFiles) + +LOCAL_MODULE_TAGS := optional +LOCAL_MODULE:= libcryptfs_hw +LOCAL_SHARED_LIBRARIES := $(commonSharedLibraries) + +LOCAL_MODULE_OWNER := qcom + +# USE_ICE_FOR_STORAGE_ENCRYPTION would be true in future if +# TARGET_USE_EMMC_USE_ICE is set +ifeq ($(TARGET_USE_UFS_ICE),true) +LOCAL_CFLAGS += -DUSE_ICE_FOR_STORAGE_ENCRYPTION +endif + +include $(BUILD_SHARED_LIBRARY) +endif \ No newline at end of file diff --git a/cryptfs_hw/cryptfs_hw.c b/cryptfs_hw/cryptfs_hw.c new file mode 100755 index 0000000..725a55c --- /dev/null +++ b/cryptfs_hw/cryptfs_hw.c @@ -0,0 +1,279 @@ +/* Copyright (c) 2014, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "cutils/log.h" +#include "cutils/properties.h" +#include "cutils/android_reboot.h" +#include "keymaster_common.h" +#include "hardware.h" + +#if defined(__LP64__) +#define QSEECOM_LIBRARY_PATH "/vendor/lib64/libQSEEComAPI.so" +#else +#define QSEECOM_LIBRARY_PATH "/vendor/lib/libQSEEComAPI.so" +#endif + + +// When device comes up or when user tries to change the password, user can +// try wrong password upto a certain number of times. If user enters wrong +// password further, HW would wipe all disk encryption related crypto data +// and would return an error ERR_MAX_PASSWORD_ATTEMPTS to VOLD. VOLD would +// wipe userdata partition once this error is received. +#define ERR_MAX_PASSWORD_ATTEMPTS -10 +#define QSEECOM_DISK_ENCRYPTION 1 +#define QSEECOM_UFS_ICE_DISK_ENCRYPTION 3 +#define QSEECOM_SDCC_ICE_DISK_ENCRYPTION 4 +#define MAX_PASSWORD_LEN 32 +#define QCOM_ICE_STORAGE_UFS 1 +#define QCOM_ICE_STORAGE_SDCC 2 + +/* Operations that be performed on HW based device encryption key */ +#define SET_HW_DISK_ENC_KEY 1 +#define UPDATE_HW_DISK_ENC_KEY 2 + +#define QSEECOM_UP_CHECK_COUNT 10 + +static int loaded_library = 0; +static int (*qseecom_create_key)(int, void*); +static int (*qseecom_update_key)(int, void*, void*); +static int (*qseecom_wipe_key)(int); + +inline void* secure_memset(void* v, int c , size_t n) { + volatile unsigned char* p = (volatile unsigned char* )v; + while (n--) *p++ = c; + return v; +} + + +static int map_usage(int usage) +{ + int storage_type = is_ice_enabled(); + if (usage == QSEECOM_DISK_ENCRYPTION) { + if (storage_type == QCOM_ICE_STORAGE_UFS) { + return QSEECOM_UFS_ICE_DISK_ENCRYPTION; + } + else if (storage_type == QCOM_ICE_STORAGE_SDCC) { + return QSEECOM_SDCC_ICE_DISK_ENCRYPTION ; + } + } + return usage; +} + +static unsigned char* get_tmp_passwd(const char* passwd) +{ + int passwd_len = 0; + unsigned char * tmp_passwd = NULL; + if(passwd) { + tmp_passwd = (unsigned char*)malloc(MAX_PASSWORD_LEN); + if(tmp_passwd) { + memset(tmp_passwd, 0, MAX_PASSWORD_LEN); + passwd_len = strnlen(passwd, MAX_PASSWORD_LEN); + memcpy(tmp_passwd, passwd, passwd_len); + } else { + SLOGE("%s: Failed to allocate memory for tmp passwd \n", __func__); + } + } else { + SLOGE("%s: Passed argument is NULL \n", __func__); + } + return tmp_passwd; +} + +static int is_qseecom_up() +{ + int i = 0; + char value[PROPERTY_VALUE_MAX] = {0}; + + for (; imodule_api_version; +} + +int should_use_keymaster() +{ + /* HW FDE key would be tied to keymaster only if: + * New Keymaster is available + * keymaster partition exists on the device + */ + int rc = 0; + if (get_keymaster_version() != KEYMASTER_MODULE_API_VERSION_1_0) { + SLOGI("Keymaster version is not 1.0"); + return rc; + } + + return 1; +} diff --git a/cryptfs_hw/cryptfs_hw.h b/cryptfs_hw/cryptfs_hw.h new file mode 100755 index 0000000..e857c47 --- /dev/null +++ b/cryptfs_hw/cryptfs_hw.h @@ -0,0 +1,46 @@ +/* Copyright (c) 2014, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef __CRYPTFS_HW_H_ +#define __CRYPTFS_HW_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +int set_hw_device_encryption_key(const char*, const char*); +int update_hw_device_encryption_key(const char*, const char*, const char*); +int clear_hw_device_encryption_key(); +unsigned int is_hw_disk_encryption(const char*); +int is_ice_enabled(void); +int should_use_keymaster(); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/recovery/root/vendor/lib64/hw/gatekeeper.msm8998.so b/recovery/root/vendor/lib64/hw/gatekeeper.msm8998.so old mode 100755 new mode 100644 diff --git a/recovery/root/vendor/lib64/hw/keystore.msm8998.so b/recovery/root/vendor/lib64/hw/keystore.msm8998.so old mode 100755 new mode 100644 diff --git a/recovery/root/vendor/lib64/lib-sec-disp.so b/recovery/root/vendor/lib64/lib-sec-disp.so old mode 100755 new mode 100644 diff --git a/recovery/root/vendor/lib64/libGPreqcancel.so b/recovery/root/vendor/lib64/libGPreqcancel.so old mode 100755 new mode 100644 diff --git a/recovery/root/vendor/lib64/libGPreqcancel_svc.so b/recovery/root/vendor/lib64/libGPreqcancel_svc.so old mode 100755 new mode 100644 diff --git a/recovery/root/vendor/lib64/libQSEEComAPI.so b/recovery/root/vendor/lib64/libQSEEComAPI.so old mode 100755 new mode 100644 diff --git a/recovery/root/vendor/lib64/libSecureUILib.so b/recovery/root/vendor/lib64/libSecureUILib.so old mode 100755 new mode 100644 diff --git a/recovery/root/vendor/lib64/libStDrvInt.so b/recovery/root/vendor/lib64/libStDrvInt.so old mode 100755 new mode 100644 diff --git a/recovery/root/vendor/lib64/libdiag.so b/recovery/root/vendor/lib64/libdiag.so old mode 100755 new mode 100644 diff --git a/recovery/root/vendor/lib64/libdrmfs.so b/recovery/root/vendor/lib64/libdrmfs.so old mode 100755 new mode 100644 diff --git a/recovery/root/vendor/lib64/libdrmtime.so b/recovery/root/vendor/lib64/libdrmtime.so old mode 100755 new mode 100644 diff --git a/recovery/root/vendor/lib64/libqisl.so b/recovery/root/vendor/lib64/libqisl.so old mode 100755 new mode 100644 diff --git a/recovery/root/vendor/lib64/librpmb.so b/recovery/root/vendor/lib64/librpmb.so old mode 100755 new mode 100644 diff --git a/recovery/root/vendor/lib64/libsecureui.so b/recovery/root/vendor/lib64/libsecureui.so old mode 100755 new mode 100644 diff --git a/recovery/root/vendor/lib64/libsecureui_svcsock.so b/recovery/root/vendor/lib64/libsecureui_svcsock.so old mode 100755 new mode 100644 diff --git a/recovery/root/vendor/lib64/libspl.so b/recovery/root/vendor/lib64/libspl.so old mode 100755 new mode 100644 diff --git a/recovery/root/vendor/lib64/libssd.so b/recovery/root/vendor/lib64/libssd.so old mode 100755 new mode 100644 diff --git a/recovery/root/vendor/lib64/libtime_genoff.so b/recovery/root/vendor/lib64/libtime_genoff.so old mode 100755 new mode 100644 -- 2.20.1