From nobody Tue May 30 23:37:48 2023 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 4QW82j35vDz4YLrt; Tue, 30 May 2023 23:37:49 +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 4QW82j13dhz3j4J; Tue, 30 May 2023 23:37:49 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1685489869; 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=Td7Sq1VOaR766zt1N9dJ1Nb/T3lpMJL338TpoC0IQYE=; b=wZXDWA8pKkodnaDAhHMUZqSm6y8f9SANbkHx+3q5wAVsSvKydBy0qvkibACwd4gu5+GA2i HfQnphWrNehUc+8TW0AfZMWNIylWUFhmR+sI3/luK5VqZZfuZbPQZ5Jeyu4Z2mbDCncwqM Kke27g1/rKcn9E05nTvD0Wq/VAy59xLV8Z8NjO8QML8kyHSLd9h58TZl3K0nKa6B6lp21g A0Qg1+O0Hq3St265iWu66ZJhyghc5IWJp4kZzYlwcoo+3qOYeSjFOuIZHJAjUis8PPFOcN C0blk9Sy3uKeTXM6Uqr3xGUXdccjER1WlV3r6imlsOULC0euJaSsuWK+/8eEcQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1685489869; 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=Td7Sq1VOaR766zt1N9dJ1Nb/T3lpMJL338TpoC0IQYE=; b=mTbJH7yb6FIf8wNTAtU5+FwqYBnwK88yXYBxUC9gwa70ZiSK0gcdRDw/9IW/e00jFIALHm BcWOoZ66A4hVb58u3XKolo67cIqW5Gn+PN179xSizBO064gWqVGd9vqFLHUGUhMmlW237c sTt0o3I4Cc54lgCqlfy4lWCiMOr8jPPYvh+HX4NevXeLPcd9NTRBWTHMTdOb8xDutf5ZcG k2ErHLyVRzzublBLGEKt/x67mAxJIG3aBVL2CSXPg9r0y7xRZYszolM0851Riym6ltIJSj Pk0lnzmo/snPFIfSZUxCPQyeE/udN7iDpsJ5CVCMfDSA9TyLBWvHkOJeZYWi3A== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1685489869; a=rsa-sha256; cv=none; b=ceppN+EF4DzW5QIYjSijHoH+6dlBnaAYyb3BjiPxhu7WpOP1mpZrckrNujjCBP8n1v9EvU xiPKaGT64+0EHEWBYp2974XTXqQO6EpajSpU40Jhqw4rWYoQiqGt8Sp6TIc7oQxJCx7Dus /5+++0c8WhDs1nUmWAx4MxLt8geMwliOkfSwjwwpJh1w2kZ+5d/MQsenGXpRYtGcIswHZ4 8K5JmBGun+B3N9hMA6WhKv2XruphsbtnkhM5EDgddq8KwmF5XUAoJMf9pRZ1EG2ntF0WxP lsQiIbhHP9EZSPMUARJORCpCztuADXa55fVV/hymFkSEAni1Qu/wDn3O9dezFw== 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 4QW82j040sz1CZT; Tue, 30 May 2023 23:37:49 +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 34UNbmbj056879; Tue, 30 May 2023 23:37:48 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 34UNbmV2056878; Tue, 30 May 2023 23:37:48 GMT (envelope-from git) Date: Tue, 30 May 2023 23:37:48 GMT Message-Id: <202305302337.34UNbmV2056878@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Jessica Clarke Subject: git: 659a0041dd06 - main - imgact: Make et_dyn_addr part of image_params 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: jrtc27 X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 659a0041dd06355704f1bce0c5d7cbcb0b32c0a4 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by jrtc27: URL: https://cgit.FreeBSD.org/src/commit/?id=659a0041dd06355704f1bce0c5d7cbcb0b32c0a4 commit 659a0041dd06355704f1bce0c5d7cbcb0b32c0a4 Author: Jessica Clarke AuthorDate: 2023-05-30 23:15:43 +0000 Commit: Jessica Clarke CommitDate: 2023-05-30 23:15:43 +0000 imgact: Make et_dyn_addr part of image_params This already gets passed around between various imgact_elf functions, so moving it removes an argument from all those places. A future commit will make use of this for hwpmc, though, to provide the load base for PIEs, which currently isn't available to tools like pmcstat. Reviewed by: kib, markj, jhb Differential Revision: https://reviews.freebsd.org/D39594 --- sys/kern/imgact_elf.c | 35 +++++++++++++++++------------------ sys/sys/imgact.h | 1 + 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/sys/kern/imgact_elf.c b/sys/kern/imgact_elf.c index e81810c33b33..35975af565fc 100644 --- a/sys/kern/imgact_elf.c +++ b/sys/kern/imgact_elf.c @@ -924,7 +924,7 @@ __CONCAT(rnd_, __elfN(base))(vm_map_t map, u_long minv, u_long maxv, static int __elfN(enforce_limits)(struct image_params *imgp, const Elf_Ehdr *hdr, - const Elf_Phdr *phdr, u_long et_dyn_addr) + const Elf_Phdr *phdr) { struct vmspace *vmspace; const char *err_str; @@ -939,9 +939,9 @@ __elfN(enforce_limits)(struct image_params *imgp, const Elf_Ehdr *hdr, if (phdr[i].p_type != PT_LOAD || phdr[i].p_memsz == 0) continue; - seg_addr = trunc_page(phdr[i].p_vaddr + et_dyn_addr); + seg_addr = trunc_page(phdr[i].p_vaddr + imgp->et_dyn_addr); seg_size = round_page(phdr[i].p_memsz + - phdr[i].p_vaddr + et_dyn_addr - seg_addr); + phdr[i].p_vaddr + imgp->et_dyn_addr - seg_addr); /* * Make the largest executable segment the official @@ -1106,7 +1106,7 @@ __CONCAT(exec_, __elfN(imgact))(struct image_params *imgp) char *interp; Elf_Brandinfo *brand_info; struct sysentvec *sv; - u_long addr, baddr, et_dyn_addr, entry, proghdr; + u_long addr, baddr, entry, proghdr; u_long maxalign, maxsalign, mapsz, maxv, maxv1, anon_loc; uint32_t fctl0; int32_t osrel; @@ -1235,7 +1235,6 @@ __CONCAT(exec_, __elfN(imgact))(struct image_params *imgp) goto ret; } sv = brand_info->sysvec; - et_dyn_addr = 0; if (hdr->e_type == ET_DYN) { if ((brand_info->flags & BI_CAN_EXEC_DYN) == 0) { uprintf("Cannot execute shared object\n"); @@ -1249,13 +1248,13 @@ __CONCAT(exec_, __elfN(imgact))(struct image_params *imgp) if (baddr == 0) { if ((sv->sv_flags & SV_ASLR) == 0 || (fctl0 & NT_FREEBSD_FCTL_ASLR_DISABLE) != 0) - et_dyn_addr = __elfN(pie_base); + imgp->et_dyn_addr = __elfN(pie_base); else if ((__elfN(pie_aslr_enabled) && (imgp->proc->p_flag2 & P2_ASLR_DISABLE) == 0) || (imgp->proc->p_flag2 & P2_ASLR_ENABLE) != 0) - et_dyn_addr = ET_DYN_ADDR_RAND; + imgp->et_dyn_addr = ET_DYN_ADDR_RAND; else - et_dyn_addr = __elfN(pie_base); + imgp->et_dyn_addr = __elfN(pie_base); } } @@ -1288,11 +1287,11 @@ __CONCAT(exec_, __elfN(imgact))(struct image_params *imgp) if ((sv->sv_flags & SV_ASLR) == 0 || (imgp->proc->p_flag2 & P2_ASLR_DISABLE) != 0 || (fctl0 & NT_FREEBSD_FCTL_ASLR_DISABLE) != 0) { - KASSERT(et_dyn_addr != ET_DYN_ADDR_RAND, - ("et_dyn_addr == RAND and !ASLR")); + KASSERT(imgp->et_dyn_addr != ET_DYN_ADDR_RAND, + ("imgp->et_dyn_addr == RAND and !ASLR")); } else if ((imgp->proc->p_flag2 & P2_ASLR_ENABLE) != 0 || (__elfN(aslr_enabled) && hdr->e_type == ET_EXEC) || - et_dyn_addr == ET_DYN_ADDR_RAND) { + imgp->et_dyn_addr == ET_DYN_ADDR_RAND) { imgp->map_flags |= MAP_ASLR; /* * If user does not care about sbrk, utilize the bss @@ -1329,24 +1328,24 @@ __CONCAT(exec_, __elfN(imgact))(struct image_params *imgp) error = ENOEXEC; } - if (error == 0 && et_dyn_addr == ET_DYN_ADDR_RAND) { + if (error == 0 && imgp->et_dyn_addr == ET_DYN_ADDR_RAND) { KASSERT((map->flags & MAP_ASLR) != 0, ("ET_DYN_ADDR_RAND but !MAP_ASLR")); error = __CONCAT(rnd_, __elfN(base))(map, vm_map_min(map) + mapsz + lim_max(td, RLIMIT_DATA), /* reserve half of the address space to interpreter */ - maxv / 2, maxalign, &et_dyn_addr); + maxv / 2, maxalign, &imgp->et_dyn_addr); } vn_lock(imgp->vp, LK_SHARED | LK_RETRY); if (error != 0) goto ret; - error = __elfN(load_sections)(imgp, hdr, phdr, et_dyn_addr, NULL); + error = __elfN(load_sections)(imgp, hdr, phdr, imgp->et_dyn_addr, NULL); if (error != 0) goto ret; - error = __elfN(enforce_limits)(imgp, hdr, phdr, et_dyn_addr); + error = __elfN(enforce_limits)(imgp, hdr, phdr); if (error != 0) goto ret; @@ -1370,7 +1369,7 @@ __CONCAT(exec_, __elfN(imgact))(struct image_params *imgp) map->anon_loc = addr; } - entry = (u_long)hdr->e_entry + et_dyn_addr; + entry = (u_long)hdr->e_entry + imgp->et_dyn_addr; imgp->entry_addr = entry; if (interp != NULL) { @@ -1389,7 +1388,7 @@ __CONCAT(exec_, __elfN(imgact))(struct image_params *imgp) if (error != 0) goto ret; } else - addr = et_dyn_addr; + addr = imgp->et_dyn_addr; error = exec_map_stack(imgp); if (error != 0) @@ -1405,7 +1404,7 @@ __CONCAT(exec_, __elfN(imgact))(struct image_params *imgp) vn_lock(imgp->vp, LK_SHARED | LK_RETRY); } elf_auxargs->execfd = -1; - elf_auxargs->phdr = proghdr + et_dyn_addr; + elf_auxargs->phdr = proghdr + imgp->et_dyn_addr; elf_auxargs->phent = hdr->e_phentsize; elf_auxargs->phnum = hdr->e_phnum; elf_auxargs->pagesz = PAGE_SIZE; diff --git a/sys/sys/imgact.h b/sys/sys/imgact.h index 963f53aa387b..7f3219a972fe 100644 --- a/sys/sys/imgact.h +++ b/sys/sys/imgact.h @@ -66,6 +66,7 @@ struct image_params { const char *image_header; /* header of file to exec */ unsigned long entry_addr; /* entry address of target executable */ unsigned long reloc_base; /* load address of image */ + unsigned long et_dyn_addr; /* PIE load base */ char *interpreter_name; /* name of the interpreter */ void *auxargs; /* ELF Auxinfo structure pointer */ struct sf_buf *firstpage; /* first page that we mapped */