Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp3307953imm; Thu, 17 May 2018 06:51:17 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqZNp0oP1R3Ed0gPGjmRt2v3bDZtg9HxKJtAEMy33e06lfFE28PgwBWXirxG9fB0YqYnXdc X-Received: by 2002:a17:902:7082:: with SMTP id z2-v6mr5207132plk.373.1526565077186; Thu, 17 May 2018 06:51:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526565077; cv=none; d=google.com; s=arc-20160816; b=GzCr/CUb5KmZPGof0PEOfsDfEaXhr4cD5jmKKP3UugVL6TtZYS4ojf23tQSipx6BcG TW2KNIPx4k/o+9iuKb4bwwdK7HpDUEBMMY00U5wXeAJvQDOhlOACFvk9QJrx9xqQTVg4 Ses/IoByhpBU2fMt4GbPVDsWPOnME2Wr9oJe1vOiaEvAxdJktBKklJJbPgMblh7bnwUX ikjgPvtZC4nzvatne+v8LFQXM4fccYgmFcz8GR4tMd/IHDr1fntFw74WrRjj8bZAYgyH K524NGOfhs7C2Bm+ow9sXSHHccIpY+Gozl19yYi6WVrwMaLjVpyRZne/Kq08XLNot5D0 MiQg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:arc-authentication-results; bh=NZ0kYXcQVzHq6F9TOBiKyqYc2Vd6zNkcKRAellYdQoU=; b=gAoagKs8KA7spirwn4DjqDmYTHp/2/UEiEsUGOPX8NLnfp7wm6hzv0B2znx3IV4dM7 jsN1W9tPYUSR9vLhCvyfLQWDxMM/K1Ehhcukul7yXLB2yg21dI5SzmvISKjqoN5hf36Y pulsEEaZS0fAdN1nuqh5NvOEm5XtvMyNW1E7blRAbcEQMtokJG7QOCMsVjUlnFXatDv7 3cv1/2R+qHcnrLX1lAntFesZV3rnNY64hG6vpv5SfS3SksQEULOOUnIDP3tDrUEdRXCH YrsZMwUsPLUU5z9PQ6SSWu7hFn2Zwgs8HrfbNmdx/scIluerm/dKDiRDqrApp63kBbi0 2i/w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t23-v6si4922165ply.237.2018.05.17.06.51.02; Thu, 17 May 2018 06:51:17 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752073AbeEQNtp (ORCPT + 99 others); Thu, 17 May 2018 09:49:45 -0400 Received: from mx1.redhat.com ([209.132.183.28]:44654 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751017AbeEQNtn (ORCPT ); Thu, 17 May 2018 09:49:43 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 79E8230BCED5; Thu, 17 May 2018 13:49:43 +0000 (UTC) Received: from treble (ovpn-120-21.rdu2.redhat.com [10.10.120.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9399E1001F40; Thu, 17 May 2018 13:49:41 +0000 (UTC) Date: Thu, 17 May 2018 08:49:34 -0500 From: Josh Poimboeuf To: Linus Torvalds Cc: Alexey Dobriyan , Peter Anvin , kernel test robot , Ingo Molnar , Thomas Gleixner , Andrew Lutomirski , Borislav Petkov , Brian Gerst , Denys Vlasenko , Peter Zijlstra , Linux Kernel Mailing List , Peter Anvin , tipbuild@zytor.com, LKP Subject: [PATCH] objtool: Detect assembly code falling through to INT3 padding Message-ID: <20180517134934.eog2fgoby5azq5a7@treble> References: <20180515080033.GA7714@yexl-desktop> <20180515210757.GA12225@avx2> <20180515214337.GA18021@avx2> <20180515222211.ods5hzne46hozojq@treble> <20180515224354.zmygmsnlqj5lrdbo@treble> <20180516033044.odb74pdgcn5nacwb@treble> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20180516033044.odb74pdgcn5nacwb@treble> User-Agent: NeoMutt/20180323 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Thu, 17 May 2018 13:49:43 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org With the following commit: 51bad67ffbce ("x86/asm: Pad assembly functions with INT3 instructions") ... asm function alignments are padded with INT3, so it's no longer safe to fall through to an aligned function. Make sure we catch any such cases with objtool. Note this only adds checking for 64-bit, since objtool doesn't support x86-32. Suggested-by: Thomas Gleixner Suggested-by: Linus Torvalds Signed-off-by: Josh Poimboeuf --- arch/x86/kernel/head_64.S | 2 -- tools/objtool/arch.h | 3 ++- tools/objtool/arch/x86/decode.c | 2 +- tools/objtool/check.c | 11 ++++++++++- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S index 8344dd2f310a..3ed8cec6e765 100644 --- a/arch/x86/kernel/head_64.S +++ b/arch/x86/kernel/head_64.S @@ -285,11 +285,9 @@ ENTRY(early_idt_handler_array) .endif pushq $i # 72(%rsp) Vector number jmp early_idt_handler_common - UNWIND_HINT_IRET_REGS i = i + 1 .fill early_idt_handler_array + i*EARLY_IDT_HANDLER_SIZE - ., 1, 0xcc .endr - UNWIND_HINT_IRET_REGS offset=16 END(early_idt_handler_array) early_idt_handler_common: diff --git a/tools/objtool/arch.h b/tools/objtool/arch.h index b0d7dc3d71b5..6eb058a8ac00 100644 --- a/tools/objtool/arch.h +++ b/tools/objtool/arch.h @@ -33,7 +33,8 @@ #define INSN_STACK 8 #define INSN_BUG 9 #define INSN_NOP 10 -#define INSN_OTHER 11 +#define INSN_PADDING 11 +#define INSN_OTHER 12 #define INSN_LAST INSN_OTHER enum op_dest_type { diff --git a/tools/objtool/arch/x86/decode.c b/tools/objtool/arch/x86/decode.c index 7e86a743f851..82b41bb93c02 100644 --- a/tools/objtool/arch/x86/decode.c +++ b/tools/objtool/arch/x86/decode.c @@ -421,7 +421,7 @@ int arch_decode_instruction(struct elf *elf, struct section *sec, case 0xcc: /* int3: used for asm function padding by the __ALIGN macro */ - *type = INSN_NOP; + *type = INSN_PADDING; break; case 0xe3: diff --git a/tools/objtool/check.c b/tools/objtool/check.c index f4bbce838433..4d387448519f 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -1936,6 +1936,14 @@ static int validate_branch(struct objtool_file *file, struct instruction *first, } return 0; + case INSN_PADDING: + if (!file->c_file) { + WARN_FUNC("code falls through to INT3 padding", + insn->sec, insn->offset); + return 1; + } + break; + case INSN_STACK: if (update_insn_state(insn, &state)) return 1; @@ -2032,7 +2040,8 @@ static bool ignore_unreachable_insn(struct instruction *insn) { int i; - if (insn->ignore || insn->type == INSN_NOP) + if (insn->ignore || insn->type == INSN_NOP || + insn->type == INSN_PADDING) return true; /* -- 2.17.0