Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp502900rwi; Tue, 18 Oct 2022 22:01:03 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6v4cAhgoAFc2H6Ia8m5yTZvLM6zQf2OtpOcyedCYOpyDZRAdYBeDWhPvDMKMfw7lD520Th X-Received: by 2002:a17:902:c412:b0:180:6445:8894 with SMTP id k18-20020a170902c41200b0018064458894mr6473662plk.133.1666155663425; Tue, 18 Oct 2022 22:01:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666155663; cv=none; d=google.com; s=arc-20160816; b=mTsOMhf7yg58ASneroKICX1wW6QOeIL21qUDxG2q2RkPJ6VMTIKzgHxUUmOKbwtYeA fGGkROVVI6AqXuwxVu5g2xXkvtGma3vRe1L/EVtHAutyVG8MrG1zL9sdlWc14W1T+DW6 qkgYwgd4ks5kof82GoODgiMOnVyirg9gDlGB7sQxUiP/Qa3Dk6QvCoFNjfp70HOpiviu GRHsCgdtWRVwDBzXmVO6rV1lY2SdajeZnlyhfUU+xj7uacMDRGkRSCNSLWgcqRscsQX4 HtuN7qiR2VIZq3yX9ByaP382UGtiz8AQ/8zDIm5cGimlFcTXPGJVXKl2m3XhIBoBm8NN ZRNg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:message-id:references :in-reply-to:subject:cc:to:from:date:mime-version; bh=xiB1R2f3MtUy35K588H2Y4tXar/380ZLf16L0f1Q9/g=; b=UkPylYvvJXf1THD1ji6E5V6lbv/az5FGQt3s9vvXJVFfrm6NrKwgIoRqbng7RbTzia QJs1YoVjBWyWYKYdkb/2IhJT0zvQ0/vYZr6rrjqWf8X20RcOK2iNqGAFdKBZIO2lZSh4 NRCRsht/QqRf4uDFa5EfNE61MK3MEXNDNbpXxn4O3cMIi/ZsdMvOzFvVS/AMd2i6Gw9C oFCqUpecOoGrJlt2n533BZFlqTbSL7igxempEgtsXrtTVjOZteqOuIajOX+qQUgddHwT PEC2QNGov4YDwAXciWnH/t9G0jXvyZPkjgOs1NqV+kvMrHOlft4gqmA5f6MOpwNZ59Ou My/A== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x69-20020a638648000000b0043cab865857si16484057pgd.250.2022.10.18.22.00.50; Tue, 18 Oct 2022 22:01:03 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229755AbiJSEss (ORCPT + 99 others); Wed, 19 Oct 2022 00:48:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53740 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229722AbiJSEsr (ORCPT ); Wed, 19 Oct 2022 00:48:47 -0400 Received: from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net [217.70.183.196]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1C72B57BC7 for ; Tue, 18 Oct 2022 21:48:45 -0700 (PDT) Received: (Authenticated sender: joao@overdrivepizza.com) by mail.gandi.net (Postfix) with ESMTPA id 500D6E0003; Wed, 19 Oct 2022 04:48:42 +0000 (UTC) MIME-Version: 1.0 Date: Tue, 18 Oct 2022 21:48:42 -0700 From: Joao Moreira To: Peter Zijlstra Cc: Kees Cook , x86@kernel.org, Sami Tolvanen , linux-kernel@vger.kernel.org, Mark Rutland , Josh Poimboeuf Subject: Re: [PATCH] x86/ibt: Implement FineIBT In-Reply-To: References: <202210181020.79AF7F7@keescook> Message-ID: X-Sender: joao@overdrivepizza.com Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,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 >> Is it useful to get the compiler to emit 0xcc with >> -fpatchable-function-entry under any circumstance? I can probably >> change >> that quickly if needed/useful. > > Having it emit 0xcc for the bytes in front of the symbol might be > interesting. It would mean a few kernel changes, but nothing too hard. > > That is, -fpatchable-function-entry=N,M gets us N-M bytes in at the > start of the symbol and M bytes in front of it. The N-M bytes at the > start of the function *are* executed and should obviously not become > 0xcc (GCC keeps them 0x90 while LLVM makes them large NOPs). Uhum, all makes sense. I drafted something here: https://github.com/lvwr/llvm-project/commits/joao/int3 Let me know if this works for you or if there is something that should be tweaked, like adding a specific flag and such. This currently emits 0xcc instead of 0x90 for the nops before the function entry symbol for kernel code on x86-64. It seems to be working (see generated snippet below), but let me know otherwise: Generated with -fpatchable-function-entry=10,5 Disassembly of section .text: 0000000000000000 : 0: cc int3 1: cc int3 2: cc int3 3: cc int3 4: cc int3 0000000000000005 : 5: 0f 1f 44 00 08 nopl 0x8(%rax,%rax,1) a: 41 57 push %r15 c: 41 56 push %r14 ...