Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp1057985yba; Thu, 18 Apr 2019 14:28:25 -0700 (PDT) X-Google-Smtp-Source: APXvYqytxXXL2zIMDTczQm2khqEP3tSdAfWCYEKP++3D2Y7OyWWko7vj5+/285ocfnvWOmYBJ2Iv X-Received: by 2002:a17:902:801:: with SMTP id 1mr22077180plk.14.1555622905781; Thu, 18 Apr 2019 14:28:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555622905; cv=none; d=google.com; s=arc-20160816; b=Rmg0wy7hxRgGWjWEVlxv83nXb5ubZ1AKmzd2N3EOMqKYzkaS7lfJS1ZwfowKDP7G0X C1X8kJbGq0la9wM4QXvaqHmCcro/cbU2jLCdYVhWbUdQdJgR7REdnUVf6CEyk/e8Ptrz n5lyUS+FSt61ndkBWLhzIpyFpms+AvtcnotT5v9L5kDrNG0j7e70eLJhD1PUYO2pAN5y iKmzFb8rNgABYyAcu9dh+ATc9xlF2+Bgntto9NQxYjUAVA/HBIs3f6P1GgnhH31b6LDW RrX6iH7rn4hrNt9f+SZM4gZPbDInNaXs1ikNeCMmBvJcAG3X2Uaoo721MjWwpCANp3m6 u31g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :content-id:user-agent:content-language:accept-language:in-reply-to :references:message-id:date:thread-index:thread-topic:subject:cc:to :from:dkim-signature; bh=QTkpgF6MsdgM/3ek6kB91g2L6guOHq+ZH/z9h01KWbc=; b=JdzeDpA7IvRf4uI5ZvYDLF2HGcNFjTKcWLv9mnupJgQBJO6Q45wjUZ4FdnMkg4Z9z/ enPN8u8Whk2gohjuUwfM9uSUZ6k3VxNWPPs16VPVGNxhneN3uNYr4eNh6S6hrLKPa9Ti jqYHWOPfVsoDZXXEb00Nbxkdk/fhY2zHUxUFVMbAAjRKbXU3DgYwRb6rvK17Z4Uu+Igb qCzPr6FyrjoLu0RPFz4uwxF9oSLNMwpFyMpjvZWtf3awpDBAb9TFtgi93l7o/YipSaQY 9ZOVjOlHIbiytO46phDM8hfQF9CDl67O2ihFB1OSeiFX3ZL09xPzQKmmxcCiKZnxrVdg 1GMw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@wavesemi.onmicrosoft.com header.s=selector1-wavecomp-com header.b=ana1Xhhz; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b9si3294181pla.275.2019.04.18.14.28.09; Thu, 18 Apr 2019 14:28:25 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@wavesemi.onmicrosoft.com header.s=selector1-wavecomp-com header.b=ana1Xhhz; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389316AbfDRV1N (ORCPT + 99 others); Thu, 18 Apr 2019 17:27:13 -0400 Received: from mail-eopbgr750135.outbound.protection.outlook.com ([40.107.75.135]:3589 "EHLO NAM02-BL2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728264AbfDRV1N (ORCPT ); Thu, 18 Apr 2019 17:27:13 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wavesemi.onmicrosoft.com; s=selector1-wavecomp-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=QTkpgF6MsdgM/3ek6kB91g2L6guOHq+ZH/z9h01KWbc=; b=ana1Xhhzu7Hz0IFrEkCAwEkDkTQsgImcguCMCnydl+XhBbfTZnkqsKFlYTD3mC9abDEBGFaWFnoo0gzQy1z4Z4XyDP9M4yt/pydlX4TuEwl4JnjS8wLZRxQlmEe/mtasK7hjxzsj/Zf6pSDMY5Vkh9h26+ZvktF7WP1qoIVuTHg= Received: from MWHPR2201MB1277.namprd22.prod.outlook.com (10.174.162.17) by MWHPR2201MB1424.namprd22.prod.outlook.com (10.172.63.18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1813.12; Thu, 18 Apr 2019 21:27:08 +0000 Received: from MWHPR2201MB1277.namprd22.prod.outlook.com ([fe80::b9d6:bf19:ec58:2765]) by MWHPR2201MB1277.namprd22.prod.outlook.com ([fe80::b9d6:bf19:ec58:2765%7]) with mapi id 15.20.1813.013; Thu, 18 Apr 2019 21:27:08 +0000 From: Paul Burton To: Alexandre Ghiti CC: Andrew Morton , Christoph Hellwig , Russell King , Catalin Marinas , Will Deacon , Ralf Baechle , James Hogan , Palmer Dabbelt , Albert Ou , Alexander Viro , Luis Chamberlain , Kees Cook , "linux-kernel@vger.kernel.org" , "linux-arm-kernel@lists.infradead.org" , "linux-mips@vger.kernel.org" , "linux-riscv@lists.infradead.org" , "linux-fsdevel@vger.kernel.org" , "linux-mm@kvack.org" Subject: Re: [PATCH v3 08/11] mips: Properly account for stack randomization and stack guard gap Thread-Topic: [PATCH v3 08/11] mips: Properly account for stack randomization and stack guard gap Thread-Index: AQHU9N7WOMS/C9RNx0iyqk626UOBSKZCcS8A Date: Thu, 18 Apr 2019 21:27:08 +0000 Message-ID: <20190418212701.dpymnwuki3g7rox2@pburton-laptop> References: <20190417052247.17809-1-alex@ghiti.fr> <20190417052247.17809-9-alex@ghiti.fr> In-Reply-To: <20190417052247.17809-9-alex@ghiti.fr> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: BYAPR02CA0046.namprd02.prod.outlook.com (2603:10b6:a03:54::23) To MWHPR2201MB1277.namprd22.prod.outlook.com (2603:10b6:301:24::17) user-agent: NeoMutt/20180716 authentication-results: spf=none (sender IP is ) smtp.mailfrom=pburton@wavecomp.com; x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [67.207.99.198] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 33f5353b-dda9-4910-9587-08d6c4449c56 x-microsoft-antispam: BCL:0;PCL:0;RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600141)(711020)(4605104)(2017052603328)(7193020);SRVR:MWHPR2201MB1424; x-ms-traffictypediagnostic: MWHPR2201MB1424: x-ms-exchange-purlcount: 1 x-microsoft-antispam-prvs: x-forefront-prvs: 0011612A55 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(7916004)(39850400004)(346002)(136003)(376002)(366004)(396003)(189003)(199004)(58126008)(97736004)(6246003)(8936002)(486006)(54906003)(8676002)(81156014)(7416002)(6116002)(25786009)(3846002)(81166006)(229853002)(33716001)(2906002)(6916009)(11346002)(316002)(66556008)(66476007)(73956011)(6486002)(446003)(52116002)(1076003)(6436002)(476003)(4326008)(44832011)(6506007)(5660300002)(386003)(42882007)(14454004)(26005)(76176011)(14444005)(256004)(99286004)(53936002)(9686003)(15650500001)(6306002)(6512007)(305945005)(186003)(71190400001)(71200400001)(7736002)(478600001)(966005)(102836004)(68736007)(66066001)(66446008)(64756008)(66946007);DIR:OUT;SFP:1102;SCL:1;SRVR:MWHPR2201MB1424;H:MWHPR2201MB1277.namprd22.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; received-spf: None (protection.outlook.com: wavecomp.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: 8f4+5nWoBkDj6d1MLlkvJBbL7HDwiQVIXpbaTMbUbalRzhboOrsRxZoUH949lssGtYMTSYy3jxy5+j1nM/rKWn4tVwzvbGdScU9RVhY8wbH6pY12EcqIYEe/gTCLQxzWEmMzWSuSGX0GaUU+cLuTuwXR0hsJCvKOaupWI0YjGxfS3zmOoL82DAhFZa/t778WMCols7AhxapTvBIIQTsLvgWrfQH16GSsxKmGHr4qgowyOKg9YUK66JY/8Yil7SsqzfembPwfLkmIT/BRxLxyK8yFRlhTiLaHNIiCnc1cOfGDWG2TWZt92W+a20PnZs/3W2xUGl3T5g9sEZ6kUUQiRfw7K2sggJJ/3JydxgDKBWStRA6Jqn0RcBkNUscy7D614xZHrygsPek1twK/Igwi/u8uXfVsDQ/VNP4h4M/c07o= Content-Type: text/plain; charset="us-ascii" Content-ID: <7903A9C444F5B74FB67DD91CFCCC1456@namprd22.prod.outlook.com> Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: mips.com X-MS-Exchange-CrossTenant-Network-Message-Id: 33f5353b-dda9-4910-9587-08d6c4449c56 X-MS-Exchange-CrossTenant-originalarrivaltime: 18 Apr 2019 21:27:08.3517 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 463607d3-1db3-40a0-8a29-970c56230104 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR2201MB1424 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Alexandre, On Wed, Apr 17, 2019 at 01:22:44AM -0400, Alexandre Ghiti wrote: > This commit takes care of stack randomization and stack guard gap when > computing mmap base address and checks if the task asked for randomizatio= n. > This fixes the problem uncovered and not fixed for mips here: > https://www.mail-archive.com/linux-kernel@vger.kernel.org/msg1429066.html >=20 > Signed-off-by: Alexandre Ghiti For patches 8-10: Acked-by: Paul Burton Thanks for improving this, Paul > --- > arch/mips/mm/mmap.c | 14 ++++++++++++-- > 1 file changed, 12 insertions(+), 2 deletions(-) >=20 > diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c > index 2f616ebeb7e0..3ff82c6f7e24 100644 > --- a/arch/mips/mm/mmap.c > +++ b/arch/mips/mm/mmap.c > @@ -21,8 +21,9 @@ unsigned long shm_align_mask =3D PAGE_SIZE - 1; /* Sane= caches */ > EXPORT_SYMBOL(shm_align_mask); > =20 > /* gap between mmap and stack */ > -#define MIN_GAP (128*1024*1024UL) > -#define MAX_GAP ((TASK_SIZE)/6*5) > +#define MIN_GAP (128*1024*1024UL) > +#define MAX_GAP ((TASK_SIZE)/6*5) > +#define STACK_RND_MASK (0x7ff >> (PAGE_SHIFT - 12)) > =20 > static int mmap_is_legacy(struct rlimit *rlim_stack) > { > @@ -38,6 +39,15 @@ static int mmap_is_legacy(struct rlimit *rlim_stack) > static unsigned long mmap_base(unsigned long rnd, struct rlimit *rlim_st= ack) > { > unsigned long gap =3D rlim_stack->rlim_cur; > + unsigned long pad =3D stack_guard_gap; > + > + /* Account for stack randomization if necessary */ > + if (current->flags & PF_RANDOMIZE) > + pad +=3D (STACK_RND_MASK << PAGE_SHIFT); > + > + /* Values close to RLIM_INFINITY can overflow. */ > + if (gap + pad > gap) > + gap +=3D pad; > =20 > if (gap < MIN_GAP) > gap =3D MIN_GAP; > --=20 > 2.20.1 >=20