android_kernel_google_msm/kernel
Kees Cook ec7215ac09 fs: add link restrictions
This adds symlink and hardlink restrictions to the Linux VFS.

Symlinks:

A long-standing class of security issues is the symlink-based
time-of-check-time-of-use race, most commonly seen in world-writable
directories like /tmp. The common method of exploitation of this flaw
is to cross privilege boundaries when following a given symlink (i.e. a
root process follows a symlink belonging to another user). For a likely
incomplete list of hundreds of examples across the years, please see:
http://cve.mitre.org/cgi-bin/cvekey.cgi?keyword=/tmp

The solution is to permit symlinks to only be followed when outside
a sticky world-writable directory, or when the uid of the symlink and
follower match, or when the directory owner matches the symlink's owner.

Some pointers to the history of earlier discussion that I could find:

 1996 Aug, Zygo Blaxell
  http://marc.info/?l=bugtraq&m=87602167419830&w=2
 1996 Oct, Andrew Tridgell
  http://lkml.indiana.edu/hypermail/linux/kernel/9610.2/0086.html
 1997 Dec, Albert D Cahalan
  http://lkml.org/lkml/1997/12/16/4
 2005 Feb, Lorenzo Hernández García-Hierro
  http://lkml.indiana.edu/hypermail/linux/kernel/0502.0/1896.html
 2010 May, Kees Cook
  https://lkml.org/lkml/2010/5/30/144

