From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.71) id 1ZvrQj-0004a1-7f for mharc-grub-devel@gnu.org; Mon, 09 Nov 2015 13:44:37 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33159) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZvrQg-0004ZT-Ly for grub-devel@gnu.org; Mon, 09 Nov 2015 13:44:35 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZvrQf-000810-Gz for grub-devel@gnu.org; Mon, 09 Nov 2015 13:44:34 -0500 Received: from mail-wm0-x242.google.com ([2a00:1450:400c:c09::242]:34669) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZvrQf-00080w-AA for grub-devel@gnu.org; Mon, 09 Nov 2015 13:44:33 -0500 Received: by wmww144 with SMTP id w144so14345235wmw.1 for ; Mon, 09 Nov 2015 10:44:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=subject:to:references:cc:from:message-id:date:user-agent :mime-version:in-reply-to:content-type; bh=jdejB4AC11EhRSMs0OZ+8UqhIN/k+sKXuuVeu3QwLhE=; b=A0bUnXTH3KuGOVH+mQ0FQ4vbirutbr2hPTjlqt+eL3/9lZQNKLUV8Z3gW2p+QKr++D VKgGsEH7E4ldZ1mW3wFE1aUfTXgcFryigV9Lc8tjsIveoecmmnnRbv1+9O4TbxQ2CW6V q+uP4QN8ZhIxCkm0af30Qkzw6ilLwjmnu163KaT97x4q8f11iE+fH205+KFW8g1siepY 8cWTj87F8RTjUdFyXreJKD509Tm6CrCDoudrc0+mksgFzk4uwAzebf4nQYDPnitBey/3 +j9Jg0U7ieA75N6GzKnFcsEno5UAK/dEwhd315ryllmG+3lqI2UtSE15oQRJKzyn0+Im sbsA== X-Received: by 10.28.16.132 with SMTP id 126mr26162280wmq.86.1447094672474; Mon, 09 Nov 2015 10:44:32 -0800 (PST) Received: from ?IPv6:2620:0:105f:fd00:863a:4bff:fe50:abc4? ([2620:0:105f:fd00:863a:4bff:fe50:abc4]) by smtp.gmail.com with ESMTPSA id vr10sm16781516wjc.38.2015.11.09.10.44.30 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 09 Nov 2015 10:44:30 -0800 (PST) Subject: Re: [PATCH v2 2/6] relocator: Do not use memory region if its starta is smaller than size To: Andrei Borzenkov , The development of GNU GRUB References: <1437402954-7375-1-git-send-email-daniel.kiper@oracle.com> <1437402954-7375-3-git-send-email-daniel.kiper@oracle.com> From: =?UTF-8?Q?Vladimir_'=cf=86-coder/phcoder'_Serbinenko?= Message-ID: <5640E987.5080701@gmail.com> Date: Mon, 9 Nov 2015 19:44:23 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Icedove/38.3.0 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="7LwQjvJ6QvjR443HIpqx1xi0xORRGUwiU" X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:400c:c09::242 Cc: Juergen Gross , wei.liu2@citrix.com, keir@xen.org, Ian Campbell , Stefano Stabellini , andrew.cooper3@citrix.com, Roy Franz , "Sun, Ning" , david.vrabel@citrix.com, Jan Beulich , xen-devel@lists.xenproject.org, qiaowei.ren@intel.com, richard.l.maliszewski@intel.com, gang.wei@intel.com, Fu Wei X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: The development of GNU GRUB List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 09 Nov 2015 18:44:36 -0000 This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --7LwQjvJ6QvjR443HIpqx1xi0xORRGUwiU Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 21.07.2015 08:42, Andrei Borzenkov wrote: > On Mon, Jul 20, 2015 at 5:35 PM, Daniel Kiper = wrote: >> malloc_in_range() should not use memory region if its starta is smalle= r >> than size. Otherwise target wraps around and points to region which is= >> usually not a RAM, e.g.: >> >> loader/multiboot.c:93: segment 0: paddr=3D0x800000, memsz=3D0x3f800000= , vaddr=3D0x800000 >> lib/relocator.c:1241: min_addr =3D 0x0, max_addr =3D 0xfffffffffffffff= f, target =3D 0x800000 >> lib/relocator.c:434: trying to allocate in 0x800000-0xffffffffffffffff= aligned 0x1 size 0x3f800000 >> lib/relocator.c:434: trying to allocate in 0x0-0x800000 aligned 0x1 si= ze 0x3f800000 >> lib/relocator.c:434: trying to allocate in 0x0-0xffffffffffffffff alig= ned 0x1 size 0x3f800000 >> lib/relocator.c:1188: allocated: 0xffffffffc07fffff+0x3f800000 >> lib/relocator.c:1277: allocated 0xffffffffc07fffff/0x800000 >> >> Signed-off-by: Daniel Kiper >> --- >> grub-core/lib/relocator.c | 2 +- >> 1 file changed, 1 insertion(+), 1 deletion(-) >> >> diff --git a/grub-core/lib/relocator.c b/grub-core/lib/relocator.c >> index f759c7f..4eee0c5 100644 >> --- a/grub-core/lib/relocator.c >> +++ b/grub-core/lib/relocator.c >> @@ -748,7 +748,7 @@ malloc_in_range (struct grub_relocator *rel, >> /* Found an usable address. */ >> goto found; >> } >> - if (isinsidebefore && !isinsideafter && !from_low_priv) >> + if (isinsidebefore && !isinsideafter && !from_low_priv && star= ta >=3D size) >=20 > That's too late, we need to check end of region on previous iteration. > Consider region of 128 bytes, requested size 129 and alignment 256. > Than starta still ends up high in memory. >=20 Agreed, we need a check earlier. It makes sense to split this block with an if (from_low_priv) as both flows are completely separate and splitting them will make it more readable >> { >> target =3D starta - size; >> if (target > end - size) >> -- >> 1.7.10.4 >> >> >> _______________________________________________ >> Grub-devel mailing list >> Grub-devel@gnu.org >> https://lists.gnu.org/mailman/listinfo/grub-devel >=20 --7LwQjvJ6QvjR443HIpqx1xi0xORRGUwiU Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iF4EAREKAAYFAlZA6YcACgkQmBXlbbo5nOv8iwEAraKOj+0YXyq/95oidZvwDo5p +a3OBzkj4BnJ1dHdiPAA/jPjAVQf3Bt+B3R7z1e/7GBkPNWoMUDyFMVHC3l/9ZVI =sxdo -----END PGP SIGNATURE----- --7LwQjvJ6QvjR443HIpqx1xi0xORRGUwiU--