Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 11 Aug 2012 21:45:23 +0300
From:      Konstantin Belousov <kostikbel@gmail.com>
To:        Dan Plassche <dplassche@gmail.com>
Cc:        freebsd-hackers@freebsd.org
Subject:   Re: FreeBSD 1.x Binaries Work Except under Chroot
Message-ID:  <20120811184522.GK2425@deviant.kiev.zoral.com.ua>
In-Reply-To: <CAOD8Yqpz89-bxN7vpsyNWisr7eMDjcbvTSfknvG6M_jZFOW-yQ@mail.gmail.com>
References:  <CAOD8YqpVzT0pdBCHaMcu2krpjHcP3eotyDtiBR7OzUK1E9Hi5g@mail.gmail.com> <20120810170715.GI2425@deviant.kiev.zoral.com.ua> <CAOD8Yqpz89-bxN7vpsyNWisr7eMDjcbvTSfknvG6M_jZFOW-yQ@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help

--9a9Vq1BJdYBEXpLG
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

Why did you stripped the public list from the Cc: ?

On Fri, Aug 10, 2012 at 05:05:09PM -0400, Dan Plassche wrote:
> On Fri, Aug 10, 2012 at 1:07 PM, Konstantin Belousov
> <kostikbel@gmail.com> wrote:
>=20
> > Try to ktrace the binaries to see what is going on. I suspect that
> > sources for 1.1.5 are not in our cvs/svn, so it is troublesome to
> > say anuthing without ktrace dump.
>=20
> Ok, below is the kdump from running basename as a simple example
> that produces the "ld.so: whereis: libc.so.1.1" error under a
> chrooted environment.
>=20
> I probably should have mentioned that I'm running these with
> "sysctl security.bsd.map_at_zero=3D1" set.  The static binaries
> in /bin and /sbin also work under the chroot, but the others in
> /usr/bin and /usr/sbin fail with the ld.so error.
You should have mentioned that it is only _some_ binaries which are
affected, since I was not able to reproduce your issue at all with
/bin/sh or /bin/ls in chroot. It took me a while to realize that you
specifically shown the trace for basename.

>=20
> Here's the kdump:
>   1144 basename CALL
> compat.mmap(0x2006b000,0x6bb8,0x7,0x122,0xffffffff,0x4d000)
>   1144 basename RET   compat.mmap -1 errno 22 Invalid argument
And there is the problem, induced by more strict check added in r205536.
Try the patch below, it could be applicable to 8.2 still. It worked for
me on HEAD.

diff --git a/sys/vm/vm_mmap.c b/sys/vm/vm_mmap.c
index 3fccd9e..e89d586 100644
--- a/sys/vm/vm_mmap.c
+++ b/sys/vm/vm_mmap.c
@@ -207,11 +207,24 @@ sys_mmap(td, uap)
=20
 	fp =3D NULL;
=20
-	/* Make sure mapping fits into numeric range, etc. */
-	if ((uap->len =3D=3D 0 && !SV_CURPROC_FLAG(SV_AOUT) &&
-	     curproc->p_osrel >=3D P_OSREL_MAP_ANON) ||
-	    ((flags & MAP_ANON) && (uap->fd !=3D -1 || pos !=3D 0)))
-		return (EINVAL);
+	/*
+	 * Enforce the constraints.
+	 * Mapping of length 0 allowed for old binaries.
+	 *
+	 * Anonymous mapping shall specify -1 as filedescriptor and
+	 * zero position for new code. Be nice to ancient a.out
+	 * binaries and correct pos for anonymous mapping, since old
+	 * ld.so sometimes issues anonymous map requests with non-zero
+	 * pos.
+	 */
+	if (!SV_CURPROC_FLAG(SV_AOUT)) {
+		if ((uap->len =3D=3D 0 && curproc->p_osrel >=3D P_OSREL_MAP_ANON) ||
+		    ((flags & MAP_ANON) !=3D 0 && (uap->fd !=3D -1 || pos !=3D 0)))
+			return (EINVAL);
+	} else {
+		if ((flags & MAP_ANON) !=3D 0)
+			pos =3D 0;
+	}
=20
 	if (flags & MAP_STACK) {
 		if ((uap->fd !=3D -1) ||

--9a9Vq1BJdYBEXpLG
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (FreeBSD)

iEYEARECAAYFAlAmqEIACgkQC3+MBN1Mb4i2hACgrcmc3VuTWvy54u+rHNlz3O6W
ZOUAnRiKMPAMlhGABKtEWp0avYZo+fUl
=mq/V
-----END PGP SIGNATURE-----

--9a9Vq1BJdYBEXpLG--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20120811184522.GK2425>