From owner-freebsd-security@FreeBSD.ORG Fri Sep 28 13:24:50 2012 Return-Path: Delivered-To: freebsd-security@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 7A1441065670 for ; Fri, 28 Sep 2012 13:24:50 +0000 (UTC) (envelope-from andrey@zonov.org) Received: from mail-la0-f54.google.com (mail-la0-f54.google.com [209.85.215.54]) by mx1.freebsd.org (Postfix) with ESMTP id DBAF58FC12 for ; Fri, 28 Sep 2012 13:24:49 +0000 (UTC) Received: by lage12 with SMTP id e12so1294747lag.13 for ; Fri, 28 Sep 2012 06:24:48 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=sender:message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:x-enigmail-version:content-type :x-gm-message-state; bh=5ATV68ok1bsBYH22JsGQHR20TNP+Zj5GRKiSyJBCc4o=; b=HkpNsNbng3hWM5eCoyXX3iGc8mCO4q1ws/xQMRkHHaZzJG8Y4SThKFYloBR2BsGUrK xHOT9PMDxrXaymXVkpJqZMJIeJ23uQzoewir+xlqyFgTvnQW85T8umaJcQvhRnh/8rcO xhBkZmFyKTjaLwsIWkYl2CVMf58j6bhiI+ci+W7lQT3f52RCduplJNvXmBT6GNd502EU tvhQ68AfUJ/LlLoUF2d30LD3RXK1FGcUJQeAhOR75cxB62D6IvKQ1NY+s7r1/moQdHxB vWF7ngH2jr7m4FpXwbNCbveVcQDdQE40lataugwd0XV4idKbqGgHx036dX7uMrYiG/p3 +wOQ== Received: by 10.152.111.71 with SMTP id ig7mr5998756lab.28.1348838688425; Fri, 28 Sep 2012 06:24:48 -0700 (PDT) Received: from dhcp170-82-red.yandex.net (dhcp170-82-red.yandex.net. [95.108.170.82]) by mx.google.com with ESMTPS id tb8sm2511962lab.4.2012.09.28.06.24.47 (version=SSLv3 cipher=OTHER); Fri, 28 Sep 2012 06:24:47 -0700 (PDT) Sender: Andrey Zonov Message-ID: <5065A51B.6010905@FreeBSD.org> Date: Fri, 28 Sep 2012 17:24:43 +0400 From: Andrey Zonov User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:15.0) Gecko/20120907 Thunderbird/15.0.1 MIME-Version: 1.0 To: "Simon L. B. Nielsen" References: <50619E5D.3010503@FreeBSD.org> In-Reply-To: X-Enigmail-Version: 1.4.4 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="------------enig113F7C254FA28DBDFF7833B6" X-Gm-Message-State: ALoCoQl9BBP+jrsCf0pw1Y+yMXiA2jEmbUf+DkwdbWwv/y/doUOAishuG7KSwvD89w5PWTDfsIlV Cc: freebsd-security@freebsd.org Subject: Re: [patch] unprivileged mlock(2) X-BeenThere: freebsd-security@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Security issues \[members-only posting\]" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 28 Sep 2012 13:24:50 -0000 This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enig113F7C254FA28DBDFF7833B6 Content-Type: multipart/mixed; boundary="------------090508050401040600020903" This is a multi-part message in MIME format. --------------090508050401040600020903 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On 9/27/12 7:25 PM, Simon L. B. Nielsen wrote: > On Tue, Sep 25, 2012 at 1:06 PM, Andrey Zonov wrote:= >> Hi, >> >> Please review this patch [1] which allows unprivileged users call >> mlock()/munlock() and mlockall()/munlockall(). >> >> AFAIK, these calls were not allowed for every-one because accounting f= or >> mlockall(MCL_FUTURE) was not implemented. >=20 > I can't comment on the implementation details (don't know much about > VM system), but do you have tests to show that the new code actually > works in preventing users from mlocking more than 8MB by default? >=20 Sure, test is attached. So, lock only current memory: [zont@vm020 ~/mlock]$ limits -l 50m ./mlock 1 100 mlock: rss: 138Mb; allocated: 100Mb Lock only future memory: [zont@vm020 ~/mlock]$ limits -l 50m ./mlock 2 100 mlock: calloc(): Cannot allocate memory mlock: rss: 46Mb; allocated: 33Mb and fail at about 50Mb. Now lock current and future memory: [zont@vm020 ~/mlock]$ limits -l 50m ./mlock 3 100 mlock: calloc(): Cannot allocate memory mlock: rss: 49Mb; allocated: 33Mb and fail again. The numbers are rough because I use calloc() in test. To get more precise numbers test should be rewritten to use mmap() and/or sbrk(). --=20 Andrey Zonov --------------090508050401040600020903 Content-Type: text/plain; charset=UTF-8; x-mac-type="0"; x-mac-creator="0"; name="mlock.c" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="mlock.c" LyoKICogQ29weXJpZ2h0IChjKSAyMDEyIEFuZHJleSBab25vdgogKi8KCiNpbmNsdWRlIDxz eXMvdHlwZXMuaD4KI2luY2x1ZGUgPHN5cy90aW1lLmg+CiNpbmNsdWRlIDxzeXMvcmVzb3Vy Y2UuaD4KI2luY2x1ZGUgPHN5cy9tbWFuLmg+CiNpbmNsdWRlIDxlcnIuaD4KI2luY2x1ZGUg PHN0ZGxpYi5oPgojaW5jbHVkZSA8dW5pc3RkLmg+CgppbnQKbWFpbihpbnQgYXJnYywgY2hh ciAqKmFyZ3YpCnsKCXN0cnVjdCBydXNhZ2UgcnU7CglpbnQgZmxhZ3MsIGksIG51bTsKCglp ZiAoYXJnYyAhPSAzKQoJCWVycngoMSwKCQkgICAgInVzYWdlOiBtbG9jayA8ZmxhZ3M+IDxu dW0+XG4iCgkJICAgICJmbGFnczpcbiIKCQkgICAgIgkxID0gTUNMX0NVUlJFTlRcbiIKCQkg ICAgIgkyID0gTUNMX0ZVVFVSRVxuIgoJCSAgICAiCTMgPSBNQ0xfQ1VSUkVOVHxNQ0xfRlVU VVJFIik7CgoJZmxhZ3MgPQlhdG9pKGFyZ3ZbMV0pOwoJbnVtID0gYXRvaShhcmd2WzJdKTsK CglpZiAobWxvY2thbGwoZmxhZ3MpID09IC0xKQoJCWVycigxLCAibWxvY2thbGwoKSIpOwoJ Zm9yIChpID0gMDsgaSA8IG51bTsgaSsrKSB7CgkJaWYgKGNhbGxvYygxLCAxMDI0ICogMTAy NCkgPT0gTlVMTCkgewoJCQl3YXJuKCJjYWxsb2MoKSIpOwoJCQlnb3RvIG91dDsKCQl9Cgl9 CglpZiAobXVubG9ja2FsbCgpID09IC0xKSB7CgkJd2FybigibXVubG9ja2FsbCgpIik7CgkJ Z290byBvdXQ7Cgl9CgpvdXQ6CglnZXRydXNhZ2UoUlVTQUdFX1NFTEYsICZydSk7Cgl3YXJu eCgicnNzOiAlbGRNYjsgYWxsb2NhdGVkOiAlZE1iIiwgcnUucnVfbWF4cnNzLygxPDwxMCks IGkpOwoKCWV4aXQoMCk7Cn0K --------------090508050401040600020903-- --------------enig113F7C254FA28DBDFF7833B6 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG/MacGPG2 v2.0.18 (Darwin) Comment: GPGTools - http://gpgtools.org iQEcBAEBAgAGBQJQZaUdAAoJEBWLemxX/CvTLyUH/3Vpg5KgRzTwPHPEw9EGSAMG ju3TiZLWPM7P+ogJtL4CaFP8iTCiFzLpYX37vuv46pgYwn5hRV+8sEJWjksKBfhS FUgKKeQfBwZT1XSppuc2QPCxsvL/ToN/EIRe09TVVJao334ZQMqiBi4HbffE2iaI ZY/NVEdZInOui/FJhOi3mxpxm4nZSvut2E8KMiwusLJXakgTMTrsIt07EZiMCQxN WmT1fvJxgcRH3YS+oeEhxmJlu6r38lX5WV7UiP2nrNWvjYJuYTNT+Fz3BJP1tTZN jgmnQiICQT8fqQZIETluyHws+h6UX5Wr6DgfYC2eSUpzIRITWS1BESGmDST9Xlc= =qkma -----END PGP SIGNATURE----- --------------enig113F7C254FA28DBDFF7833B6--