Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp4747610rwe; Tue, 30 Aug 2022 16:34:43 -0700 (PDT) X-Google-Smtp-Source: AA6agR50Qt82ffxPqLcxE2/U40/yK46TiNIdjm/O/M5WJ/EfcZFJHIJSZ598/D/fladbyrvwYt0a X-Received: by 2002:a17:907:1c01:b0:6f4:2692:e23 with SMTP id nc1-20020a1709071c0100b006f426920e23mr18398160ejc.243.1661902483460; Tue, 30 Aug 2022 16:34:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661902483; cv=none; d=google.com; s=arc-20160816; b=a1KQIuFmh3ifGmMHXHWApxb2AIvse4/6ne2tx2wuAtkZ66YDBJjzrJVVfCiYfbsgTQ ycPEg4dmDDUkju1qLe+OJWWA5Y7DVX+18KxIAVorYi+zBigJLTXYiWuUVUI+gBDG85+2 OKXHvNW9S+1+AgY/BnxQGNZELsq+NKha92ZzpTOtQiICPsDzsYXOkhZmvp6cIUBXOwec slV5hsikTMktdfG16pczKXVOvmA2buwduU+y0yzth0K7aWoN5RmPVVDUI+8HTNhnfAe3 Ho209UocIqCN3JlMMDPsDbLugIyIGkgGE8rsTKQrrR8+qc1EZybyOZfyEA1BnjKXogkc HeBw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:dkim-signature; bh=stIJrjMqwQ0zAOFApEyjbwm3OExfLqdVzHQ/Ti/K+RQ=; b=VYlkhrJo2wE3H0GIFZgy7xN6gKmwORbKMbPCypX/KspH4R+R750LJzwH4st0RMlQ/c jsrt/plWtlOqswKF1JQVoQZs9sYQA2eOndGNYYSUHFx6zU16SfxmmWDuVr0/oA0QdbsG uJzb0IqQ3eTCqDtZa7rOBCZA/+FupVK8NLpR/jlNx52U59nksv1e36S9tH7wAyOYzCFc iYDw6bWJqmM4LAp+fU9q0RWc4YbtvBPUwZBSfMGg9DM9PYtM1Lkxtu0pmAQRH3fzIfj1 kZfkqgOmteEesEmn2/L4rlP7xZTinKodVYm5vIN0PLkEf4qHynYW4zc49MLoHX0iPWTs KKDA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=XT3FqCUj; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l4-20020a1709060e0400b0073d9daaf4f3si9074617eji.693.2022.08.30.16.34.18; Tue, 30 Aug 2022 16:34:43 -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=@google.com header.s=20210112 header.b=XT3FqCUj; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232195AbiH3XcW (ORCPT + 99 others); Tue, 30 Aug 2022 19:32:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42368 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232046AbiH3Xb6 (ORCPT ); Tue, 30 Aug 2022 19:31:58 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0BE7B72FE5 for ; Tue, 30 Aug 2022 16:31:53 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id f12-20020a25b6cc000000b0069a9e36de26so875610ybm.16 for ; Tue, 30 Aug 2022 16:31:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc:subject:date; bh=stIJrjMqwQ0zAOFApEyjbwm3OExfLqdVzHQ/Ti/K+RQ=; b=XT3FqCUj0oWltSKyz0DMYCdz3zG/R+ch6PgREyusoybVfYnjSIIp1QEVmgkw27BMRj 1bwaWQRauXjRVmhR+FXatY3cAFgTFdHOwv4MeNRe9viWmXCdGh3ZqgTqK/bonGIUbUm2 nzVQrEYCIwgQuRvzHL9weunLc+sqBtMBzhAT8qbEtdumA2TqedCJySqMrqa0Xf9T3VwZ xs9JxjNj3lR1umlvKCUf9SNYAvbTD4J4ebt11ivYnN3e4XZbiJ9Vkff0l7aHJfuG01re yOHwdfZzJCRQzCio9+FrwTtHBU/fAgGor0fUpdX6v+iYm5fuK07woR5EljmpbadzEdVA zmtA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date; bh=stIJrjMqwQ0zAOFApEyjbwm3OExfLqdVzHQ/Ti/K+RQ=; b=I7+AaBoS6PEbD/UVqx5Zdx8D3BwzBRUGzIaCMF8/H763UqyH/Zi1nLft/KWuVrXV9b PD+pTRLkdOad7o54hY4qvQI7fClx7sDoUh/MtpDlH62xBSYWqW/1SneA75W5gCqYx/sb OppAfUqzRMK6ClUoXAeCNV10dnlh+talNIm2MGeUJX2UtqpJ0ERlZTi5ly8/vS7zPKO1 gEYL5KnVtrrcZiNVZbJQnAXxySJddTDKito80CFIhBZUcSAbjfMtzh7/geky8XN4E602 ySQik7QwXw0/EEj4hirihGyJHlpGLPFY5CyWnoobxFRCnHJTnXpuEkuy+g082d5EEozj 2c4Q== X-Gm-Message-State: ACgBeo3DvIQZNXvuw5fWeQt6Os9z3uoWK8Et1qWgz4aZiSGW4JAxyKAR mrGfn9gGb8IVmF8SbdofsfJ/D0qhafRl2YnZ7w+vXpu1YhrJ2fKaCaOePszrSV1922rJB/BFHRl hwbpGJ7KQZ0lyA3plVuZuxx4UwssoGFf9/1na+lRoHeg73eR/lG6XvEvcO38ZEpgCVpLxViGbsF 8p4hkAouO64Q== X-Received: from samitolvanen1.mtv.corp.google.com ([2620:15c:201:2:54d9:7143:6a7d:91d]) (user=samitolvanen job=sendgmr) by 2002:a81:8803:0:b0:341:6235:8cbe with SMTP id y3-20020a818803000000b0034162358cbemr7018693ywf.146.1661902312128; Tue, 30 Aug 2022 16:31:52 -0700 (PDT) Date: Tue, 30 Aug 2022 16:31:15 -0700 In-Reply-To: <20220830233129.30610-1-samitolvanen@google.com> Message-Id: <20220830233129.30610-8-samitolvanen@google.com> Mime-Version: 1.0 References: <20220830233129.30610-1-samitolvanen@google.com> X-Developer-Key: i=samitolvanen@google.com; a=openpgp; fpr=35CCFB63B283D6D3AEB783944CB5F6848BBC56EE X-Developer-Signature: v=1; a=openpgp-sha256; l=1674; i=samitolvanen@google.com; h=from:subject; bh=qxVnlSZocW9/1UypXlLGEHXfm4CDzclNhcl/lJ18fGo=; b=owEB7QES/pANAwAKAUy19oSLvFbuAcsmYgBjDp3M7+6Z3E3yWx3lSnRphzF4/3RQHI2psdANcTX1 DniQSb2JAbMEAAEKAB0WIQQ1zPtjsoPW0663g5RMtfaEi7xW7gUCYw6dzAAKCRBMtfaEi7xW7vYpC/ wJyHxmthaRukbl+m+7vClm87xKX81E51zW8v/dmnTAiBQ7oT1Ek1XR7SJo/50PfceCBcZ366Psr6wx L7143nIwKv3bXT4p97cRjwxu4M0m8HvXeZYxX2Xqsc6uerduxtDTzFjDPWA8VsVsVXpIN5BluFq//1 Jx120TP9+6zYwQsOBpMcJCq2cr+LMVUG0pX2qqLSJGAE1+2yoL2kBisWcIdDxS1jJ5266S/HoYqktz JO/BzYSjJqxWmTxt2M4SzxDHm1EgNjsm5ntVO+KRW+klcvF2/1A+hyopJ1c+SrByL7fc/WNq8q15Gu rS6sXoG21TAT7q0EBWR2GYae6G6d/o1Sn1DTQpzi+TfRj8zYXkDPGgdxdflelIoodZ3g3q/vf2hzCC Y6S35Cpa4ek9uS8PsTuYFkYecoZCw/xrq+x1R6KPGpwl3/NAuYPWxv8goJ10UY0hjOxJby0LDXRouv cp8+PZmKAqFAjGeoHcRcLyUkHJSTY52q00bcKiCKHOdz8= X-Mailer: git-send-email 2.37.2.672.g94769d06f0-goog Subject: [PATCH v4 07/21] lkdtm: Emit an indirect call for CFI tests From: Sami Tolvanen To: linux-kernel@vger.kernel.org Cc: Kees Cook , Josh Poimboeuf , Peter Zijlstra , x86@kernel.org, Catalin Marinas , Will Deacon , Mark Rutland , Nathan Chancellor , Nick Desaulniers , Joao Moreira , Sedat Dilek , Steven Rostedt , linux-hardening@vger.kernel.org, linux-arm-kernel@lists.infradead.org, llvm@lists.linux.dev, Sami Tolvanen Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL autolearn=unavailable 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 Clang can convert the indirect calls in lkdtm_CFI_FORWARD_PROTO into direct calls. Move the call into a noinline function that accepts the target address as an argument to ensure the compiler actually emits an indirect call instead. Signed-off-by: Sami Tolvanen Reviewed-by: Nick Desaulniers Acked-by: Kees Cook --- drivers/misc/lkdtm/cfi.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/drivers/misc/lkdtm/cfi.c b/drivers/misc/lkdtm/cfi.c index 71483cb1e422..5245cf6013c9 100644 --- a/drivers/misc/lkdtm/cfi.c +++ b/drivers/misc/lkdtm/cfi.c @@ -20,6 +20,13 @@ static noinline int lkdtm_increment_int(int *counter) return *counter; } + +/* Don't allow the compiler to inline the calls. */ +static noinline void lkdtm_indirect_call(void (*func)(int *)) +{ + func(&called_count); +} + /* * This tries to call an indirect function with a mismatched prototype. */ @@ -29,15 +36,11 @@ static void lkdtm_CFI_FORWARD_PROTO(void) * Matches lkdtm_increment_void()'s prototype, but not * lkdtm_increment_int()'s prototype. */ - void (*func)(int *); - pr_info("Calling matched prototype ...\n"); - func = lkdtm_increment_void; - func(&called_count); + lkdtm_indirect_call(lkdtm_increment_void); pr_info("Calling mismatched prototype ...\n"); - func = (void *)lkdtm_increment_int; - func(&called_count); + lkdtm_indirect_call((void *)lkdtm_increment_int); pr_err("FAIL: survived mismatched prototype function call!\n"); pr_expected_config(CONFIG_CFI_CLANG); -- 2.37.2.672.g94769d06f0-goog