From owner-freebsd-hackers@FreeBSD.ORG Sun Nov 6 18:10:49 2011 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 9B57C106564A; Sun, 6 Nov 2011 18:10:49 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from mail.zoral.com.ua (mx0.zoral.com.ua [91.193.166.200]) by mx1.freebsd.org (Postfix) with ESMTP id 362468FC08; Sun, 6 Nov 2011 18:10:44 +0000 (UTC) Received: from alf.home (alf.kiev.zoral.com.ua [10.1.1.177]) by mail.zoral.com.ua (8.14.2/8.14.2) with ESMTP id pA6IAfHO040588 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Sun, 6 Nov 2011 20:10:41 +0200 (EET) (envelope-from kostikbel@gmail.com) Received: from alf.home (kostik@localhost [127.0.0.1]) by alf.home (8.14.5/8.14.5) with ESMTP id pA6IAfo9056094; Sun, 6 Nov 2011 20:10:41 +0200 (EET) (envelope-from kostikbel@gmail.com) Received: (from kostik@localhost) by alf.home (8.14.5/8.14.5/Submit) id pA6IAfAF056093; Sun, 6 Nov 2011 20:10:41 +0200 (EET) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: alf.home: kostik set sender to kostikbel@gmail.com using -f Date: Sun, 6 Nov 2011 20:10:41 +0200 From: Kostik Belousov To: Mikolaj Golub Message-ID: <20111106181041.GH50300@deviant.kiev.zoral.com.ua> References: <20111025082451.GO50300@deviant.kiev.zoral.com.ua> <86aa8k2im0.fsf@kopusha.home.net> <20111031094948.GB50300@deviant.kiev.zoral.com.ua> <86vcr21agm.fsf@kopusha.home.net> <20111105135801.GT50300@deviant.kiev.zoral.com.ua> <86ehxmpogp.fsf@kopusha.home.net> <20111105154443.GB50300@deviant.kiev.zoral.com.ua> <86ehxmjsza.fsf@kopusha.home.net> <20111105194553.GK50300@deviant.kiev.zoral.com.ua> <8662iyjof9.fsf@kopusha.home.net> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="Y9J5124L7u056RQu" Content-Disposition: inline In-Reply-To: <8662iyjof9.fsf@kopusha.home.net> User-Agent: Mutt/1.4.2.3i X-Virus-Scanned: clamav-milter 0.95.2 at skuns.kiev.zoral.com.ua X-Virus-Status: Clean X-Spam-Status: No, score=-3.9 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00 autolearn=ham version=3.2.5 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on skuns.kiev.zoral.com.ua Cc: freebsd-hackers@freebsd.org, Robert Watson Subject: Re: "ps -e" without procfs(5) X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 06 Nov 2011 18:10:49 -0000 --Y9J5124L7u056RQu Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sat, Nov 05, 2011 at 10:37:46PM +0200, Mikolaj Golub wrote: >=20 > On Sat, 5 Nov 2011 21:45:53 +0200 Kostik Belousov wrote: >=20 > KB> On Sat, Nov 05, 2011 at 08:59:21PM +0200, Mikolaj Golub wrote: > >>=20 > >> On Sat, 5 Nov 2011 17:44:43 +0200 Kostik Belousov wrote: > >>=20 > >> >> KB> I think that the aux vector must be naturally aligned. You c= an return > >> >> KB> ENOEXEC early if vptr is not aligned. > >> >>=20 > >> >> Not sure I see what you mean. vptr for auxv is calculated just co= uple lines > >> >> above, and I check the result here, in the part common for all ve= ctor types. > >> KB> You do not check for the alignment. Am I wrong ? > >>=20 > >> I see now. If natural alignment means "addr % sizeof(aux) =3D=3D 0" t= hen the aux > >> vectors are not naturally aligned. After adding this check: > >>=20 > >> if (vptr % sizeof(aux) !=3D 0) > >> return (ENOEXEC); > KB> No, the natural alignment of the structure is the alignment of the m= ost > KB> demanding member. So it is 4 bytes on 32bit, and 8 bytes on 64. >=20 > >>=20 > >> I started to observe many ENOEXEC errors. Adding printf showed that t= he > >> vectors are half size aligned. > >>=20 > >> On i386: > >>=20 > >> get_proc_vector(pid =3D getty[3442], type =3D 2): vptr (2143284876) %= sizeof(aux) (8) =3D 4) > >>=20 > >> On amd64: > >>=20 > >> get_proc_vector(pid =3D getty[2425], type =3D 2): vptr (1407374883465= 68) % sizeof(aux) (16) =3D 8) > >>=20 > >> Looking at exec_copyout_strings() from kern_exec.c, how destp is calc= ulated, I > >> think they are sizeof(char *) aligned. > >>=20 > >> Do you think it is worth adding the check for sizeof(char *) alignmen= t? > >>=20 > >> if (vptr % (sizeof(char *) !=3D 0) > >> return (ENOEXEC); > KB> I suggest to use #if __ELF_WORD_SIZE =3D=3D 32 or 64. >=20 > Thanks. The updated patch: >=20 > http://people.freebsd.org/~trociny/env.sys.3.patch Oops, I missed this in the previous review. You cannot use fubyte in proc_read_mem(). fubyte reads a byte from the address space of the current process. The fix is easy, use proc_rwmem for 1 byte. I do not think that fall back to single byte read is warranted for proc_read_mem calls e.g. for ps_strings. Add a flag to indicate whether the proc_read_mem should fall back to byte read ? I would prefer using sizeof(uint64_t) and sizeof(uint32_t) instead of 8 and 4 constants in the align checks. Might be, add PROC_ASSERT_HELD() to get_ps_string() ? procfs patch looks good. --Y9J5124L7u056RQu Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.18 (FreeBSD) iEYEARECAAYFAk62zaEACgkQC3+MBN1Mb4icCACeJcDhyPfaGTk7frkifRXO5mUE nYYAoMf82kNB6RVH1dmMK+DRmmYTcehs =wxV9 -----END PGP SIGNATURE----- --Y9J5124L7u056RQu--