Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp4702013imw; Tue, 12 Jul 2022 12:42:01 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vI2ypbphdHk78LhszEeK/E9g6D/QLlZFDjSBvY7uURt0EfX9JwDLnb34t8pDGclMZdDMgf X-Received: by 2002:a05:6402:2742:b0:43a:bd75:5e82 with SMTP id z2-20020a056402274200b0043abd755e82mr26238351edd.274.1657654920868; Tue, 12 Jul 2022 12:42:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657654920; cv=none; d=google.com; s=arc-20160816; b=hUI+pY+IEFaphFkbqPpYVFiq8+EKZ1Bd9zr/gjCvf0A8u4eGdgKy8eiSPqoN8UiCnI olcazrbP2spt/FjUbh4W/NND58BN4P9SB5Zj3WmyikwjJfm9iCgDUj8EMwfTnKvQlApu /7YUkLpBI0h6C70ho2u3MeXxlb5eQXWaZzBldHs7CDDqAWid7IgOXp/w9IW446Ox+hfY 5HUEKYbfZt5gp2UwZdeRWNhfahS66tNOzoWgoXlQZSYnUC8O/x6bwtJRs79FS+3cyXKK dkh4nCedRrNColNEsg7d/gR28BUmYipICundV2kkxjyFi95pJ2G5hpo6m/AEA5R2WnSA Aakg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=kfjnlXRlhLnjmmumRGr7BVc0/otGZx4l+4tJ5daxh8M=; b=q+/pjlUhm1lGtYOHzNp8349+Y/TLEftTwiKr8mpr371a22tnx6pzuUJ7PaVZRv3cJN 7UMpq5mFoNfNaKWab/9wXglq+v1Vu+VlTd8N5yQcbKzXlmwiSvRH6yhkYiwN8S4pajiv uH+lWe4kXyl5qBm33e8RxuOthsm8DUBDiwkvMJfFl9Tw0C4eenab/u65MI/ABNaYtQC6 /FM57GHxErl53InIplnMMNzpT2CFx7fyyDdUhRSh9MPxhSz6e31O8EEhl3Qqnvyvt9AN b3SS8cvBsQCv/AsvHhk7BEGSMZdz6LXBomAfoS2stOUklG29+wVxmURClbdElY1PuSMB nnwg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=IYTJQ6Wf; 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=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l21-20020a170906795500b0072b4afe43desi2650104ejo.105.2022.07.12.12.41.34; Tue, 12 Jul 2022 12:42:00 -0700 (PDT) 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=@linuxfoundation.org header.s=korg header.b=IYTJQ6Wf; 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=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234595AbiGLSup (ORCPT + 99 others); Tue, 12 Jul 2022 14:50:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44838 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234568AbiGLSuW (ORCPT ); Tue, 12 Jul 2022 14:50:22 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 89BCBE2A1A; Tue, 12 Jul 2022 11:44:10 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 54F75B81B96; Tue, 12 Jul 2022 18:44:08 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9732AC3411C; Tue, 12 Jul 2022 18:44:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1657651447; bh=b4lPAu6TIYBuJvohHsBAYnRu4yFmScVttnEgCBbUYFc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IYTJQ6WfDeWm9ZrPyRb9VInTsplCGUifyd/hj5nftXG86xMfADhq5ohPYOmmpjYx/ ODfikNlli0H/fvPBAxMleLzLr2mVUfy9M6doJdB67qtTs08v85S+ikCobtjcmKxY8b FLlI5FVCOGwTO04lQ0IqTAqwHOOJOiV98I9vt9hU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Peter Zijlstra (Intel)" , Borislav Petkov , Josh Poimboeuf , Alexei Starovoitov , Thadeu Lima de Souza Cascardo , Ben Hutchings Subject: [PATCH 5.10 048/130] objtool: Explicitly avoid self modifying code in .altinstr_replacement Date: Tue, 12 Jul 2022 20:38:14 +0200 Message-Id: <20220712183248.643758185@linuxfoundation.org> X-Mailer: git-send-email 2.37.0 In-Reply-To: <20220712183246.394947160@linuxfoundation.org> References: <20220712183246.394947160@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 From: Peter Zijlstra commit dd003edeffa3cb87bc9862582004f405d77d7670 upstream. Assume ALTERNATIVE()s know what they're doing and do not change, or cause to change, instructions in .altinstr_replacement sections. Signed-off-by: Peter Zijlstra (Intel) Reviewed-by: Borislav Petkov Acked-by: Josh Poimboeuf Tested-by: Alexei Starovoitov Link: https://lore.kernel.org/r/20211026120309.722511775@infradead.org [cascardo: context adjustment] Signed-off-by: Thadeu Lima de Souza Cascardo [bwh: Backported to 5.10: objtool doesn't have any mcount handling] Signed-off-by: Ben Hutchings Signed-off-by: Greg Kroah-Hartman --- tools/objtool/check.c | 36 ++++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -870,18 +870,27 @@ static void remove_insn_ops(struct instr } } -static void add_call_dest(struct objtool_file *file, struct instruction *insn, - struct symbol *dest, bool sibling) +static void annotate_call_site(struct objtool_file *file, + struct instruction *insn, bool sibling) { struct reloc *reloc = insn_reloc(file, insn); + struct symbol *sym = insn->call_dest; - insn->call_dest = dest; - if (!dest) + if (!sym) + sym = reloc->sym; + + /* + * Alternative replacement code is just template code which is + * sometimes copied to the original instruction. For now, don't + * annotate it. (In the future we might consider annotating the + * original instruction if/when it ever makes sense to do so.) + */ + if (!strcmp(insn->sec->name, ".altinstr_replacement")) return; - if (insn->call_dest->static_call_tramp) { - list_add_tail(&insn->call_node, - &file->static_call_list); + if (sym->static_call_tramp) { + list_add_tail(&insn->call_node, &file->static_call_list); + return; } /* @@ -889,7 +898,7 @@ static void add_call_dest(struct objtool * so they need a little help, NOP out any KCOV calls from noinstr * text. */ - if (insn->sec->noinstr && insn->call_dest->kcov) { + if (insn->sec->noinstr && sym->kcov) { if (reloc) { reloc->type = R_NONE; elf_write_reloc(file->elf, reloc); @@ -901,7 +910,16 @@ static void add_call_dest(struct objtool : arch_nop_insn(insn->len)); insn->type = sibling ? INSN_RETURN : INSN_NOP; + return; } +} + +static void add_call_dest(struct objtool_file *file, struct instruction *insn, + struct symbol *dest, bool sibling) +{ + insn->call_dest = dest; + if (!dest) + return; /* * Whatever stack impact regular CALLs have, should be undone @@ -911,6 +929,8 @@ static void add_call_dest(struct objtool * are converted to JUMP, see read_intra_function_calls(). */ remove_insn_ops(insn); + + annotate_call_site(file, insn, sibling); } /*