DivestOS/Patches/LineageOS-16.0/android_system_core/0001-Harden.patch

58 lines
2.6 KiB
Diff
Raw Normal View History

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Daniel Micay <danielmicay@gmail.com>
Date: Mon, 12 Feb 2018 03:29:58 -0500
2019-07-05 20:47:59 +00:00
Subject: [PATCH] Harden
Change-Id: I46e3fc4ac896a509ab8ca90ae4ce09b820da434b
[tad@spotco.us]: added protected fifos and regular from newer GrapheneOS patches
[tad@spotco.us]: added IPv6 privacy options TODO split into another patch
---
init/init.cpp | 6 +++---
rootdir/init.rc | 11 +++++++++++
2 files changed, 14 insertions(+), 3 deletions(-)
diff --git a/init/init.cpp b/init/init.cpp
2019-06-17 20:30:01 +00:00
index eb9dd755b..504a6d13e 100644
--- a/init/init.cpp
+++ b/init/init.cpp
2019-06-17 20:30:01 +00:00
@@ -577,14 +577,14 @@ int main(int argc, char** argv) {
mount("tmpfs", "/dev", "tmpfs", MS_NOSUID, "mode=0755");
mkdir("/dev/pts", 0755);
mkdir("/dev/socket", 0755);
- mount("devpts", "/dev/pts", "devpts", 0, NULL);
+ mount("devpts", "/dev/pts", "devpts", MS_NOSUID|MS_NOEXEC, NULL);
#define MAKE_STR(x) __STRING(x)
- mount("proc", "/proc", "proc", 0, "hidepid=2,gid=" MAKE_STR(AID_READPROC));
+ mount("proc", "/proc", "proc", MS_NOSUID|MS_NODEV|MS_NOEXEC, "hidepid=2,gid=" MAKE_STR(AID_READPROC));
// Don't expose the raw commandline to unprivileged processes.
chmod("/proc/cmdline", 0440);
gid_t groups[] = { AID_READPROC };
setgroups(arraysize(groups), groups);
- mount("sysfs", "/sys", "sysfs", 0, NULL);
2019-03-04 08:27:18 +00:00
+ mount("sysfs", "/sys", "sysfs", MS_NOSUID|MS_NODEV|MS_NOEXEC, NULL);
mount("selinuxfs", "/sys/fs/selinux", "selinuxfs", 0, NULL);
mknod("/dev/kmsg", S_IFCHR | 0600, makedev(1, 11));
diff --git a/rootdir/init.rc b/rootdir/init.rc
index 9ad628b4e..4ed148857 100644
--- a/rootdir/init.rc
+++ b/rootdir/init.rc
@@ -121,6 +121,17 @@ on init
write /proc/sys/kernel/sched_wakeup_granularity_ns 2000000
write /proc/sys/kernel/sched_child_runs_first 0
+ write /proc/sys/kernel/dmesg_restrict 1
+ write /proc/sys/fs/protected_hardlinks 1
+ write /proc/sys/fs/protected_symlinks 1
+ write /proc/sys/fs/protected_fifos 1
+ write /proc/sys/fs/protected_regular 1
2019-07-05 20:47:59 +00:00
+ write /proc/sys/net/ipv6/conf/all/use_tempaddr 2
2020-05-13 21:25:52 +00:00
+ write /proc/sys/net/ipv6/conf/all/max_addresses 128
+ write /proc/sys/net/ipv6/conf/all/temp_prefered_lft 21600
2019-07-05 20:47:59 +00:00
+ write /proc/sys/net/ipv6/conf/default/use_tempaddr 2
2020-05-13 21:25:52 +00:00
+ write /proc/sys/net/ipv6/conf/default/max_addresses 128
+ write /proc/sys/net/ipv6/conf/default/temp_prefered_lft 21600
write /proc/sys/kernel/randomize_va_space 2
write /proc/sys/vm/mmap_min_addr 32768
write /proc/sys/net/ipv4/ping_group_range "0 2147483647"