2018-04-04 07:52:11 -04:00
#!/bin/bash
#DivestOS: A privacy oriented Android distribution
2018-06-03 14:13:59 -04:00
#Copyright (c) 2017-2018 Divested Computing, Inc.
2018-04-04 07:52:11 -04:00
#
#This program is free software: you can redistribute it and/or modify
#it under the terms of the GNU General Public License as published by
#the Free Software Foundation, either version 3 of the License, or
#(at your option) any later version.
#
#This program is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
#GNU General Public License for more details.
#
#You should have received a copy of the GNU General Public License
#along with this program. If not, see <https://www.gnu.org/licenses/>.
2018-06-29 00:55:21 -04:00
if [ " $DOS_NON_COMMERCIAL_USE_PATCHES " = true ] ; then
2018-06-03 08:24:23 -04:00
echo -e "\e[0;33mWARNING: YOU HAVE ENABLED PATCHES THAT WHILE ARE OPEN SOURCE ARE ALSO ENCUMBERED BY RESTRICTIVE LICENSES\e[0m" ;
2018-04-23 18:18:09 -04:00
echo -e "\e[0;33mPLEASE SEE THE 'LICENSES' FILE AT THE ROOT OF THIS REPOSITORY FOR MORE INFORMATION\e[0m" ;
2018-06-03 08:24:23 -04:00
echo -e "\e[0;33mDISABLE THEM BY SETTING 'NON_COMMERCIAL_USE_PATCHES' TO 'false' IN 'Scripts/init.sh'\e[0m" ;
2018-04-23 18:18:09 -04:00
sleep 15;
fi ;
2018-04-04 07:52:11 -04:00
startPatcher( ) {
2018-07-04 15:35:16 -04:00
java -jar " $DOS_BINARY_PATCHER " patch " $DOS_BUILD_BASE " " $DOS_WORKSPACE_ROOT " "Patches/" " $DOS_SCRIPTS_CVES " $1 ;
2018-04-04 07:52:11 -04:00
}
export -f startPatcher;
enter( ) {
echo "================================================================================================"
2018-06-23 00:21:48 -04:00
dir = " $1 " ;
2018-06-29 00:55:21 -04:00
cd " $DOS_BUILD_BASE $dir " ;
2018-06-23 00:21:48 -04:00
echo " [ENTERING] $dir " ;
2018-04-04 07:52:11 -04:00
}
export -f enter;
enterAndClear( ) {
2018-06-23 00:21:48 -04:00
enter " $1 " ;
2018-04-04 07:52:11 -04:00
gitReset;
}
export -f enterAndClear;
gitReset( ) {
git add -A && git reset --hard;
}
export -f gitReset;
2018-05-10 23:45:29 -04:00
scanForMalware( ) {
2018-05-11 06:15:29 -04:00
if [ -x /usr/bin/clamscan ] && [ -r /var/lib/clamav/main.cvd ] ; then
echo -e "\e[0;32mStarting a malware scan...\e[0m" ;
excludes = "--exclude-dir=\".git\" --exclude-dir=\".repo\"" ;
2018-06-23 00:21:48 -04:00
scanQueue = " $2 " ;
2018-05-11 06:15:29 -04:00
if [ " $1 " = true ] ; then
2018-06-29 00:55:21 -04:00
if [ " $DOS_MALWARE_SCAN_SETTING " != "quick" ] || [ " $DOS_MALWARE_SCAN_SETTING " = "extra" ] ; then
scanQueue = $scanQueue " $DOS_BUILD_BASE /frameworks $DOS_BUILD_BASE /vendor " ;
2018-05-11 06:15:29 -04:00
fi ;
2018-06-29 00:55:21 -04:00
if [ " $DOS_MALWARE_SCAN_SETTING " = "slow" ] ; then
scanQueue = $scanQueue " $DOS_BUILD_BASE /external $DOS_BUILD_BASE /prebuilts $DOS_BUILD_BASE /toolchain $DOS_BUILD_BASE /tools " ;
2018-05-11 06:15:29 -04:00
fi ;
2018-06-29 00:55:21 -04:00
if [ " $DOS_MALWARE_SCAN_SETTING " = "full" ] ; then
scanQueue = " $DOS_BUILD_BASE " ;
2018-05-11 06:15:29 -04:00
fi ;
2018-05-11 02:50:52 -04:00
fi ;
2018-06-23 00:21:48 -04:00
du -hsc " $scanQueue " ;
/usr/bin/clamscan --recursive --detect-pua --infected " $excludes " " $scanQueue " ;
clamscanExit = " $? " ;
2018-05-10 23:45:29 -04:00
if [ " $clamscanExit " -eq "1" ] ; then
echo -e "\e[0;31m----------------------------------------------------------------\e[0m" ;
echo -e "\e[0;31mWARNING: MALWARE WAS FOUND! PLEASE INVESTIGATE!\e[0m" ;
echo -e "\e[0;31m----------------------------------------------------------------\e[0m" ;
2018-05-11 02:50:52 -04:00
sleep 60;
2018-05-10 23:45:29 -04:00
fi ;
if [ " $clamscanExit " -eq "0" ] ; then
echo -e "\e[0;32mNo malware found\e[0m" ;
2018-05-11 02:50:52 -04:00
fi ;
if [ " $clamscanExit " -eq "2" ] ; then
echo -e "\e[0;33m----------------------------------------------------------------\e[0m" ;
echo -e "\e[0;33mWARNING: AN ERROR OCCURED. PLEASE INVESTIGATE!\e[0m" ;
echo -e "\e[0;33m----------------------------------------------------------------\e[0m" ;
sleep 60;
2018-05-10 23:45:29 -04:00
fi ;
else
echo -e "\e[0;33mWARNING: clamscan is unavailable, a malware scan will not be performed!\e[0m" ;
fi ;
}
export -f scanForMalware;
2018-06-24 04:26:59 -04:00
generateBootAnimationMask( ) {
text = $1 ;
2018-06-24 05:26:03 -04:00
font = $2
output = $3 ;
convert -background black -fill transparent -font " $font " -gravity center -size 512x128 label:" $text " " $output " ;
2018-06-24 04:26:59 -04:00
}
export -f generateBootAnimationMask;
2018-06-24 08:42:02 -04:00
generateBootAnimationShine( ) {
color = $1 ;
2018-06-25 09:34:50 -04:00
style = $2 ;
output = $3 ;
2018-06-25 14:19:38 -04:00
#The colors need to be symmetrical in order to make the animation smooth and not have any noticble lines
convert -size 1024x128 -define gradient:angle= 90 " $style " :" $color " \( +clone -flop \) +append " $output " ;
2018-06-24 08:42:02 -04:00
}
export -f generateBootAnimationShine;
2018-06-13 19:48:53 -04:00
audit2allowCurrent( ) {
2018-06-24 05:26:03 -04:00
adb shell dmesg | audit2allow -p " $ANDROID_PRODUCT_OUT " /root/sepolicy;
2018-06-13 19:48:53 -04:00
}
export -f audit2allowCurrent;
audit2allowADB( ) {
adb pull /sys/fs/selinux/policy;
adb logcat -b all -d | audit2allow -p policy;
}
export -f audit2allowADB;
2018-04-04 07:52:11 -04:00
disableDexPreOpt( ) {
2018-06-29 00:55:21 -04:00
cd " $DOS_BUILD_BASE $1 " ;
2018-04-04 07:52:11 -04:00
if [ -f BoardConfig.mk ] ; then
sed -i "s/WITH_DEXPREOPT := true/WITH_DEXPREOPT := false/" BoardConfig.mk;
echo "Disabled dexpreopt" ;
fi ;
2018-06-29 00:55:21 -04:00
cd " $DOS_BUILD_BASE " ;
2018-04-04 07:52:11 -04:00
}
export -f disableDexPreOpt;
compressRamdisks( ) {
if [ -f BoardConfig.mk ] ; then
echo "LZMA_RAMDISK_TARGETS := boot,recovery" >> BoardConfig.mk;
echo "Enabled ramdisk compression" ;
fi ;
}
export -f compressRamdisks;
enhanceLocation( ) {
2018-08-07 23:07:36 -04:00
gpsConfig = $1 ;
#Attempt to get the real device directory
if [ [ " $gpsConfig " = *"device/" * ] ] ; then
deviceDir = $( sed 's|gps/gps.conf||' <<< " $gpsConfig " ) ;
deviceDir = $( sed 's|configs/gps.conf||' <<< " $deviceDir " ) ;
deviceDir = $( sed 's|gps/etc/gps.conf||' <<< " $deviceDir " ) ;
2018-08-08 20:23:26 -04:00
deviceDir = $( sed 's|gps.conf||' <<< " $deviceDir " ) ;
2018-08-07 23:07:36 -04:00
else
deviceDir = $( dirname " $gpsConfig " ) ;
fi ;
2018-08-08 20:23:26 -04:00
#Debugging (adb logcat | grep -i -e locsvc -e izat -e gps -e geo -e location)
2018-08-07 23:07:36 -04:00
#sed -i 's|DEBUG_LEVEL = .|DEBUG_LEVEL = 4|' "$gpsConfig" &> /dev/null || true;
2018-04-04 07:52:11 -04:00
#Enable GLONASS
2018-08-07 23:07:36 -04:00
if [ " $DOS_GPS_GLONASS_FORCED " = true ] ; then
sed -i 's/#A_GLONASS_POS_PROTOCOL_SELECT/A_GLONASS_POS_PROTOCOL_SELECT/' " $gpsConfig " & >/dev/null || true;
sed -i 's/A_GLONASS_POS_PROTOCOL_SELECT = 0.*/A_GLONASS_POS_PROTOCOL_SELECT = 15/' " $gpsConfig " & >/dev/null || true;
sed -i 's|A_GLONASS_POS_PROTOCOL_SELECT=0.*</item>|A_GLONASS_POS_PROTOCOL_SELECT=15</item>|' " $deviceDir " overlay/frameworks/base/core/res/res/values*/*.xml & >/dev/null || true;
2018-06-03 08:24:23 -04:00
fi ;
2018-08-07 23:07:36 -04:00
#Change capabilities
2018-08-08 20:23:26 -04:00
sed -i 's|CAPABILITIES=.*|CAPABILITIES=0x33|' " $gpsConfig " & > /dev/null || true; #Disable (?) MSA. 0x20 is used for both ULP and geofencing
2018-08-07 23:07:36 -04:00
#Change servers
sed -i " s|SUPL_HOST=.*|SUPL_HOST= $DOS_GPS_SUPL_HOST | " " $gpsConfig " & > /dev/null || true;
sed -i " s|NTP_SERVER=.*|NTP_SERVER= $DOS_GPS_NTP_SERVER | " " $gpsConfig " & > /dev/null || true;
2018-04-04 07:52:11 -04:00
#Recommended reading: https://wwws.nightwatchcybersecurity.com/2016/12/05/cve-2016-5341/
#XTRA: Only use specified URLs
2018-08-07 23:07:36 -04:00
sed -i 's|XTRA_SERVER_QUERY=1|XTRA_SERVER_QUERY=0|' " $gpsConfig " & >/dev/null || true;
sed -i 's|#XTRA_SERVER|XTRA_SERVER|' " $gpsConfig " & >/dev/null || true;
2018-08-09 00:42:07 -04:00
#Switch gpsOneXtra to IZatCloud (invalid certificate)
sed -i '/xtrapath/!s|://xtra|://xtrapath|' " $deviceDir " overlay/frameworks/base/core/res/res/values*/*.xml " $gpsConfig " & >/dev/null || true;
sed -i 's|gpsonextra.net|izatcloud.net|' " $deviceDir " overlay/frameworks/base/core/res/res/values*/*.xml " $gpsConfig " & >/dev/null || true;
#Enable HTTPS (IZatCloud supports HTTPS)
sed -i 's|http://xtrapath|https://xtrapath|' " $deviceDir " overlay/frameworks/base/core/res/res/values*/*.xml " $gpsConfig " & >/dev/null || true;
#sed -i 's|http://gllto|https://gllto|' "$deviceDir"overlay/frameworks/base/core/res/res/values*/*.xml "$gpsConfig" &>/dev/null || true; XXX: GLPals has an invaid certificate
2018-04-04 07:52:11 -04:00
#XTRA: Use format version 3 if possible
2018-08-07 23:07:36 -04:00
if grep -sq "XTRA_VERSION_CHECK" " $gpsConfig " ; then #Using hardware/qcom/gps OR precompiled blob OR device specific implementation
sed -i 's|XTRA_VERSION_CHECK=0|XTRA_VERSION_CHECK=1|' " $gpsConfig " & >/dev/null || true;
sed -i 's|xtra2.bin|xtra3grc.bin|' " $gpsConfig " & >/dev/null || true;
elif grep -sq "BOARD_VENDOR_QCOM_LOC_PDK_FEATURE_SET := true" " $deviceDir " BoardConfig.mk " $deviceDir " boards/*gps.mk; then
if ! grep -sq "USE_DEVICE_SPECIFIC_LOC_API := true" " $deviceDir " BoardConfig.mk " $deviceDir " boards/*gps.mk; then
if ! grep -sq "libloc" ./" $deviceDir " /*proprietary*.txt; then #Using hardware/qcom/gps
sed -i 's|xtra2.bin|xtra3grc.bin|' " $gpsConfig " & >/dev/null || true;
2018-04-04 07:52:11 -04:00
fi ;
fi ;
fi ;
2018-08-07 23:07:36 -04:00
echo " Enhanced location services for $deviceDir " ;
2018-04-04 07:52:11 -04:00
}
export -f enhanceLocation;
enableZram( ) {
2018-06-29 00:55:21 -04:00
cd " $DOS_BUILD_BASE $1 " ;
2018-04-04 07:52:11 -04:00
sed -i 's|#/dev/block/zram0|/dev/block/zram0|' fstab.* root/fstab.* rootdir/fstab.* rootdir/etc/fstab.* & >/dev/null || true;
echo " Enabled zram for $1 " ;
2018-06-29 00:55:21 -04:00
cd " $DOS_BUILD_BASE " ;
2018-04-04 07:52:11 -04:00
}
export -f enableZram;
enableForcedEncryption( ) {
2018-06-29 00:55:21 -04:00
cd " $DOS_BUILD_BASE $1 " ;
2018-04-23 15:41:43 -04:00
sed -i 's|encryptable=/|forceencrypt=/|' fstab.* root/fstab.* rootdir/fstab.* rootdir/etc/fstab.* & >/dev/null || true;
echo " Enabled forceencrypt for $1 " ;
2018-06-29 00:55:21 -04:00
cd " $DOS_BUILD_BASE " ;
2018-04-04 07:52:11 -04:00
}
export -f enableForcedEncryption;
enableStrongEncryption( ) {
2018-06-29 00:55:21 -04:00
cd " $DOS_BUILD_BASE $1 " ;
2018-04-04 07:52:11 -04:00
if [ -f BoardConfig.mk ] ; then
2018-04-28 15:35:53 -04:00
echo "TARGET_WANTS_STRONG_ENCRYPTION := true" >> BoardConfig.mk;
echo " Enabled AES-256 encryption for $1 " ;
2018-04-04 07:52:11 -04:00
fi ;
2018-06-29 00:55:21 -04:00
cd " $DOS_BUILD_BASE " ;
2018-04-04 07:52:11 -04:00
}
export -f enableStrongEncryption;
getDefconfig( ) {
if ls arch/arm/configs/lineage*defconfig 1> /dev/null 2>& 1; then
defconfigPath = "arch/arm/configs/lineage*defconfig" ;
elif ls arch/arm64/configs/lineage*defconfig 1> /dev/null 2>& 1; then
defconfigPath = "arch/arm64/configs/lineage*defconfig" ;
else
defconfigPath = "arch/arm/configs/*defconfig arch/arm64/configs/*defconfig" ;
fi ;
2018-06-23 01:08:42 -04:00
echo $defconfigPath ;
2018-04-04 07:52:11 -04:00
#echo "Found defconfig at $defconfigPath"
}
export -f getDefconfig;
2018-06-24 01:27:33 -04:00
changeDefaultDNS( ) {
dnsPrimary = "" ;
dnsPrimaryV6 = "" ;
dnsSecondary = "" ;
dnsSecondaryV6 = "" ;
2018-06-29 00:55:21 -04:00
if [ -z " $DNS_PRESET " ] ; then
if [ [ " $DOS_DEFAULT_DNS_PRESET " = = "Cloudflare" ] ] ; then #https://developers.cloudflare.com/1.1.1.1/commitment-to-privacy/privacy-policy/privacy-policy/
2018-06-24 01:27:33 -04:00
dnsPrimary = "1.0.0.1" ;
dnsPrimaryV6 = "2606:4700:4700::1001" ;
dnsSecondary = "1.1.1.1" ;
dnsSecondaryV6 = "2606:4700:4700::1111" ;
2018-06-29 00:55:21 -04:00
elif [ [ " $DOS_DEFAULT_DNS_PRESET " = = "OpenNIC" ] ] ; then #https://servers.opennicproject.org/edit.php?srv=ns3.any.dns.opennic.glue
2018-07-19 22:15:20 -04:00
dnsPrimary = "169.239.202.202" ; #RIP
2018-06-24 01:27:33 -04:00
dnsPrimaryV6 = "2a05:dfc7:5353::53" ;
dnsSecondary = "185.121.177.177" ;
dnsSecondaryV6 = "2a05:dfc7:5::53" ;
2018-06-29 00:55:21 -04:00
elif [ [ " $DOS_DEFAULT_DNS_PRESET " = = "DNSWATCH" ] ] ; then #https://dns.watch
2018-06-24 01:27:33 -04:00
dnsPrimary = "84.200.69.80" ;
dnsPrimaryV6 = "2001:1608:10:25::1c04:b12f" ;
dnsSecondary = "84.200.70.40" ;
dnsSecondaryV6 = "2001:1608:10:25::9249:d69b" ;
2018-06-29 00:55:21 -04:00
elif [ [ " $DOS_DEFAULT_DNS_PRESET " = = "Google" ] ] ; then #https://developers.google.com/speed/public-dns/privacy
2018-06-24 01:27:33 -04:00
dnsPrimary = "8.8.8.8" ;
dnsPrimaryV6 = "2001:4860:4860::8888" ;
dnsSecondary = "8.8.4.4" ;
dnsSecondaryV6 = "2001:4860:4860::8844" ;
2018-06-29 00:55:21 -04:00
elif [ [ " $DOS_DEFAULT_DNS_PRESET " = = "OpenDNS" ] ] ; then #https://www.cisco.com/c/en/us/about/legal/privacy-full.html
2018-06-24 01:27:33 -04:00
dnsPrimary = "208.67.222.222" ;
dnsPrimaryV6 = "2620:0:ccc::2" ;
dnsSecondary = "208.67.220.220" ;
dnsSecondaryV6 = "2620:0:ccd::2" ;
2018-06-29 00:55:21 -04:00
elif [ [ " $DOS_DEFAULT_DNS_PRESET " = = "Quad9" ] ] ; then #https://www.quad9.net/privacy/
2018-06-24 01:27:33 -04:00
dnsPrimary = "9.9.9.9" ;
dnsPrimaryV6 = "2620:fe::fe" ;
dnsSecondary = "149.112.112.112" ;
2018-06-25 19:15:22 -04:00
dnsSecondaryV6 = "2620:fe::fe" ; #no secondary available
2018-06-29 00:55:21 -04:00
elif [ [ " $DOS_DEFAULT_DNS_PRESET " = = "Quad9U" ] ] ; then #https://www.quad9.net/privacy/
2018-06-25 19:15:22 -04:00
dnsPrimary = "9.9.9.10" ;
dnsPrimaryV6 = "2620:fe::10" ;
dnsSecondary = "149.112.112.10" ;
dnsSecondaryV6 = "2620:fe::10" ; #no secondary available
2018-06-29 00:55:21 -04:00
elif [ [ " $DOS_DEFAULT_DNS_PRESET " = = "Verisign" ] ] ; then #https://www.verisign.com/en_US/security-services/public-dns/terms-of-service/index.xhtml
2018-06-24 04:26:59 -04:00
dnsPrimary = "64.6.64.6" ;
dnsPrimaryV6 = "2620:74:1b::1:1" ;
dnsSecondary = "64.6.65.6" ;
dnsSecondaryV6 = "2620:74:1c::2:2" ;
2018-06-24 01:27:33 -04:00
fi ;
else
echo "You must first set a preset via the DEFAULT_DNS_PRESET variable in init.sh!" ;
fi ;
2018-07-10 08:29:08 -04:00
files = "core/res/res/values/config.xml packages/SettingsLib/res/values/strings.xml services/core/java/com/android/server/connectivity/NetworkDiagnostics.java services/core/java/com/android/server/connectivity/Tethering.java services/core/java/com/android/server/connectivity/tethering/TetheringConfiguration.java services/java/com/android/server/connectivity/Tethering.java" ;
2018-06-24 01:27:33 -04:00
sed -i " s/8\.8\.8\.8/ $dnsPrimary / " $files & >/dev/null || true;
sed -i " s/2001:4860:4860::8888/ $dnsPrimaryV6 / " $files & >/dev/null || true;
sed -i " s/8\.8\.4\.4/ $dnsSecondary / " $files & >/dev/null || true;
sed -i " s/2001:4860:4860::8844/ $dnsSecondaryV6 / " $files & >/dev/null || true;
}
export -f changeDefaultDNS;
2018-04-04 07:52:11 -04:00
editKernelLocalversion( ) {
defconfigPath = $( getDefconfig)
2018-06-23 01:08:42 -04:00
sed -i 's/CONFIG_LOCALVERSION=".*"/CONFIG_LOCALVERSION="' " $1 " '"/' $defconfigPath & >/dev/null || true;
2018-04-04 07:52:11 -04:00
}
export -f editKernelLocalversion;
hardenDefconfig( ) {
2018-06-29 00:55:21 -04:00
cd " $DOS_BUILD_BASE $1 " ;
2018-04-04 07:52:11 -04:00
#Attempts to enable/disable supported options to increase security
#See https://kernsec.org/wiki/index.php/Kernel_Self_Protection_Project/Recommended_Settings
defconfigPath = $( getDefconfig)
#Enable supported options
#Disabled: CONFIG_DEBUG_SG (bootloops - https://patchwork.kernel.org/patch/8989981)
2018-06-13 19:48:53 -04:00
declare -a optionsYes = ( "CONFIG_ARM64_SW_TTBR0_PAN" "CONFIG_BUG" "CONFIG_BUG_ON_DATA_CORRUPTION" "CONFIG_CC_STACKPROTECTOR" "CONFIG_CC_STACKPROTECTOR_STRONG" "CONFIG_CPU_SW_DOMAIN_PAN" "CONFIG_DEBUG_CREDENTIALS" "CONFIG_DEBUG_KERNEL" "CONFIG_DEBUG_LIST" "CONFIG_DEBUG_NOTIFIERS" "CONFIG_DEBUG_RODATA" "CONFIG_DEBUG_WX" "CONFIG_FORTIFY_SOURCE" "CONFIG_GCC_PLUGIN_LATENT_ENTROPY" "CONFIG_GCC_PLUGIN_RANDSTRUCT" "CONFIG_GCC_PLUGINS" "CONFIG_GCC_PLUGIN_STRUCTLEAK" "CONFIG_GCC_PLUGIN_STRUCTLEAK_BYREF_ALL" "CONFIG_HARDENED_USERCOPY" "CONFIG_IO_STRICT_DEVMEM" "CONFIG_KAISER" "CONFIG_LEGACY_VSYSCALL_NONE" "CONFIG_PAGE_POISONING" "CONFIG_PAGE_POISONING_NO_SANITY" "CONFIG_PAGE_POISONING_ZERO" "CONFIG_PAGE_TABLE_ISOLATION" "CONFIG_PANIC_ON_OOPS" "CONFIG_RANDOMIZE_BASE" "CONFIG_REFCOUNT_FULL" "CONFIG_RETPOLINE" "CONFIG_SCHED_STACK_END_CHECK" "CONFIG_SECCOMP" "CONFIG_SECCOMP_FILTER" "CONFIG_SECURITY" "CONFIG_SECURITY_PERF_EVENTS_RESTRICT" "CONFIG_SECURITY_YAMA" "CONFIG_SECURITY_YAMA_STACKED" "CONFIG_SLAB_FREELIST_RANDOM" "CONFIG_SLAB_HARDENED" "CONFIG_SLUB_DEBUG" "CONFIG_STRICT_DEVMEM" "CONFIG_STRICT_KERNEL_RWX" "CONFIG_STRICT_MEMORY_RWX" "CONFIG_SYN_COOKIES" "CONFIG_UNMAP_KERNEL_AT_EL0" "CONFIG_VMAP_STACK" "CONFIG_SECURITY_DMESG_RESTRICT" "CONFIG_SLAB_FREELIST_HARDENED" "CONFIG_GCC_PLUGINS" "CONFIG_GCC_PLUGIN_LATENT_ENTROPY" "CONFIG_GCC_PLUGIN_STRUCTLEAK" "CONFIG_GCC_PLUGIN_STRUCTLEAK_BYREF_ALL" "CONFIG_GCC_PLUGIN_RANDSTRUCT" "CONFIG_GCC_PLUGIN_RANDSTRUCT_PERFORMANCE" )
2018-04-04 07:52:11 -04:00
for option in " ${ optionsYes [@] } "
do
2018-06-23 01:08:42 -04:00
sed -i 's/# ' " $option " ' is not set/' " $option " '=y/' $defconfigPath & >/dev/null || true;
2018-04-04 07:52:11 -04:00
#Some defconfigs are very minimal/not-autogenerated, so lets add the rest. Obviously most won't have any affect as they aren't supported.
2018-06-23 00:21:48 -04:00
if [ [ " $defconfigPath " = = *"lineage" * ] ] ; then
2018-06-23 01:08:42 -04:00
if ! grep -q " $option " "=y" $defconfigPath ; then
echo " $option " "=y" | tee -a $defconfigPath > /dev/null;
2018-04-04 07:52:11 -04:00
fi ;
fi ;
done
#Disable supported options
#TODO: Disable earjack/uart debugger
2018-06-13 19:48:53 -04:00
declare -a optionsNo = ( "CONFIG_ACPI_CUSTOM_METHOD" "CONFIG_BINFMT_MISC" "CONFIG_COMPAT_BRK" "CONFIG_COMPAT_VDSO" "CONFIG_CP_ACCESS64" "CONFIG_DEVKMEM" "CONFIG_DEVMEM" "CONFIG_DEVPORT" "CONFIG_HIBERNATION" "CONFIG_INET_DIAG" "CONFIG_KEXEC" "CONFIG_LEGACY_PTYS" "CONFIG_MSM_BUSPM_DEV" "CONFIG_OABI_COMPAT" "CONFIG_PROC_KCORE" "CONFIG_PROC_VMCORE" "CONFIG_SECURITY_SELINUX_DISABLE" "CONFIG_SLAB_MERGE_DEFAULT" "CONFIG_WLAN_FEATURE_MEMDUMP" )
2018-04-04 07:52:11 -04:00
for option in " ${ optionsNo [@] } "
do
2018-06-23 01:08:42 -04:00
sed -i 's/' " $option " '=y/# ' " $option " ' is not set/' $defconfigPath & >/dev/null || true;
2018-04-04 07:52:11 -04:00
done
#Extras
2018-06-23 01:08:42 -04:00
sed -i 's/CONFIG_ARCH_MMAP_RND_BITS=8/CONFIG_ARCH_MMAP_RND_BITS=16/' $defconfigPath & >/dev/null || true;
sed -i 's/CONFIG_ARCH_MMAP_RND_BITS=18/CONFIG_ARCH_MMAP_RND_BITS=24/' $defconfigPath & >/dev/null || true;
sed -i 's/CONFIG_DEFAULT_MMAP_MIN_ADDR=4096/CONFIG_DEFAULT_MMAP_MIN_ADDR=32768/' $defconfigPath & >/dev/null || true;
2018-06-26 05:57:22 -04:00
sed -i 's/CONFIG_LSM_MMAP_MIN_ADDR=4096/CONFIG_LSM_MMAP_MIN_ADDR=32768/' $defconfigPath & >/dev/null || true;
2018-04-04 07:52:11 -04:00
editKernelLocalversion "-dos" ;
echo " Hardened defconfig for $1 " ;
2018-06-29 00:55:21 -04:00
cd " $DOS_BUILD_BASE " ;
2018-04-04 07:52:11 -04:00
}
export -f hardenDefconfig;