From owner-freebsd-current@FreeBSD.ORG Sat Mar 21 01:57:29 2015 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 6149D975; Sat, 21 Mar 2015 01:57:29 +0000 (UTC) Received: from mail-wi0-x229.google.com (mail-wi0-x229.google.com [IPv6:2a00:1450:400c:c05::229]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id E1972DCB; Sat, 21 Mar 2015 01:57:28 +0000 (UTC) Received: by wibgn9 with SMTP id gn9so3146867wib.1; Fri, 20 Mar 2015 18:57:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:to:cc:subject:message-id:mail-followup-to:references :mime-version:content-type:content-disposition:in-reply-to :user-agent; bh=f+3VWkTfmbk3x1pUjcigGd9gibZPkNqsWQp8nmMXOuU=; b=JFLVqq12bd7MSMiJeZku4tVo34dYyCONt7/YZHntpOCYkWrNL/TW0SsGi7A2oLl2At zhOQdP2jaZ1fvb5z3pStygbbms7EqXsAY9z9/ZRJPdqPJhwZDGyDS4Ao8CsyW++9XcvZ 14XWZAct6FK5ueJh3Pkew420q9SbGM1iC6YhVJOJTdVhmwibhUAxgC7wip79D2m92ozR n6qYad3iFctEfLl2PWLIkjFVa3c0juuKO8IQavR7r/qB7P35v4rmAi9Dqa7M0QjBgCee 2zHMTEiFQ/TyHGdD0XrP18MGms9ZaWVUeAcFKe7tBL0DcVlgt2xdOWZEJZmZGl3Pm3lD yMmg== X-Received: by 10.194.76.69 with SMTP id i5mr25704844wjw.3.1426903046476; Fri, 20 Mar 2015 18:57:26 -0700 (PDT) Received: from dft-labs.eu (n1x0n-1-pt.tunnel.tserv5.lon1.ipv6.he.net. [2001:470:1f08:1f7::2]) by mx.google.com with ESMTPSA id hl15sm508214wib.3.2015.03.20.18.57.24 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Fri, 20 Mar 2015 18:57:25 -0700 (PDT) Date: Sat, 21 Mar 2015 02:57:22 +0100 From: Mateusz Guzik To: Konstantin Belousov Subject: Re: [PATCH 1/3] fork: assign refed credentials earlier Message-ID: <20150321015722.GC27736@dft-labs.eu> Mail-Followup-To: Mateusz Guzik , Konstantin Belousov , jenkins-admin@freebsd.org, freebsd-current@freebsd.org, Mateusz Guzik References: <20150320122125.GP2379@kib.kiev.ua> <1426899640-6599-1-git-send-email-mjguzik@gmail.com> <1426899640-6599-2-git-send-email-mjguzik@gmail.com> <20150321015151.GF2379@kib.kiev.ua> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20150321015151.GF2379@kib.kiev.ua> User-Agent: Mutt/1.5.21 (2010-09-15) Cc: freebsd-current@freebsd.org, jenkins-admin@freebsd.org, Mateusz Guzik X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 21 Mar 2015 01:57:29 -0000 On Sat, Mar 21, 2015 at 03:51:51AM +0200, Konstantin Belousov wrote: > On Sat, Mar 21, 2015 at 02:00:38AM +0100, Mateusz Guzik wrote: > > From: Mateusz Guzik > > > > Prior to this change the kernel would take p1's credentials and assign > > them tempororarily to p2. But p1 could change credentials at that time > > and in effect give us a use-after-free. > In which way could it change the credentials ? The assigned credentials > are taken from td_ucred, which, I thought, are guaranteed to be stable > for the duration of a syscall. > It takes thread's credential in do_fork. But initial copy is taken unlocked from struct proc. Relevant part of the diff: > > @@ -870,7 +867,7 @@ fork1(struct thread *td, int flags, int pages, struct proc **procp, > > * XXX: This is ugly; when we copy resource usage, we need to bump > > * per-cred resource counters. > > */ > > - proc_set_cred(newproc, p1->p_ucred); > > + proc_set_cred(newproc, crhold(td->td_ucred)); > > -- Mateusz Guzik