Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752842AbdGEM0q (ORCPT ); Wed, 5 Jul 2017 08:26:46 -0400 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:56662 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752769AbdGEM0n (ORCPT ); Wed, 5 Jul 2017 08:26:43 -0400 Message-ID: <1499257556.2707.38.camel@decadent.org.uk> Subject: Re: [PATCH] mm: larger stack guard gap, between vmas From: Ben Hutchings To: Willy Tarreau Cc: Michal Hocko , Linus Torvalds , Hugh Dickins , Oleg Nesterov , "Jason A. Donenfeld" , Rik van Riel , Larry Woodman , "Kirill A. Shutemov" , Tony Luck , "James E.J. Bottomley" , Helge Diller , James Hogan , Laura Abbott , Greg KH , "security@kernel.org" , linux-distros@vs.openwall.org, Qualys Security Advisory , LKML , Ximin Luo Date: Wed, 05 Jul 2017 13:25:56 +0100 In-Reply-To: <20170704171102.GF22013@1wt.eu> References: <1498009101.2655.6.camel@decadent.org.uk> <20170621092419.GA22051@dhcp22.suse.cz> <1498042057.2655.8.camel@decadent.org.uk> <1499126133.2707.20.camel@decadent.org.uk> <20170704084122.GC14722@dhcp22.suse.cz> <20170704093538.GF14722@dhcp22.suse.cz> <20170704094728.GB22013@1wt.eu> <20170704104211.GG14722@dhcp22.suse.cz> <20170704113611.GA4732@decadent.org.uk> <20170704171102.GF22013@1wt.eu> Content-Type: multipart/signed; micalg="pgp-sha512"; protocol="application/pgp-signature"; boundary="=-69ypT6Ke1h+WxRqqdbGw" X-Mailer: Evolution 3.22.6-1 Mime-Version: 1.0 X-SA-Exim-Connect-IP: 2a02:8011:400e:2:6f00:88c8:c921:d332 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2759 Lines: 78 --=-69ypT6Ke1h+WxRqqdbGw Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Tue, 2017-07-04 at 19:11 +0200, Willy Tarreau wrote: > On Tue, Jul 04, 2017 at 12:36:11PM +0100, Ben Hutchings wrote: > > @@ -2323,11 +2330,17 @@ int expand_downwards(struct vm_area_struct *vma= , > > =C2=A0 if (error) > > =C2=A0 return error; > > =C2=A0 > > - /* Enforce stack_guard_gap */ > > + /* > > + =C2=A0* Enforce stack_guard_gap, but allow VM_NONE mappings in the ga= p > > + =C2=A0* as some applications try to make their own stack guards > > + =C2=A0*/ > > =C2=A0 gap_addr =3D address - stack_guard_gap; > > =C2=A0 if (gap_addr > address) > > =C2=A0 return -ENOMEM; > > - prev =3D vma->vm_prev; > > + for (prev =3D vma->vm_prev; > > + =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0prev && !(prev->vm_flags & (VM_READ | V= M_WRITE | VM_EXEC)); > > + =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0prev =3D prev->vm_prev) > > + ; > > =C2=A0 if (prev && prev->vm_end > gap_addr) { > > =C2=A0 if (!(prev->vm_flags & VM_GROWSDOWN)) > > =C2=A0 return -ENOMEM; >=20 > Hmmm shouldn't we also stop looping when we're out of the gap ? Yes, either that or only allow one such vma. Ben. > Something like this : >=20 > for (prev =3D vma->vm_prev; > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0prev && !(prev->vm_flags & (VM_READ | VM_W= RITE | VM_EXEC)) && > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0address - prev->vm_end <= stack_guard_gap; > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0prev =3D prev->vm_prev) > ; >=20 > This would limit the risk of runaway loops if someone is having fun > allocating a lot of memory in small chunks (eg: 4 GB in 1 million > independant mmap() calls). --=20 Ben Hutchings Anthony's Law of Force: Don't force it, get a larger hammer. --=-69ypT6Ke1h+WxRqqdbGw Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEErCspvTSmr92z9o8157/I7JWGEQkFAllc2tQACgkQ57/I7JWG EQkqSBAAhd//L+TC4/y4H5666aPXVYEtbN+J0cReNJtbXhcXSRJH/ORqNNbOzXxj pyTc2ci3/AzvZGg/5ibLMDn9EwBcepsGGQXubCc+jPJNgPy4HUTuUUzJsG7MPctO /u/wFz+7mWQyQXSeFESHwiOqbvQokk2ZhXKuNVIJRfkGmvnLvOXaZx5w/wWi0qfa IuLMfXbJfF+tYwZfuPk65s2HrQjIQskfF4+2QkmGoxxNUblkaa9HPmpjDTjxLeuI M5WzGjUK+8R5JzmA68LduJc72mm34M6roJW6BG/Zxsm0mRUhVpUJ8ZISlsbkXXpu ANtLcuNPxC5YF5AYoSES7gzxiIc67Y7zaGdgarNyv9Sk/+89FR706pjxk2go5Kat WWpwKiM6nexYVeIE3Dlqtr5rdmlNAcQLhLvZhrcOIazl/49k2iJZDt6p3t0pvU6+ 2nmNIfiPPjQPrHxtMCh4yaC2xT/3svzrmGbFfEKzQEUBRF+TvNtczQtQDTrdUoTw ORyx8UL/Of9q8vU1D3cLtVwbaPNjd+3v7YQcPs1jLtNrGoJov1JwQDhVSUAK0Jd6 9qZjY+B68U9XXNUmdYZDZGv4XPUUaru4UUqjWOAUAWr/2imHTGwmtGE7L144iqjl JHbVQnbA3IrFZxWjzdS89/OonKwlSRcVRezA2Bmgq5Hr/QEbcuE= =8QaR -----END PGP SIGNATURE----- --=-69ypT6Ke1h+WxRqqdbGw--