From patchwork Mon Feb 13 11:10:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: tip-bot2 for Thomas Gleixner X-Patchwork-Id: 56204 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2284549wrn; Mon, 13 Feb 2023 03:11:29 -0800 (PST) X-Google-Smtp-Source: AK7set9EnTq9bdGq49F8fhIk9sGookubEgsqL+tSW2WaTSy19DEjtOg2a6fR7tQBnHVJ70N3mQc1 X-Received: by 2002:a17:907:3fa9:b0:878:5da4:77a6 with SMTP id hr41-20020a1709073fa900b008785da477a6mr33977391ejc.51.1676286689148; Mon, 13 Feb 2023 03:11:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676286689; cv=none; d=google.com; s=arc-20160816; b=YEKct8GAROoK6RaeOH/7L3gbJuDxBIWs/C/nM7sLl7+1NoqnzEZbMDsqrLc6wMf44+ xhzT3esfFP7+h2IOcN+upQyuGvUt1c3UH1iS8o0PmkXlL2cP692lW4w1YiUcbLW7c28P xiSL8bHZamU0O3MNN02t2UObuAdIvGlYytb/Q9qBFqy9vvEtvGvMGF2nObHo0cf3Gcne w3LjzJRZD98yHcV2EMcN6CRlAgHYWXlqSOig/ORu5ftGnZdpA1xr3rkbj59bWm5nIMal kUAZTeZ/BNVfFeACM5ibiDGqnY2R2FotWuFi1uJu9K1jJ3jDwgS0lktT/8sfkfe0ZeR4 kEtw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=JOC0a4gy2ApTzddPrjSS4SZiss1DvZODmo8oPZZk5lY=; b=FotqkRAwzaXd9nYY8HNbF7CDqkBHu6imVUtrTih7gRv8mXV4GkinwU25i1BaZ8pgoK pYE3PcakQpQAl29zgXWn35aoC+wIPyNZfe34MhDn+4PWab8BF80Aw2A6A+TpBWBoleMo pm6HDgbTyFEzOjQFm1Ku3d3c+H9lvdSylwlMQo5LnilQQj5AktkDtNyBew2TG3p2r59s L/L7jmXszZ5BaRKAL0OvRlM2F5+M/kO7QbFsI5fkalos+NKfvxnbhBNRE8ZSuv2Lb6vC 8EglRgbWvM2dYcltd+esB0En/5jRjiMyAzgUK9uGsH9OwR1ZtAg0bFcqxE8DIDzu4ken nh3w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=j5xXLzEW; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=qa49NxNK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id mt24-20020a170907619800b008af2a8e982esi6207329ejc.871.2023.02.13.03.11.06; Mon, 13 Feb 2023 03:11:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=j5xXLzEW; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=qa49NxNK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230227AbjBMLKg (ORCPT + 99 others); Mon, 13 Feb 2023 06:10:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48406 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230200AbjBMLKe (ORCPT ); Mon, 13 Feb 2023 06:10:34 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 25EB5EC5B; Mon, 13 Feb 2023 03:10:31 -0800 (PST) Date: Mon, 13 Feb 2023 11:10:28 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1676286628; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=JOC0a4gy2ApTzddPrjSS4SZiss1DvZODmo8oPZZk5lY=; b=j5xXLzEW9kyStfVvpjdy8+7zUVVolEbfCBUmsuhRPzY3MkMX9HGAbf7Ve1zqE2VUqvuEiB dGxocwJieRjGGTeCKPJyQ3+QtmdKnxxg54YfA8pZu81cYERkcQJsqtgCAXs518uMHm+U4F mmegKnlfBgfMZx5hd3ol2X78M7CN+vtZDdbZtA1B8NCRuLDmcmwOQqNY60iRNYbV7LSeGF Qu6Mtn0RrVuWLmTSlFwGp3K8oACt3wublerEb5F28HBStk9wzkkXXrUDcr8TTE0Ns1mfHS fGFd+3k4O7G43V/MC1uMvcT44EIx1aeJvYtQJoHvvxWThUqR15Skna3XElQDcA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1676286628; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=JOC0a4gy2ApTzddPrjSS4SZiss1DvZODmo8oPZZk5lY=; b=qa49NxNKB4eF2K16abgm3uedoYNQ484YY7PR9jPClfrHz/1rsUulNmq2lV1yEgA74MjCvY n4cUz00nw5kD8EBw== From: "tip-bot2 for Peter Zijlstra" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: objtool/core] objtool: Fix overlapping alternatives Cc: "Peter Zijlstra (Intel)" , Josh Poimboeuf , Nathan Chancellor , linux@weissschuh.net, x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20230208172245.711471461@infradead.org> References: <20230208172245.711471461@infradead.org> MIME-Version: 1.0 Message-ID: <167628662854.4906.18315456608077226990.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1757285090917564540?= X-GMAIL-MSGID: =?utf-8?q?1757713991392363988?= The following commit has been merged into the objtool/core branch of tip: Commit-ID: 339b90b37d80ff2f4064bf072584031f3b1b5838 Gitweb: https://git.kernel.org/tip/339b90b37d80ff2f4064bf072584031f3b1b5838 Author: Peter Zijlstra AuthorDate: Wed, 08 Feb 2023 18:18:03 +01:00 Committer: Peter Zijlstra CommitterDate: Mon, 13 Feb 2023 11:26:08 +01:00 objtool: Fix overlapping alternatives Things like ALTERNATIVE_{2,3}() generate multiple alternatives on the same place, objtool would override the first orig_alt_group with the second (or third), failing to check the CFI among all the different variants. Signed-off-by: Peter Zijlstra (Intel) Acked-by: Josh Poimboeuf Tested-by: Nathan Chancellor # build only Tested-by: Thomas Weißschuh # compile and run Link: https://lore.kernel.org/r/20230208172245.711471461@infradead.org --- tools/objtool/check.c | 69 ++++++++++++++++++++++++++---------------- 1 file changed, 43 insertions(+), 26 deletions(-) diff --git a/tools/objtool/check.c b/tools/objtool/check.c index 6f0adb2..7e9d3d3 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -1744,36 +1744,49 @@ static int handle_group_alt(struct objtool_file *file, struct instruction *orig_insn, struct instruction **new_insn) { - struct instruction *last_orig_insn, *last_new_insn = NULL, *insn, *nop = NULL; + struct instruction *last_new_insn = NULL, *insn, *nop = NULL; struct alt_group *orig_alt_group, *new_alt_group; unsigned long dest_off; - - orig_alt_group = malloc(sizeof(*orig_alt_group)); + orig_alt_group = orig_insn->alt_group; if (!orig_alt_group) { - WARN("malloc failed"); - return -1; - } - orig_alt_group->cfi = calloc(special_alt->orig_len, - sizeof(struct cfi_state *)); - if (!orig_alt_group->cfi) { - WARN("calloc failed"); - return -1; - } + struct instruction *last_orig_insn = NULL; - last_orig_insn = NULL; - insn = orig_insn; - sec_for_each_insn_from(file, insn) { - if (insn->offset >= special_alt->orig_off + special_alt->orig_len) - break; + orig_alt_group = malloc(sizeof(*orig_alt_group)); + if (!orig_alt_group) { + WARN("malloc failed"); + return -1; + } + orig_alt_group->cfi = calloc(special_alt->orig_len, + sizeof(struct cfi_state *)); + if (!orig_alt_group->cfi) { + WARN("calloc failed"); + return -1; + } - insn->alt_group = orig_alt_group; - last_orig_insn = insn; - } - orig_alt_group->orig_group = NULL; - orig_alt_group->first_insn = orig_insn; - orig_alt_group->last_insn = last_orig_insn; + insn = orig_insn; + sec_for_each_insn_from(file, insn) { + if (insn->offset >= special_alt->orig_off + special_alt->orig_len) + break; + insn->alt_group = orig_alt_group; + last_orig_insn = insn; + } + orig_alt_group->orig_group = NULL; + orig_alt_group->first_insn = orig_insn; + orig_alt_group->last_insn = last_orig_insn; + } else { + if (orig_alt_group->last_insn->offset + orig_alt_group->last_insn->len - + orig_alt_group->first_insn->offset != special_alt->orig_len) { + WARN_FUNC("weirdly overlapping alternative! %ld != %d", + orig_insn->sec, orig_insn->offset, + orig_alt_group->last_insn->offset + + orig_alt_group->last_insn->len - + orig_alt_group->first_insn->offset, + special_alt->orig_len); + return -1; + } + } new_alt_group = malloc(sizeof(*new_alt_group)); if (!new_alt_group) { @@ -1848,7 +1861,7 @@ static int handle_group_alt(struct objtool_file *file, dest_off = arch_jump_destination(insn); if (dest_off == special_alt->new_off + special_alt->new_len) { - insn->jump_dest = next_insn_same_sec(file, last_orig_insn); + insn->jump_dest = next_insn_same_sec(file, orig_alt_group->last_insn); if (!insn->jump_dest) { WARN_FUNC("can't find alternative jump destination", insn->sec, insn->offset); @@ -3226,8 +3239,12 @@ static int propagate_alt_cfi(struct objtool_file *file, struct instruction *insn alt_cfi[group_off] = insn->cfi; } else { if (cficmp(alt_cfi[group_off], insn->cfi)) { - WARN_FUNC("stack layout conflict in alternatives", - insn->sec, insn->offset); + struct alt_group *orig_group = insn->alt_group->orig_group ?: insn->alt_group; + struct instruction *orig = orig_group->first_insn; + char *where = offstr(insn->sec, insn->offset); + WARN_FUNC("stack layout conflict in alternatives: %s", + orig->sec, orig->offset, where); + free(where); return -1; } }