From patchwork Thu Feb 23 08:32:06 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: 60836 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp203470wrd; Thu, 23 Feb 2023 00:39:12 -0800 (PST) X-Google-Smtp-Source: AK7set9za/aQl1veOMKR1PN9JoqJnc6DiH8t7ECPxdpzHE1h2n0H18PbfwDXI6/b7qa65tv8FE1G X-Received: by 2002:a05:6a20:1610:b0:bf:f68:9b1a with SMTP id l16-20020a056a20161000b000bf0f689b1amr12719581pzj.1.1677141552226; Thu, 23 Feb 2023 00:39:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677141552; cv=none; d=google.com; s=arc-20160816; b=sHnGqg4sAwA7CigxKPMCTt4PJPibIjd4D0u97RhMHXz7zG6ZmdhHAIifeboJOI1JA7 ug/Ni+x5s89oTJb3Zr20EnzP9D2ZgL0OuzJwE4BgCrCM4p5q38BwHlt184EXpGEw0n9o lsIDSZPCTmUxIUFuSFDVsHlnlVyH2xHZc0MojNI776lDhKi+lHISLkOS+gDrVhhzmHXV Q/0h5mzO1g95PzkHZBoaJPG92G/O2Cl2dm2wVCvdhaO31XmxlmxNvAv0s6b3M29jIvQY WMh149aoPE1ZKz6k2dpcmF60vQjIz+4TtdvjH5X/05s/KtT4X/2vm9fWe0SgbKaRiwsA 1ycA== 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=+Y8Fntz/JA1B8hjHAmR4+FqdQgTAPuLDEnq2QoeBt+0=; b=qNH4KBCD+BGcGkMfQq7iuGScSmdwKtn3g3dxGQwVFzMwZPHZ2ujQLgaD9dnLKDG6Vb 9+MQ2d/UcijhQJo1NAHN9JYOPEa3HTTI8qmbb+rkYhyClpEeut+Iq862vJqH3P4iMl4Q /QxHITsD5hWMWdHfEN9tR1FBmjzGBMiy5clIYom3PT24VTCNXPUzw4sBK1qd81y4J0gm M7rg4JXqsidjKKtFdI+CkzJrnjA10x7JOfE/Dmzd01CiH8DHi6wXvEq+EV572W2iLnGM Wc8oVs7wEghBQMacmj4nPtCWckgQFRISVLpbLrQzd+1H1hfki8odnssDo5/JkyyLXVCH /LcA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=MHProl2e; dkim=neutral (no key) header.i=@linutronix.de; 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 p28-20020a056a0026dc00b005a8ee167e52si11690600pfw.325.2023.02.23.00.38.59; Thu, 23 Feb 2023 00:39:12 -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=MHProl2e; dkim=neutral (no key) header.i=@linutronix.de; 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 S233652AbjBWIcS (ORCPT + 99 others); Thu, 23 Feb 2023 03:32:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55780 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233386AbjBWIcL (ORCPT ); Thu, 23 Feb 2023 03:32:11 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EF2AD4D627; Thu, 23 Feb 2023 00:32:08 -0800 (PST) Date: Thu, 23 Feb 2023 08:32:06 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1677141127; 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=+Y8Fntz/JA1B8hjHAmR4+FqdQgTAPuLDEnq2QoeBt+0=; b=MHProl2e7l015GMvW+/zf/81rXlBzdD0kAN17PmNNUwhPxtkSa8EF2B5Cqe+Z3riI79SgB dx+qCfyQWhOde5lA9j9PXqAEIa381jaJ5eYOkJB4VW0kWafQrt76ymOndXjd++fTKNHCUm gt55+bcRU++q8fsxKPKpGkSJ45BpCoH7maCUj9uF1wJbD2X/6P4r104uym0HwYWdbpF1g0 ualBKdOhK1ea0Mapfd8VMG/DAg/clkTo3EbWAM7w8tTL0eRjkJFBSq9sF0MDNeKcS+AhZr rKjR0rZ42JqTBrz/OXy4ZpZk3ZIn3FE5r+lCW3jRhmLwmgPdfii1upcKxCJgRA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1677141127; 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=+Y8Fntz/JA1B8hjHAmR4+FqdQgTAPuLDEnq2QoeBt+0=; b=RGBxyLD5n81e2p4e0m/dyCvpMBBYS4ExPzbaTAmvKtBjh5xqbunHpahLaPOdfhabbncC0Y v4JDPqQWzyCVdTBQ== 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)" , Ingo Molnar , 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: <167714112674.5837.7896519866056766008.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?1758610380432899640?= The following commit has been merged into the objtool/core branch of tip: Commit-ID: a706bb08c81ac878982e41d4b6abcc42258bd39e Gitweb: https://git.kernel.org/tip/a706bb08c81ac878982e41d4b6abcc42258bd39e Author: Peter Zijlstra AuthorDate: Wed, 08 Feb 2023 18:18:03 +01:00 Committer: Ingo Molnar CommitterDate: Thu, 23 Feb 2023 09:21:33 +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) Signed-off-by: Ingo Molnar 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; } }