Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp678230imu; Fri, 11 Jan 2019 07:14:32 -0800 (PST) X-Google-Smtp-Source: ALg8bN4ZqIVtmTc7QNguSfxS6zRSQUxBsZpOl7cY1VpaCZUcClKEMI4YtaWHjwQ99UVJ3hRacsoP X-Received: by 2002:a17:902:ac1:: with SMTP id 59mr14829582plp.36.1547219672333; Fri, 11 Jan 2019 07:14:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547219672; cv=none; d=google.com; s=arc-20160816; b=hUT5/XjMHQsz3xjipiTKkdWxLocVGg0ACtpvyt9ZmdNFlV6fF4s8f7PWhX11sCHQY7 pwciSQ65TA4bZGRjFuLIfUKnMfaWea8/IsQFveuMM/HFRHzw3QFsyQIjrBmFhLUSyInU ITDUSmy1jvRr8wOk/E+PbvqXNeRRO0/3UbV6MoO+aaCvlxtCCJP7/y23293z1o59uw9W ku3jbooBN+jhl/YvZEaAZlVpFLN7LRF9KMONF6TuqGDIzWyiQbED3YwpcsNEsMnoyaRb uokNAnn/r0lWxDKA5AJrHAagcXAl/xcam5hq/bFNJrJYOvD6QI/vG7+f/XV+voh1CQ3E A2BQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Vhq2/Qk8nfFCvKz5OG/G1ZxCuC/df3liTryxlcDYixo=; b=ZOhWNfHn6pUwdW7E0LlHev7HCVbrsB2sJqVlNeAj80AplIag+wBFeHWX+NYXKSufCo KNy53b6t8H3c3rRy2bcmsLnjzVU/69XSLAJOg5CCPSsTvLoVRsHXorylJhW8v0H4FIrV dUOkWNigI4xTeyqHblxM+Zu1a8ibb9YWwv84FcT9ZpIZhLikRLyG5vJO8ZkXtaYIMu7T IThRWP/YP8FzARqn6THLc0pgAZcrZ3NQ7yBOiQXrZLPz444SAJObBuY6WAUmRcOyfCEZ UHO6F48LO9gN4ZkvAxPsL1aDe/0uQkR5IKc467BNGdW7566h/RWjWnUvRSzH5JAdVf9q FzuA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=mATZm+CU; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m75si467760pga.432.2019.01.11.07.14.17; Fri, 11 Jan 2019 07:14:32 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=mATZm+CU; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387409AbfAKOPb (ORCPT + 99 others); Fri, 11 Jan 2019 09:15:31 -0500 Received: from mail.kernel.org ([198.145.29.99]:59656 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387394AbfAKOPa (ORCPT ); Fri, 11 Jan 2019 09:15:30 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 76356214D8; Fri, 11 Jan 2019 14:15:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1547216128; bh=sAeZmfbFrisJPBcsaz9trwd91j/Fm7L1a5Xm+ilOvbg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mATZm+CUY1u4RcM1kYGdJ7e3OV6SZutK9AKW214/9JSVwQl2ix6lqcrT0eTti2swC iY/v9IROpYXMvIIom1vORPql8jlYrhZQWjq8CFTh20NqwmoVMt9UZ2F85R+Z0RBaVm axoyrvd7mZuBdfYvsMVyQShVAZTx9YVZ4busI21c= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jann Horn , Tom Gundersen , David Herrmann , Linus Torvalds Subject: [PATCH 3.18 32/47] fork: record start_time late Date: Fri, 11 Jan 2019 15:08:17 +0100 Message-Id: <20190111131000.231010024@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190111130956.170952125@linuxfoundation.org> References: <20190111130956.170952125@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: David Herrmann commit 7b55851367136b1efd84d98fea81ba57a98304cf 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 Signed-off-by: Tom Gundersen Signed-off-by: David Herrmann Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- kernel/fork.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) --- a/kernel/fork.c +++ b/kernel/fork.c @@ -1321,8 +1321,6 @@ static struct task_struct *copy_process( posix_cpu_timers_init(p); - p->start_time = ktime_get_ns(); - p->real_start_time = ktime_get_boot_ns(); p->io_context = NULL; p->audit_context = NULL; if (clone_flags & CLONE_THREAD) @@ -1487,6 +1485,17 @@ static struct task_struct *copy_process( spin_lock(¤t->sighand->siglock); /* + * From this point on we must avoid any synchronous user-space + * communication until we take the tasklist-lock. In particular, we do + * not want user-space to be able to predict the process start-time by + * stalling fork(2) after we recorded the start_time but before it is + * visible to the system. + */ + + p->start_time = ktime_get_ns(); + p->real_start_time = ktime_get_boot_ns(); + + /* * Copy seccomp details explicitly here, in case they were changed * before holding sighand lock. */