Skip to content

Commit 6d655b4

Browse files
David HerrmannBrian Maly
authored andcommitted
fork: record start_time late
commit 7b55851 upstream. This changes the fork(2) syscall to record the process start_time after initializing the basic task structure but still before making the new process visible to user-space. Technically, we could record the start_time anytime during fork(2). But this might lead to scenarios where a start_time is recorded long before a process becomes visible to user-space. For instance, with userfaultfd(2) and TLS, user-space can delay the execution of fork(2) for an indefinite amount of time (and will, if this causes network access, or similar). By recording the start_time late, it much closer reflects the point in time where the process becomes live and can be observed by other processes. Lastly, this makes it much harder for user-space to predict and control the start_time they get assigned. Previously, user-space could fork a process and stall it in copy_thread_tls() before its pid is allocated, but after its start_time is recorded. This can be misused to later-on cycle through PIDs and resume the stalled fork(2) yielding a process that has the same pid and start_time as a process that existed before. This can be used to circumvent security systems that identify processes by their pid+start_time combination. Even though user-space was always aware that start_time recording is flaky (but several projects are known to still rely on start_time-based identification), changing the start_time to be recorded late will help mitigate existing attacks and make it much harder for user-space to control the start_time a process gets assigned. Reported-by: Jann Horn <[email protected]> Signed-off-by: Tom Gundersen <[email protected]> Signed-off-by: David Herrmann <[email protected]> Signed-off-by: Linus Torvalds <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]> (cherry picked from commit 3f2e4e1) Orabug: 29850581 CVE: CVE-2019-6133 Signed-off-by: John Donnelly <[email protected]> Reviewed-by: Jack Vogel <[email protected]> Signed-off-by: Brian Maly <[email protected]>
1 parent a676a20 commit 6d655b4

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

kernel/fork.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1382,8 +1382,6 @@ static struct task_struct *copy_process(unsigned long clone_flags,
13821382

13831383
posix_cpu_timers_init(p);
13841384

1385-
p->start_time = ktime_get_ns();
1386-
p->real_start_time = ktime_get_boot_ns();
13871385
p->io_context = NULL;
13881386
p->audit_context = NULL;
13891387
if (clone_flags & CLONE_THREAD)
@@ -1538,6 +1536,17 @@ static struct task_struct *copy_process(unsigned long clone_flags,
15381536
INIT_LIST_HEAD(&p->thread_group);
15391537
p->task_works = NULL;
15401538

1539+
/*
1540+
* From this point on we must avoid any synchronous user-space
1541+
* communication until we take the tasklist-lock. In particular, we do
1542+
* not want user-space to be able to predict the process start-time by
1543+
* stalling fork(2) after we recorded the start_time but before it is
1544+
* visible to the system.
1545+
*/
1546+
1547+
p->start_time = ktime_get_ns();
1548+
p->real_start_time = ktime_get_boot_ns();
1549+
15411550
/*
15421551
* Make it visible to the rest of the system, but dont wake it up yet.
15431552
* Need tasklist lock for parent etc handling!

0 commit comments

Comments
 (0)