Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp4339328pxb; Thu, 14 Oct 2021 03:26:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwuDa/C0/Za8Un+9Hz+x9UNRiqZMw9mfXIjMlFWuG3jxnV3xc60yejb6GyDSR4My76lMGZ2 X-Received: by 2002:a17:902:8b8b:b0:13d:e91c:a1b9 with SMTP id ay11-20020a1709028b8b00b0013de91ca1b9mr4296698plb.60.1634207194468; Thu, 14 Oct 2021 03:26:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634207194; cv=none; d=google.com; s=arc-20160816; b=NExeVnnD27E2Wf1DUFF2exnIkVg2GqGq+P3V+rtCmEDzR+N77zSSUHhDi8tXJpPXLq zMUFqB32WsAuGXplDi8vPl5LFsorxfs2p0EgeuohnmrL5a/EyBdpP3PlFfNmgtVQv4yj JmB91UAoSDoUEbA3hfUf8fEyzmUemGERHQI4R3fSb6/wjqnMmEhl4KKmRd/YumShOtgx eLrzfgPztf6rebOulseAjrKmhyek6JMgTTT4BDffp+Z3SjyvVTOT0en/1LpW/cz3+jva NsByjcIRtDaqb+BZbBj/47RLmPQ6ldT6mSe7ELgNAjoRhsY0Zl3V7c8xCHQCB/jnmo2z 3JBA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=Fx9cLhN7mOpr+grnv3F8YGfL7yLYIEU/n5hQtUEVSyY=; b=bkZRC0FlzqreIwo1oKtLMzoeK/KBz7xJmie82/Fu4wu/+zkwIW7nYueJUT5fbGVZI3 TK2nOKHKIhaYZb6ckivHgrtbHmEM7WdKvgoSLAt4qxq8rzychnxacPwGymMDCO1PNAZd qaQyoFOs6JKdqppcwX+xCYhmy/1YpNeVV4Ec8eEc4qRcYOFgyhtPBP8nYVAiBW//HgX0 izwP2Jp4jSoXjDXt6agX+BJ4FhK+Do3xbkL/TZpx/xJVgp3Q3M/HjagcYXs0vXF1fJKh DEPjVXmafIhMsousK456TOVLXGZOITJ1BwjDhUgOaINONjzKPwKmlAsWn5clEtAkOJDj ad0A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=HBIQ7Jv1; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x8si2891197plo.61.2021.10.14.03.26.19; Thu, 14 Oct 2021 03:26:34 -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; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=HBIQ7Jv1; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230032AbhJNK0L (ORCPT + 99 others); Thu, 14 Oct 2021 06:26:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39846 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229912AbhJNK0K (ORCPT ); Thu, 14 Oct 2021 06:26:10 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 50016C061570; Thu, 14 Oct 2021 03:24:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=Fx9cLhN7mOpr+grnv3F8YGfL7yLYIEU/n5hQtUEVSyY=; b=HBIQ7Jv1D7PPTEog37ZzHEDdD4 fXw09We7EjdRG/JsM2auCONGNaJeVYxByvJTR0BBLKpQ50E0jtBIQ7oQQffEBpR9ZVVLPtqljJ8mV UeQqOkDFaU5AKBy/93IfRosKVg5rftVMdtvUtKocfd4a/yCtssToumA9HK42YLAG2zchyc6OzD29W TZD+lj0UpmmwgtcRMFDUk79nkNmdTdewozr/yxZmM+S2kwLrMfhug+3aK2WS962VeMVFclKDzGE4i mYIfeZ70gxEXEZ3S6iJZ5hy6+VvSJWqPRql0cEAiAN5VwrIhTaLUtfVC7Z8WdlVFsV1XiYhU8mWFt YnObZJxA==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1maxsY-008FhE-QL; Thu, 14 Oct 2021 10:22:38 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 59FB93001C0; Thu, 14 Oct 2021 12:22:26 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 45B2C2008CB91; Thu, 14 Oct 2021 12:22:26 +0200 (CEST) Date: Thu, 14 Oct 2021 12:22:26 +0200 From: Peter Zijlstra To: Sami Tolvanen Cc: x86@kernel.org, Kees Cook , Josh Poimboeuf , Nathan Chancellor , Nick Desaulniers , Sedat Dilek , Steven Rostedt , linux-hardening@vger.kernel.org, linux-kernel@vger.kernel.org, llvm@lists.linux.dev Subject: Re: [PATCH v5 01/15] objtool: Add CONFIG_CFI_CLANG support Message-ID: References: <20211013181658.1020262-1-samitolvanen@google.com> <20211013181658.1020262-2-samitolvanen@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20211013181658.1020262-2-samitolvanen@google.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Oct 13, 2021 at 11:16:44AM -0700, Sami Tolvanen wrote: > diff --git a/tools/objtool/arch/x86/decode.c b/tools/objtool/arch/x86/decode.c > index 1f2ae708b223..5fe31523e51f 100644 > --- a/tools/objtool/arch/x86/decode.c > +++ b/tools/objtool/arch/x86/decode.c > @@ -63,6 +63,23 @@ bool arch_callee_saved_reg(unsigned char reg) > } > } > > +unsigned long arch_cfi_section_reloc_offset(struct reloc *reloc) > +{ > + if (!reloc->addend) > + return 0; > + > + if (reloc->type == R_X86_64_PC32 || reloc->type == R_X86_64_PLT32) > + return reloc->addend + 4; > + > + return reloc->addend; > +} > + > +unsigned long arch_cfi_jump_reloc_offset(unsigned long offset) > +{ > + /* offset to the relocation in a jmp instruction */ > + return offset + 1; > +} > + > unsigned long arch_dest_reloc_offset(int addend) > { > return addend + 4; > diff --git a/tools/objtool/elf.c b/tools/objtool/elf.c > index b18f0055b50b..cd09c93c34fb 100644 > --- a/tools/objtool/elf.c > +++ b/tools/objtool/elf.c > @@ -575,6 +580,49 @@ static int read_rela_reloc(struct section *sec, int i, struct reloc *reloc, unsi > return 0; > } > > +/* > + * CONFIG_CFI_CLANG replaces function relocations to refer to an intermediate > + * jump table. Undo the conversion so objtool can make sense of things. > + */ > +static int fix_cfi_relocs(const struct elf *elf) > +{ > + struct section *sec; > + struct reloc *reloc; > + > + list_for_each_entry(sec, &elf->sections, list) { > + list_for_each_entry(reloc, &sec->reloc_list, list) { > + struct reloc *cfi_reloc; > + unsigned long offset; > + > + if (!reloc->sym->sec->cfi_jt) > + continue; > + > + if (reloc->sym->type == STT_SECTION) > + offset = arch_cfi_section_reloc_offset(reloc); > + else > + offset = reloc->sym->offset; > + > + /* > + * The jump table immediately jumps to the actual function, > + * so look up the relocation there. > + */ > + offset = arch_cfi_jump_reloc_offset(offset); > + cfi_reloc = find_reloc_by_dest(elf, reloc->sym->sec, offset); > + > + if (!cfi_reloc || !cfi_reloc->sym) { > + WARN("can't find a CFI jump table relocation at %s+0x%lx", > + reloc->sym->sec->name, offset); > + return -1; > + } > + > + reloc->sym = cfi_reloc->sym; > + reloc->addend = 0; > + } > + } > + > + return 0; > +} If that section ever gets modified and we end up running elf_rebuild_reloc_section() on it, we're in trouble, right? Do we want a fatal error in elf_rebuild_reloc_section() when ->cfi_jt is set?