diff options
| author | Tom Marshall <tdm.code@gmail.com> | 2017-01-25 18:01:03 +0100 |
|---|---|---|
| committer | Mister Oyster <oysterized@gmail.com> | 2017-05-21 19:16:22 +0200 |
| commit | b93332000206a6748fa7854991b9a221ffc73ec7 (patch) | |
| tree | 914ce9693c4abe00c1308b8717201666efb2a8cc /kernel | |
| parent | 9463ff35f8e31e6c88866dfc236c95a66747190c (diff) | |
kernel: Only expose su when daemon is running
It has been claimed that the PG implementation of 'su' has security
vulnerabilities even when disabled. Unfortunately, the people that
find these vulnerabilities often like to keep them private so they
can profit from exploits while leaving users exposed to malicious
hackers.
In order to reduce the attack surface for vulnerabilites, it is
therefore necessary to make 'su' completely inaccessible when it
is not in use (except by the root and system users).
Change-Id: I79716c72f74d0b7af34ec3a8054896c6559a181d
Diffstat (limited to 'kernel')
| -rw-r--r-- | kernel/exit.c | 5 | ||||
| -rw-r--r-- | kernel/fork.c | 2 | ||||
| -rw-r--r-- | kernel/sched/core.c | 32 |
3 files changed, 39 insertions, 0 deletions
diff --git a/kernel/exit.c b/kernel/exit.c index 50f67cc5f..11f99c785 100644 --- a/kernel/exit.c +++ b/kernel/exit.c @@ -779,6 +779,11 @@ void do_exit(long code) } exit_signals(tsk); /* sets PF_EXITING */ + + if (tsk->flags & PF_SU) { + su_exit(); + } + /* * tsk->flags are checked in the futex code to protect against * an exiting task cleaning up the robust pi futexes. diff --git a/kernel/fork.c b/kernel/fork.c index 655a77cde..0669e8921 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -334,6 +334,8 @@ static struct task_struct *dup_task_struct(struct task_struct *orig) printk("[%d:%s] fork fail at arch_dup_task_struct, err:%d \n", current->pid, current->comm, err); goto free_ti; } + tsk->flags &= ~PF_SU; + tsk->stack = ti; #ifdef CONFIG_SECCOMP /* diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 007e48eee..482493467 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -102,6 +102,38 @@ # include <linux/prio_tracer.h> #endif +static atomic_t __su_instances; + +int su_instances(void) +{ + return atomic_read(&__su_instances); +} + +bool su_running(void) +{ + return su_instances() > 0; +} + +bool su_visible(void) +{ + kuid_t uid = current_uid(); + if (su_running()) + return true; + if (uid_eq(uid, GLOBAL_ROOT_UID) || uid_eq(uid, GLOBAL_SYSTEM_UID)) + return true; + return false; +} + +void su_exec(void) +{ + atomic_inc(&__su_instances); +} + +void su_exit(void) +{ + atomic_dec(&__su_instances); +} + void start_bandwidth_timer(struct hrtimer *period_timer, ktime_t period) { unsigned long delta; |
