Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp1648893ybt; Thu, 18 Jun 2020 13:50:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzilftAnhd5lTSmAoVEkCDALNt0eSKl/wRW+Y1aBnZmkuZIBjoG011utiR5Jvl4kf7MWCFv X-Received: by 2002:aa7:d74c:: with SMTP id a12mr47550eds.369.1592513452029; Thu, 18 Jun 2020 13:50:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592513452; cv=none; d=google.com; s=arc-20160816; b=e/O1/otSbIOlUOYv+kYeE8/ypcvL4Pf81TnI1XCswqwbTyTrJRXqA3Kr0NioOPlDPB jkagxJyl6DhfAynLCUsonFHM45qJVdsQVP1c8x7MEYBbGJlb9PsxJttgJuMiDB3XLMxY 7BNvlJPhDeNCudUCWT67N3aWR/OBW6RzNRI2K+L/9lgmO8sqetZMLDoEIasXrGXPvOxx 79bSGej7OsQ4ytjynZq+3J1SYu+SY2XnnoiH0m2lLO5szOQA1Xr+ENjOU6cnH92j95iy sA7dUz+/Kv5Q9xzcdoE0uwAAlAhgifVJO7kz45GBRVUlE9EsJjwatP/6AZHa6G2nB2H/ 5POg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=IYEV9b3/iwCJb7kPhocLecq4657ftjqpO9eYprpZ8KQ=; b=UB66/j2E6qCcoYXR4b48eNdVzGdIqho7/nJVmf6bv61KZGQ75W8lAloaEmEOXD7BZf 3ilSHpidR7FF6v0KHfvxCu1Z5APY+bbNAYNFKgxPGmeqChS1gito7P5X7quzI0Z1AepF kRAv2UpjHwO1lYwgvmaroUzwmUT5klU262tzOjmhfVEyEbrQAiLw/6+wFL352BiHXke+ 8TWMKlQpGs8jiy+5YOxXNshpb3qdcbI1d7AZ0osVOxsKA9CqEeeT1pONOWeDP6hj5BKu U4rzikWGHN1VMMv09njHbUNw2PgIJWQVrI0kp6JgUEnGc0sDKHl0orpZ6HVSRdiuqqhG AwgA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=vmware.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j12si2201115ejs.213.2020.06.18.13.50.29; Thu, 18 Jun 2020 13:50:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=vmware.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732073AbgFRUkg (ORCPT + 99 others); Thu, 18 Jun 2020 16:40:36 -0400 Received: from ex13-edg-ou-002.vmware.com ([208.91.0.190]:36734 "EHLO EX13-EDG-OU-002.vmware.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731400AbgFRUjh (ORCPT ); Thu, 18 Jun 2020 16:39:37 -0400 Received: from sc9-mailhost2.vmware.com (10.113.161.72) by EX13-EDG-OU-002.vmware.com (10.113.208.156) with Microsoft SMTP Server id 15.0.1156.6; Thu, 18 Jun 2020 13:39:28 -0700 Received: from sc9-mailhost2.vmware.com (unknown [10.129.221.29]) by sc9-mailhost2.vmware.com (Postfix) with ESMTP id A249CB265A; Thu, 18 Jun 2020 16:39:30 -0400 (EDT) From: Matt Helsley To: CC: Josh Poimboeuf , Peter Zijlstra , Steven Rostedt , Julien Thierry , Kamalesh Babulal , Matt Helsley Subject: [RFC][PATCH v5 39/51] objtool: mcount: Verify x86 instruction with memcmp() Date: Thu, 18 Jun 2020 13:38:25 -0700 Message-ID: <1a5496d5031c7d4ff50b61a34973a8c975fb4972.1592510545.git.mhelsley@vmware.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII Received-SPF: None (EX13-EDG-OU-002.vmware.com: mhelsley@vmware.com does not designate permitted sender hosts) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Instead of hard-coding what amounts to a memcmp() use memcmp to determine if the instruction we wish to replace matches what we expect. This makes the x86 code more like that of, for instance, ARM. Signed-off-by: Matt Helsley --- tools/objtool/mcount.c | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/tools/objtool/mcount.c b/tools/objtool/mcount.c index 4d6596a031bf..5c59df0df97b 100644 --- a/tools/objtool/mcount.c +++ b/tools/objtool/mcount.c @@ -47,9 +47,10 @@ extern int warn_on_notrace_sect; /* warn when section has mcount not being recor static struct elf *lf; -static unsigned char ideal_nop5_x86_64[5] = { 0x0f, 0x1f, 0x44, 0x00, 0x00 }; -static unsigned char ideal_nop5_x86_32[5] = { 0x3e, 0x8d, 0x74, 0x26, 0x00 }; -static unsigned char *ideal_nop; +static const unsigned char ip_relative_call_x86[5] = { 0xe8, 0x00, 0x00, 0x00, 0x00 }; +static const unsigned char ideal_nop5_x86_64[5] = { 0x0f, 0x1f, 0x44, 0x00, 0x00 }; +static const unsigned char ideal_nop5_x86_32[5] = { 0x3e, 0x8d, 0x74, 0x26, 0x00 }; +static const unsigned char *ideal_nop; static char rel_type_nop; @@ -57,20 +58,12 @@ static int (*make_nop)(struct section *, size_t const offset); static int make_nop_x86(struct section *txts, size_t const offset) { - uint32_t *ptr; - unsigned char *op; - void *map = txts->data->d_buf; + unsigned char *op = txts->data->d_buf + offset - 1; if (offset < 1) return -1; - /* Confirm we have 0xe8 0x0 0x0 0x0 0x0 */ - ptr = map + offset; - if (*ptr != 0) - return -1; - - op = map + offset - 1; - if (*op != 0xe8) + if (memcmp(op, ip_relative_call_x86, 5) != 0) return -1; /* convert to nop */ -- 2.20.1