From nobody Wed Jul 19 14:59:49 2023 X-Original-To: dev-commits-src-main@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 4R5f9y20Dyz4nTh0; Wed, 19 Jul 2023 14:59:50 +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 4R5f9x6kBYz3mPK; Wed, 19 Jul 2023 14:59:49 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1689778789; 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=RVEU1qaprwaIDKYo3ahxXr0n5/BXwBWKOEafAfkjjrU=; b=TfMy7m5EZT7Z/9GZhgYdSydFw/8MTmjln0nUJleJPqtrxYveXuj9uhXCbBqQyANX3/4/HW gxnaZYfHmnuSfeMvbtsdZ+q06FpVXROldjMWPgnMqreLNlpuQwIgXGMfoDqURNRkh/Lv1s 1kpSJykCUbugLsxk8XyMisTlPzTY2kbX7MmzHRcRceVas/5ln1EdSWpdiR8hLziqFnCo/T a3zULWoXvcJP3SUQbGSPEgCV0aidSRQ+einlaVe6jLkkHkFCWgBDuGfDks861klZB+m3n6 pl3DaHI3/oe7yHwIBmHCqJ1vrIOWd2OsSI73G5+SJaKyFpUXVt8RlHTMRVh9sw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1689778789; 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=RVEU1qaprwaIDKYo3ahxXr0n5/BXwBWKOEafAfkjjrU=; b=AU7xk0WS7Mv7aCHuDjRppsousE4bc6NvC2kyztQuGxA/urzEOapN1QRQEPpA2eHejZtetx z51DzYsP+TBHiH4dAfRmWIr+j2DIwshIKKlTHy5IrYZjXAyYjsq9kJA23cpoL4IlYeChWv ax0uxPdyjr2Vnf3bGlBMRpdxzXJudo3gyNNDPz93/PnNmlDN7Vv1YLGHrdVc80UDhpX5/t QUcH6BbrFH1VK1U1zXisWQ2Ds7rDIVIiVbvMgXKnTzMJu5SdOX6Yhgy9rNE9X1lmRuAHg1 Cagvcef5Y/RMgG0im+2VYCdwVA9mei06w4853uGF4ZVbRQY4S8tVHUjGoD39yQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1689778789; a=rsa-sha256; cv=none; b=nWwk/EywZdviBcSu/212yPyi299I6keG+WWnlmCAYm067zTqI5Hmu1jQZWWjhxk2MqeTrs 8FcLHfiRzzNWkBmSG15uWvFx3tO3S309THUro6L72FUzorkCyklStA4/duIdpah27JdUGo Lq6VzkSCGbAvF8QzO/49xM7EAORztpecwBrQsaj2ZbRCaThKlML8WYGubnaE4e0xZbvuPy M0Hj85ja6HiDJM/fkg05e2ST3/P1XoRiW/ELCcNQLirMXgbzBjN1xnq+ptuxjporAPvB0e 8KozcjoupUInEbZiyhfh2eLyUNmQXU0kDbeXO4d8UQM+QBCAr5mdLC9FNFuBYw== 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 4R5f9x5QDXzrh6; Wed, 19 Jul 2023 14:59:49 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 36JExn7M067548; Wed, 19 Jul 2023 14:59:49 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 36JExn2c067547; Wed, 19 Jul 2023 14:59:49 GMT (envelope-from git) Date: Wed, 19 Jul 2023 14:59:49 GMT Message-Id: <202307191459.36JExn2c067547@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Christos Margiolis Subject: git: ea89133dbc5f - main - kinst: check for 'push %rbp' anywhere in the function List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: christos X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: ea89133dbc5f29cbb8db48ecc09a47ea22d8aa9e Auto-Submitted: auto-generated The branch main has been updated by christos: URL: https://cgit.FreeBSD.org/src/commit/?id=ea89133dbc5f29cbb8db48ecc09a47ea22d8aa9e commit ea89133dbc5f29cbb8db48ecc09a47ea22d8aa9e Author: Christos Margiolis AuthorDate: 2023-07-19 14:53:08 +0000 Commit: Christos Margiolis CommitDate: 2023-07-19 14:53:08 +0000 kinst: check for 'push %rbp' anywhere in the function Currently kinst checks if only the first instruction is 'push %rbp', essentially excluding functions that do push RBP, but not in the first instruction. This patch modifies kinst to check for 'push %rbp', as well, as a following 'pop %rbp', anywhere in the function. This behavior also matches that of FBT. Reviewed by: markj Approved by: markj (mentor) Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D40283 --- sys/cddl/dev/kinst/amd64/kinst_isa.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/sys/cddl/dev/kinst/amd64/kinst_isa.c b/sys/cddl/dev/kinst/amd64/kinst_isa.c index 908dc79e9247..398f30a281c0 100644 --- a/sys/cddl/dev/kinst/amd64/kinst_isa.c +++ b/sys/cddl/dev/kinst/amd64/kinst_isa.c @@ -22,6 +22,7 @@ #include "kinst.h" #define KINST_PUSHL_RBP 0x55 +#define KINST_POPL_RBP 0x5d #define KINST_STI 0xfb #define KINST_POPF 0x9d @@ -500,7 +501,8 @@ kinst_make_probe(linker_file_t lf, int symindx, linker_symval_t *symval, dtrace_kinst_probedesc_t *pd; const char *func; int error, instrsize, n, off; - uint8_t *instr, *limit; + uint8_t *instr, *limit, *tmp; + bool push_found, pop_found; pd = opaque; func = symval->name; @@ -515,12 +517,21 @@ kinst_make_probe(linker_file_t lf, int symindx, linker_symval_t *symval, return (0); /* - * Ignore functions not beginning with the usual function prologue. - * These might correspond to exception handlers with which we should not - * meddle. This does however exclude functions which can be safely - * traced, such as cpu_switch(). + * Refuse to instrument functions lacking the usual frame pointer + * manipulations since they might correspond to exception handlers. */ - if (*instr != KINST_PUSHL_RBP) + tmp = instr; + push_found = pop_found = false; + while (tmp < limit) { + if (*tmp == KINST_PUSHL_RBP) + push_found = true; + else if (*tmp == KINST_POPL_RBP) + pop_found = true; + if (push_found && pop_found) + break; + tmp += dtrace_instr_size(tmp); + } + if (!push_found || !pop_found) return (0); n = 0;