Past objections and rebuttals could be summarized as:

 - Violates POSIX.
   - POSIX didn't consider this situation and it's not useful to follow
     a broken specification at the cost of security.
 - Might break unknown applications that use this feature.
   - Applications that break because of the change are easy to spot and
     fix. Applications that are vulnerable to symlink ToCToU by not having
     the change aren't. Additionally, no applications have yet been found
     that rely on this behavior.
 - Applications should just use mkstemp() or O_CREATE|O_EXCL.
   - True, but applications are not perfect, and new software is written
     all the time that makes these mistakes; blocking this flaw at the
     kernel is a single solution to the entire class of vulnerability.
 - This should live in the core VFS.
   - This should live in an LSM. (https://lkml.org/lkml/2010/5/31/135)
 - This should live in an LSM.
   - This should live in the core VFS. (https://lkml.org/lkml/2010/8/2/188)

Hardlinks:

On systems that have user-writable directories on the same partition
as system files, a long-standing class of security issues is the
hardlink-based time-of-check-time-of-use race, most commonly seen in
world-writable directories like /tmp. The common method of exploitation
of this flaw is to cross privilege boundaries when following a given
hardlink (i.e. a root process follows a hardlink created by another
user). Additionally, an issue exists where users can "pin" a potentially
vulnerable setuid/setgid file so that an administrator will not actually
upgrade a system fully.

The solution is to permit hardlinks to only be created when the user is
already the existing file's owner, or if they already have read/write
access to the existing file.

Many Linux users are surprised when they learn they can link to files
they have no access to, so this change appears to follow the doctrine
of "least surprise". Additionally, this change does not violate POSIX,
which states "the implementation may require that the calling process
has permission to access the existing file"[1].

This change is known to break some implementations of the "at" daemon,
though the version used by Fedora and Ubuntu has been fixed[2] for
a while. Otherwise, the change has been undisruptive while in use in
Ubuntu for the last 1.5 years.

[1] http://pubs.opengroup.org/onlinepubs/9699919799/functions/linkat.html
[2] http://anonscm.debian.org/gitweb/?p=collab-maint/at.git;a=commitdiff;h=f4114656c3a6c6f6070e315ffdf940a49eda3279

This patch is based on the patches in Openwall and grsecurity, along with
suggestions from Al Viro. I have added a sysctl to enable the protected
behavior, and documentation.

Change-Id: Ic4872c58e8a0672147c73b13175ea143e19915ba
Signed-off-by: Kees Cook <keescook@chromium.org>
Acked-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2018-12-07 22:28:48 +04:00
..
debug Merge remote-tracking branch 'stable/linux-3.4.y' into lineage-15.1 2017-12-27 17:13:15 +03:00
events perf/core: Fix concurrent sys_perf_event_open() vs. 'move_group' race 2018-01-13 17:13:44 +03:00
gcov
irq Merge remote-tracking branch 'stable/linux-3.4.y' into lineage-15.1 2017-12-27 17:13:15 +03:00
power Merge remote-tracking branch 'stable/linux-3.4.y' into lineage-15.1 2017-12-27 17:13:15 +03:00
sched Merge remote-tracking branch 'stable/linux-3.4.y' into lineage-15.1 2017-12-27 17:13:15 +03:00
time sched_clock: Squashed revert of the latest updates 2018-02-20 21:56:17 +03:00
trace Merge remote-tracking branch 'stable/linux-3.4.y' into lineage-15.1 2017-12-27 17:13:15 +03:00
.gitignore kernel/hz.bc: ignore. 2016-10-29 23:12:15 +08:00
acct.c
async.c Fix a dead loop in async_synchronize_full() 2012-10-02 10:30:35 -07:00
audit.c audit: wait_for_auditd() should use TASK_UNINTERRUPTIBLE 2014-04-14 06:44:15 -07:00
audit.h
audit_tree.c Merge remote-tracking branch 'stable/linux-3.4.y' into lineage-15.1 2017-12-27 17:13:15 +03:00
audit_watch.c get rid of kern_path_parent() 2017-09-22 19:11:54 +03:00
auditfilter.c
auditsc.c Merge remote-tracking branch 'stable/linux-3.4.y' into lineage-15.1 2017-12-27 17:13:15 +03:00
backtracetest.c
bounds.c
capability.c
cgroup.c stop passing nameidata to ->lookup() 2018-12-07 22:26:28 +04:00
cgroup_freezer.c cgroup: cgroup_subsys->fork() should be called after the task is added to css_set 2014-03-11 16:10:03 -07:00
compat.c compat: Fix RT signal mask corruption via sigprocmask 2012-05-10 08:58:33 -07:00
configs.c
cpu.c CPU hotplug: Provide lockless versions of callback registration functions 2018-01-01 21:26:45 +03:00
cpu_pm.c
cpuset.c cpuset: PF_SPREAD_PAGE and PF_SPREAD_SLAB should be atomic flags 2014-12-01 18:02:38 +08:00
crash_dump.c
cred.c cred: copy_process() should clear child->replacement_session_keyring 2012-04-11 08:20:11 -07:00
delayacct.c
dma.c Remove all #inclusions of asm/system.h 2012-03-28 18:30:03 +01:00
elfcore.c
exec_domain.c ANDROID: exec_domains: Disable request_module() call for personalities 2017-12-27 22:46:26 +03:00
exit.c Merge remote-tracking branch 'stable/linux-3.4.y' into lineage-15.1 2017-12-27 17:13:15 +03:00
extable.c
fork.c seccomp: Replace BUG(!spin_is_locked()) with assert_spin_lock 2017-12-27 22:42:09 +03:00
freezer.c Merge remote-tracking branch 'stable/linux-3.4.y' into lineage-15.1 2017-12-27 17:13:15 +03:00
futex.c Merge remote-tracking branch 'stable/linux-3.4.y' into lineage-15.1 2017-12-27 17:13:15 +03:00
futex_compat.c futex: Revert "futex: Mark get_robust_list as deprecated" 2013-02-28 06:59:01 -08:00
groups.c
hrtimer.c Merge remote-tracking branch 'stable/linux-3.4.y' into lineage-15.1 2017-12-27 17:13:15 +03:00
hung_task.c hung_task: fix the broken rcu_lock_break() logic 2012-03-05 15:49:42 -08:00
irq_work.c irq_work: fix compile failure on tile from missing include 2012-04-13 13:15:16 -04:00
itimer.c itimer: Use printk_once instead of WARN_ONCE 2012-04-10 11:00:30 +02:00
jump_label.c static keys: Inline the static_key_enabled() function 2012-02-28 20:01:08 +01:00
kallsyms.c vsprintf: Fix %ps on non symbols when using kallsyms 2013-02-08 15:14:22 -08:00
Kconfig.freezer
Kconfig.hz
Kconfig.locks locking/kconfig: Simplify INLINE_SPIN_UNLOCK usage 2012-03-23 13:18:57 +01:00
Kconfig.preempt locking/kconfig: Simplify INLINE_SPIN_UNLOCK usage 2012-03-23 13:18:57 +01:00
kexec.c Merge branch 'akpm' (Andrew's patch-bomb) 2012-03-28 17:19:28 -07:00
kfifo.c
kmod.c usermodehelper: check subprocess_info->path != NULL 2013-05-19 10:54:50 -07:00
kprobes.c kprobes: return proper error code from register_kprobe() 2012-03-05 15:49:42 -08:00
ksysfs.c rcu: Add a module parameter to force use of expedited RCU primitives 2016-10-29 23:12:17 +08:00
kthread.c Merge remote-tracking branch 'stable/linux-3.4.y' into lineage-15.1 2017-12-27 17:13:15 +03:00
latencytop.c
lglock.c brlocks/lglocks: turn into functions 2015-07-13 11:17:40 -07:00
lockdep.c lockdep: remove task argument from debug_check_no_locks_held 2013-07-12 14:22:56 -07:00
lockdep_internals.h
lockdep_proc.c
lockdep_states.h
Makefile hotplug: Fix UP bug in smpboot hotplug code 2016-10-29 23:12:39 +08:00
module.c module: Fix locking in symbol_put_addr() 2016-04-27 18:55:19 +08:00
mutex-debug.c
mutex-debug.h
mutex.c sched/rt: Use schedule_preempt_disabled() 2012-03-01 10:28:03 +01:00
mutex.h
notifier.c
nsproxy.c userns: make each net (net_ns) belong to a user_ns 2017-09-01 13:38:07 +03:00
padata.c padata: Fix cpu hotplug 2012-03-29 19:52:46 +08:00
panic.c Merge remote-tracking branch 'stable/linux-3.4.y' into lineage-15.1 2017-12-27 17:13:15 +03:00
params.c params: <level>_initcall-like kernel parameters 2012-03-26 12:50:51 +10:30
pid.c BACKPORT: FROMLIST: pids: make task_tgid_nr_ns() safe 2018-01-13 17:13:41 +03:00
pid_namespace.c proc: Usable inode numbers for the namespace file descriptors. 2015-07-13 11:18:01 -07:00
posix-cpu-timers.c posix-cpu-timers: Fix nanosleep task_struct leak 2013-02-28 06:58:59 -08:00
posix-timers.c posix-timers: Fix stack info leak in timer_create() 2015-02-02 17:05:05 +08:00
printk.c Merge remote-tracking branch 'stable/linux-3.4.y' into lineage-15.1 2017-12-27 17:13:15 +03:00
profile.c
ptrace.c Merge remote-tracking branch 'stable/linux-3.4.y' into lineage-15.1 2017-12-27 17:13:15 +03:00
range.c
rcu.h rcu: Add a module parameter to force use of expedited RCU primitives 2016-10-29 23:12:17 +08:00
rcupdate.c rcu: Make exit_rcu() more precise and consolidate 2016-10-29 23:12:17 +08:00
rcutiny.c rcu: Correctly handle non-empty Tiny RCU callback list with none ready 2015-10-22 09:20:02 +08:00
rcutiny_plugin.h rcu: Make exit_rcu() more precise and consolidate 2016-10-29 23:12:17 +08:00
rcutorture.c PTR_ERR should be called before its argument is cleared. 2012-02-21 09:06:10 -08:00
rcutree.c rcu: Use smp_hotplug_thread facility for RCUs per-CPU kthread 2016-10-29 23:12:39 +08:00
rcutree.h rcu: Use smp_hotplug_thread facility for RCUs per-CPU kthread 2016-10-29 23:12:39 +08:00
rcutree_plugin.h rcu: Use smp_hotplug_thread facility for RCUs per-CPU kthread 2016-10-29 23:12:39 +08:00
rcutree_trace.c rcu: Use smp_hotplug_thread facility for RCUs per-CPU kthread 2016-10-29 23:12:39 +08:00
relay.c splice: fix racy pipe->buffers uses 2012-07-16 09:04:42 -07:00
res_counter.c
resource.c Merge remote-tracking branch 'stable/linux-3.4.y' into lineage-15.1 2017-12-27 17:13:15 +03:00
rtmutex-debug.c
rtmutex-debug.h rtmutex: Handle deadlock detection smarter 2014-07-17 15:39:50 -07:00
rtmutex-tester.c
rtmutex.c rtmutex: Plug slow unlock race 2014-07-17 15:39:50 -07:00
rtmutex.h rtmutex: Handle deadlock detection smarter 2014-07-17 15:39:50 -07:00
rtmutex_common.h
rwsem.c Remove all #inclusions of asm/system.h 2012-03-28 18:30:03 +01:00
seccomp.c seccomp: Replace BUG(!spin_is_locked()) with assert_spin_lock 2017-12-27 22:42:09 +03:00
semaphore.c
signal.c BACKPORT: signal: allow to send any siginfo to itself 2017-12-27 22:49:08 +03:00
smp.c Merge remote-tracking branch 'stable/linux-3.4.y' into lineage-15.1 2017-12-27 17:13:15 +03:00
smpboot.c smpboot: use kmemleak_not_leak for smpboot_thread_data 2016-10-29 23:12:40 +08:00
smpboot.h smpboot: Provide infrastructure for percpu hotplug threads 2016-10-29 23:12:39 +08:00
softirq.c Merge remote-tracking branch 'stable/linux-3.4.y' into lineage-15.1 2017-12-27 17:13:15 +03:00
spinlock.c locking/kconfig: Simplify INLINE_SPIN_UNLOCK usage 2012-03-23 13:18:57 +01:00
srcu.c rcu: Call out dangers of expedited RCU primitives 2012-02-21 09:06:08 -08:00
stacktrace.c
stop_machine.c stop_machine: Mark per cpu stopper enabled early 2016-10-29 23:12:39 +08:00
sys.c Merge remote-tracking branch 'stable/linux-3.4.y' into lineage-15.1 2017-12-27 17:13:15 +03:00
sys_ni.c seccomp: add "seccomp" syscall 2014-10-31 19:46:27 -07:00
sysctl.c fs: add link restrictions 2018-12-07 22:28:48 +04:00
sysctl_binary.c Merge remote-tracking branch 'stable/linux-3.4.y' into lineage-15.1 2017-12-27 17:13:15 +03:00
taskstats.c
test_kprobes.c
time.c jiffies: Fix timeval conversion to jiffies 2016-10-29 23:12:15 +08:00
timeconst.bc kernel: Replace timeconst.pl with a bc script 2016-10-29 23:12:15 +08:00
timer.c tick: Upstream fixes 2017-08-25 20:00:22 +03:00
tracepoint.c tracepoint: Do not waste memory on mods with no tracepoints 2014-05-18 05:25:56 -07:00
tsacct.c
uid16.c
up.c
user-return-notifier.c
user.c proc: Usable inode numbers for the namespace file descriptors. 2015-07-13 11:18:01 -07:00
user_namespace.c proc: Usable inode numbers for the namespace file descriptors. 2015-07-13 11:18:01 -07:00
utsname.c proc: Usable inode numbers for the namespace file descriptors. 2015-07-13 11:18:01 -07:00
utsname_sysctl.c
wait.c
watchdog.c kernel/watchdog.c: touch_nmi_watchdog should only touch local cpu not every one 2016-03-21 09:17:57 +08:00
workqueue.c Merge remote-tracking branch 'stable/linux-3.4.y' into lineage-15.1 2017-12-27 17:13:15 +03:00
workqueue_sched.h