From owner-svn-src-head@freebsd.org Wed Mar 15 13:06:47 2017 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id B739ED0C962; Wed, 15 Mar 2017 13:06:47 +0000 (UTC) (envelope-from alc@rice.edu) Received: from pp2.rice.edu (proofpoint2.mail.rice.edu [128.42.201.101]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 966F41BE6; Wed, 15 Mar 2017 13:06:46 +0000 (UTC) (envelope-from alc@rice.edu) Received: from pps.filterd (pp2.rice.edu [127.0.0.1]) by pp2.rice.edu (8.16.0.17/8.16.0.17) with SMTP id v2FA1wlF032162; Wed, 15 Mar 2017 08:06:39 -0500 Received: from mh2.mail.rice.edu (mh2.mail.rice.edu [128.42.201.21]) by pp2.rice.edu with ESMTP id 296nkjgawa-1; Wed, 15 Mar 2017 08:06:39 -0500 X-Virus-Scanned: by amavis-2.7.0 at mh2.mail.rice.edu, auth channel Received: from 108-254-203-201.lightspeed.hstntx.sbcglobal.net (108-254-203-201.lightspeed.hstntx.sbcglobal.net [108.254.203.201]) (using TLSv1 with cipher RC4-MD5 (128/128 bits)) (No client certificate requested) (Authenticated sender: alc) by mh2.mail.rice.edu (Postfix) with ESMTPSA id 2827C500093; Wed, 15 Mar 2017 08:06:39 -0500 (CDT) Subject: Re: svn commit: r315272 - in head: lib/libc/sys sys/sys sys/vm To: Xin LI , src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org References: <201703141710.v2EHAgxB047599@repo.freebsd.org> From: Alan Cox Message-ID: <1a83c3e4-e46f-440f-12a4-9120406a3f74@rice.edu> Date: Wed, 15 Mar 2017 08:06:38 -0500 User-Agent: Mozilla/5.0 (X11; FreeBSD i386; rv:45.0) Gecko/20100101 Thunderbird/45.5.1 MIME-Version: 1.0 In-Reply-To: <201703141710.v2EHAgxB047599@repo.freebsd.org> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 suspectscore=10 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1609300000 definitions=main-1611190142 X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 15 Mar 2017 13:06:47 -0000 On 03/14/2017 12:10, Xin LI wrote: > Author: delphij > Date: Tue Mar 14 17:10:42 2017 > New Revision: 315272 > URL: https://svnweb.freebsd.org/changeset/base/315272 > > Log: > Implement INHERIT_ZERO for minherit(2). > =20 > INHERIT_ZERO is an OpenBSD feature. > =20 > When a page is marked as such, it would be zeroed > upon fork(). > =20 > This would be used in new arc4random(3) functions. > =20 > PR: 182610 > Reviewed by: kib (earlier version) > MFC after: 1 month > Differential Revision: https://reviews.freebsd.org/D427 > > Modified: > head/lib/libc/sys/minherit.2 > head/sys/sys/mman.h > head/sys/vm/vm.h > head/sys/vm/vm_map.c > > Modified: head/lib/libc/sys/minherit.2 > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D > --- head/lib/libc/sys/minherit.2 Tue Mar 14 16:40:18 2017 (r315271) > +++ head/lib/libc/sys/minherit.2 Tue Mar 14 17:10:42 2017 (r315272) > @@ -29,7 +29,7 @@ > .\" > .\" @(#)minherit.2 8.1 (Berkeley) 6/9/93 > .\" > -.Dd October 30, 2007 > +.Dd March 15, 2017 > .Dt MINHERIT 2 > .Os > .Sh NAME > @@ -91,6 +91,11 @@ it will no longer be shared in the paren > after the parent forks and there is no way to get the previous > shared-backing-store mapping without unmapping and remapping the addre= ss > space in the parent. > +.It Dv INHERIT_ZERO > +This option causes the address space in question to be mapped as new > +anonymous pages, > +which would be initialized to all zero bytes, > +in the child process. > .El > .Sh RETURN VALUES > .Rv -std minherit > @@ -130,6 +135,13 @@ system call first appeared in > .Ox > and then in > .Fx 2.2 . > +.Pp > +The > +.Dv INHERIT_ZERO > +support first appeared in > +.Ox 5.6 > +and then in > +.Fx 12.0 . > .Sh BUGS > Once you set inheritance to > .Dv MAP_PRIVATE > > Modified: head/sys/sys/mman.h > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D > --- head/sys/sys/mman.h Tue Mar 14 16:40:18 2017 (r315271) > +++ head/sys/sys/mman.h Tue Mar 14 17:10:42 2017 (r315272) > @@ -43,6 +43,7 @@ > #define INHERIT_SHARE 0 > #define INHERIT_COPY 1 > #define INHERIT_NONE 2 > +#define INHERIT_ZERO 3 > #endif > =20 > /* > > Modified: head/sys/vm/vm.h > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D > --- head/sys/vm/vm.h Tue Mar 14 16:40:18 2017 (r315271) > +++ head/sys/vm/vm.h Tue Mar 14 17:10:42 2017 (r315272) > @@ -68,6 +68,7 @@ typedef char vm_inherit_t; /* inheritanc > #define VM_INHERIT_SHARE ((vm_inherit_t) 0) > #define VM_INHERIT_COPY ((vm_inherit_t) 1) > #define VM_INHERIT_NONE ((vm_inherit_t) 2) > +#define VM_INHERIT_ZERO ((vm_inherit_t) 3) > #define VM_INHERIT_DEFAULT VM_INHERIT_COPY > =20 > typedef u_char vm_prot_t; /* protection codes */ > > Modified: head/sys/vm/vm_map.c > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D > --- head/sys/vm/vm_map.c Tue Mar 14 16:40:18 2017 (r315271) > +++ head/sys/vm/vm_map.c Tue Mar 14 17:10:42 2017 (r315272) > @@ -2285,6 +2285,7 @@ vm_map_inherit(vm_map_t map, vm_offset_t > case VM_INHERIT_NONE: > case VM_INHERIT_COPY: > case VM_INHERIT_SHARE: > + case VM_INHERIT_ZERO: > break; > default: > return (KERN_INVALID_ARGUMENT); > @@ -3443,6 +3444,36 @@ vmspace_fork(struct vmspace *vm1, vm_oof > vm_map_copy_entry(old_map, new_map, old_entry, > new_entry, fork_charge); > break; > + > + case VM_INHERIT_ZERO: > + /* > + * Create a new anonymous mapping entry modelled from > + * the old one. > + */ > + new_entry =3D vm_map_entry_create(new_map); > + memset(new_entry, 0, sizeof(*new_entry)); > + > + new_entry->start =3D old_entry->start; > + new_entry->end =3D old_entry->end; > + new_entry->avail_ssize =3D old_entry->avail_ssize; > + new_entry->adj_free =3D old_entry->adj_free; > + new_entry->max_free =3D old_entry->max_free; The previous two fields should not be copied. The values from the old entry are not necessarily correct for the new entry. The correct values are calculated and assigned by the call to vm_map_entry_link() below.=20 So, these two assignments are harmless but also pointless. > + new_entry->eflags =3D old_entry->eflags & > + ~(MAP_ENTRY_USER_WIRED | MAP_ENTRY_IN_TRANSITION | > + MAP_ENTRY_VN_WRITECNT); > + new_entry->protection =3D old_entry->protection; > + new_entry->max_protection =3D old_entry->max_protection; > + new_entry->inheritance =3D VM_INHERIT_ZERO; > + > + vm_map_entry_link(new_map, new_map->header.prev, > + new_entry); > + vmspace_map_entry_forked(vm1, vm2, new_entry); > + > + new_entry->cred =3D curthread->td_ucred; > + crhold(new_entry->cred); > + *fork_charge +=3D (new_entry->end - new_entry->start); > + > + break; > } > old_entry =3D old_entry->next; > } > >