From nobody Sun Nov 28 02:56:12 2021 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 00D1C18B1AB4; Sun, 28 Nov 2021 02:56:12 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4J1tR01t22z3mhF; Sun, 28 Nov 2021 02:56:12 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 2165B26DDE; Sun, 28 Nov 2021 02:56:12 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 1AS2uCPh020343; Sun, 28 Nov 2021 02:56:12 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1AS2uCNe020342; Sun, 28 Nov 2021 02:56:12 GMT (envelope-from git) Date: Sun, 28 Nov 2021 02:56:12 GMT Message-Id: <202111280256.1AS2uCNe020342@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Ed Maste Subject: git: d3a7b75bbcb5 - stable/12 - Fix coredump_phnum test with ASLR enabled List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: emaste X-Git-Repository: src X-Git-Refname: refs/heads/stable/12 X-Git-Reftype: branch X-Git-Commit: d3a7b75bbcb5171d7eda9d712437efd46bb7605b Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1638068172; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=gF3OhGaXB9/ab3bVCnTM/PV96UaIFCr5b791Rr74ny0=; b=kzy+vOTyLwSelpxFJ5sX1Fw75UJYKxyApkjnXiMHljOVhSfFAxWoZIiS+XNtq/Nd1TnnyP oTqU/yMBY14ax1nMkXh8ISM8/Vg39L5OvD4FmWc/VayMOoFoah0T2iqebwzLvslZo2SFmL z/jjB/VCvV/k4mYzPX0Km/e+I/BCZ/z/8hrpyUWyGZcRxIuIDqKgBWDSf+SmoXWqMhKvx6 6wi7VvHdvCXcAOeKMWQ0c3ZSAFgI0awPw0q+hiP7QMxA4MrONTYb8BClYY4vxV93ihWg8/ hQSF5tIHt4j21EaxS0qzCbvsCqSHIgkuHqQHswZEfKkZeEu6E6YlL4xw+00Ztg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1638068172; a=rsa-sha256; cv=none; b=rE7UdHFhflI7G2joLIx7tlVrjma2mvV3yYXJ0ArgsNAYAI+keDZ77N/wAAVyDnwMGSxh+j h042iRArcQ5qmiyXLMs/jMjVJG0IIupQTg2q1lKjsWXR5Cu8f4eazZ0XXKT/lgh7DyfKet m8Lsg9tPz14SuWvie4ZelyY9VdQPoLR2RxvBzxdZ4k82RLj+2moomGt9Z7F81WrgpiUDvh fnk1g3rqv3A7a+JWvOghcQY3/TCtZPmd3T+72kfF2/IWOr95ZRH37viweSKDDEmzLaQPg/ Z1ESJ6HnsOLspbufBOoCHrcFgDgmhDtYBxe4xX+DWHX1ofjbxa+ovYSJGmnmiw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/12 has been updated by emaste: URL: https://cgit.FreeBSD.org/src/commit/?id=d3a7b75bbcb5171d7eda9d712437efd46bb7605b commit d3a7b75bbcb5171d7eda9d712437efd46bb7605b Author: Ed Maste AuthorDate: 2021-11-21 17:17:20 +0000 Commit: Ed Maste CommitDate: 2021-11-28 02:55:46 +0000 Fix coredump_phnum test with ASLR enabled coredump_phnum intends to generate a core file with many PT_LOAD segments. Previously it called mmap() in a loop with alternating protections, relying on each mapping following the previous, to produce a core file with many page-sized PT_LOAD segments. With ASLR on we no longer have this property of each mmap() following the previous. Instead, perform a single allocation, and then use mprotect() to set alternating pages to PROT_READ. PR: 259970 Reported by: lwhsu, mw Reviewed by: kib MFC after: 1 week Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D33070 (cherry picked from commit 8ec4c5dae32765701ac70811455084efd1570c32) (cherry picked from commit ee2e925603e42897fbabe1b24208d27bdcaae786) --- tests/sys/kern/coredump_phnum_helper.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/tests/sys/kern/coredump_phnum_helper.c b/tests/sys/kern/coredump_phnum_helper.c index da023e691a24..0dff59b918d9 100644 --- a/tests/sys/kern/coredump_phnum_helper.c +++ b/tests/sys/kern/coredump_phnum_helper.c @@ -42,18 +42,21 @@ int main(int argc __unused, char **argv __unused) { void *v; - unsigned i; + size_t i, pages; - for (i = 0; i < UINT16_MAX + 1000; i++) { + pages = UINT16_MAX + 1000; + v = mmap(NULL, pages * PAGE_SIZE, PROT_READ | PROT_WRITE, + MAP_ANON | MAP_PRIVATE, -1, 0); + if (v == NULL) + err(1, "mmap"); + for (i = 0; i < pages; i += 2) { /* - * Alternate protections; otherwise the kernel will just extend - * the adjacent same-protection previous mapping. + * Alternate protections to interleave RW and R PT_LOAD + * segments. */ - v = mmap(NULL, PAGE_SIZE, - (((i % 2) == 0) ? PROT_READ : 0) | PROT_WRITE, - MAP_ANON | MAP_PRIVATE, -1, 0); - if (v == MAP_FAILED) - err(1, "mmap"); + if (mprotect((char *)v + i * PAGE_SIZE, PAGE_SIZE, + PROT_READ) != 0) + err(1, "mprotect"); } /* Dump core. */