From owner-svn-src-stable-12@freebsd.org Tue May 26 14:05:38 2020 Return-Path: Delivered-To: svn-src-stable-12@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 863B92FFD84; Tue, 26 May 2020 14:05:38 +0000 (UTC) (envelope-from markj@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 "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 49WbMk32vRz4CsC; Tue, 26 May 2020 14:05:38 +0000 (UTC) (envelope-from markj@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 62F6E24561; Tue, 26 May 2020 14:05:38 +0000 (UTC) (envelope-from markj@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 04QE5cST008377; Tue, 26 May 2020 14:05:38 GMT (envelope-from markj@FreeBSD.org) Received: (from markj@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 04QE5c9a008376; Tue, 26 May 2020 14:05:38 GMT (envelope-from markj@FreeBSD.org) Message-Id: <202005261405.04QE5c9a008376@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: markj set sender to markj@FreeBSD.org using -f From: Mark Johnston Date: Tue, 26 May 2020 14:05:38 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r361504 - stable/12/lib/librtld_db X-SVN-Group: stable-12 X-SVN-Commit-Author: markj X-SVN-Commit-Paths: stable/12/lib/librtld_db X-SVN-Commit-Revision: 361504 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-12@freebsd.org X-Mailman-Version: 2.1.33 Precedence: list List-Id: SVN commit messages for only the 12-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 26 May 2020 14:05:38 -0000 Author: markj Date: Tue May 26 14:05:37 2020 New Revision: 361504 URL: https://svnweb.freebsd.org/changeset/base/361504 Log: MFC r360979: librtld_db: Fix shlib mapping offsets. PR: 244732 Modified: stable/12/lib/librtld_db/rtld_db.c Directory Properties: stable/12/ (props changed) Modified: stable/12/lib/librtld_db/rtld_db.c ============================================================================== --- stable/12/lib/librtld_db/rtld_db.c Tue May 26 14:05:06 2020 (r361503) +++ stable/12/lib/librtld_db/rtld_db.c Tue May 26 14:05:37 2020 (r361504) @@ -160,9 +160,12 @@ rd_err_e rd_loadobj_iter(rd_agent_t *rdap, rl_iter_f *cb, void *clnt_data) { struct kinfo_vmentry *kves, *kve; + const char *path; + uint64_t fileid; rd_loadobj_t rdl; rd_err_e ret; - int cnt, i, lastvn; + uintptr_t base; + int cnt, i; DPRINTF("%s\n", __func__); @@ -171,27 +174,38 @@ rd_loadobj_iter(rd_agent_t *rdap, rl_iter_f *cb, void return (RD_ERR); } + base = 0; + fileid = 0; + path = NULL; ret = RD_OK; - lastvn = 0; for (i = 0; i < cnt; i++) { - kve = kves + i; - if (kve->kve_type == KVME_TYPE_VNODE) - lastvn = i; + kve = &kves[i]; + /* + * Cache the base offset of the file mapping. The kve_offset + * field gives the file offset of a particular mapping into the + * file, but we want the mapping offset relative to the base + * mapping. + */ + if (kve->kve_type == KVME_TYPE_VNODE && + kve->kve_vn_fileid != fileid) { + base = kve->kve_start; + fileid = kve->kve_vn_fileid; + path = kve->kve_path; + } memset(&rdl, 0, sizeof(rdl)); /* * Map the kinfo_vmentry struct to the rd_loadobj structure. */ rdl.rdl_saddr = kve->kve_start; rdl.rdl_eaddr = kve->kve_end; - rdl.rdl_offset = kve->kve_offset; + rdl.rdl_offset = kve->kve_start - base; if (kve->kve_protection & KVME_PROT_READ) rdl.rdl_prot |= RD_RDL_R; if (kve->kve_protection & KVME_PROT_WRITE) rdl.rdl_prot |= RD_RDL_W; if (kve->kve_protection & KVME_PROT_EXEC) rdl.rdl_prot |= RD_RDL_X; - strlcpy(rdl.rdl_path, kves[lastvn].kve_path, - sizeof(rdl.rdl_path)); + strlcpy(rdl.rdl_path, path, sizeof(rdl.rdl_path)); if ((*cb)(&rdl, clnt_data) != 0) { ret = RD_ERR; break;