From patchwork Fri Jun 10 23:35:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sami Tolvanen X-Patchwork-Id: 12878201 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id F1204C433EF for ; Fri, 10 Jun 2022 23:38:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:References: Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=W449QCnkKwdo7g5CwbRyGVnw/shqqyKtEwuC+fNHB+A=; b=EH2jFJ0xmtuO+/LX7gt28H/qSH cUH8rz9Khw14rSelwvhQoAntaFqFPuZinQ635ZNAQo9SyBZzdEIJfBjsQGtO59wJUGGIzRg+BtdaQ VbVjugSL77kbciI12WU9Yt6PkEXj521uW0VhdHujYS3Goj6IktV8Lh6I8gslMXi9qIA8Qw8dVSlx/ QCF64odHP3qOg21Xvk9UUOUYhODWuj1ZBdwY/2t9YWAutEp5aYPBBH8mS9xK0Q1Cte6Kuvx1JM1WX pFoICPfCUQzHjOhOFOPTh728bp3rdQWhCTlTBslqP5ubPAzuxXgpD57vQhwYRgZf30FApRaDZqQE7 mjFwW3JQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nzoC0-00ARus-0D; Fri, 10 Jun 2022 23:37:28 +0000 Received: from mail-yb1-xb49.google.com ([2607:f8b0:4864:20::b49]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nzoA9-00AQtZ-KX for linux-arm-kernel@lists.infradead.org; Fri, 10 Jun 2022 23:35:34 +0000 Received: by mail-yb1-xb49.google.com with SMTP id m11-20020a25710b000000b0065d4a4abca1so535090ybc.18 for ; Fri, 10 Jun 2022 16:35:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=Km+SEqSQafJfKP/QlrO+B8JhEJgvv7t8sRyDHP36l7I=; b=tKyaaswHCvlF0Vka4hqQ38TU6ilg+rrQ78ebLnM4FfuhwM9T62lwgPgbZGmqVEK4z3 cppKegF45ke5Bs+5aNH1UKbxpiMYkuInpWbnpY7DO/3YzVl0pyC34AEvR3RqcqVH0ynn Lo39ZsRLQVWZBypDxoUefxGRbqHDhx7N4wCEphc1UNRG+7Vxt0GiDM2zX5iXiJkjUNJk 8U2JfGkl0crXRWKcnjZbMI74tRgBQM2TEIxfNJjl1gZ/BO3uud2jZowx8aMylpnZBiNc ysGG0G7dDodOPTiJ9tOnE33FKvabqAXEvds55FrKwiHhWkwqN5YeIuDC/0b745I5UivI kuNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=Km+SEqSQafJfKP/QlrO+B8JhEJgvv7t8sRyDHP36l7I=; b=HDkavc61hK8dYHoG+wWtBoYXRqeysvXn9I/P5pvms9Wx9x3Gbok/0wIntm2vg2XOD0 BrRvA+71LjIIbL/toW4gScTCqpjcz8iVCV+h0y7XURdMehqsT3UC2RWbnFszaBhErDfx fNPxCGR25N15YKuoI39OYU8pxjJSYBaDfyJcnrawNSZEW1QDmJj9E26IBuy3X13vO5SO mMFufAZt3Rq92xhw4d7HCtcS4lFsqE3XTjNWAXFAhWmjnXDQRBZ1apDwtyplsJilfo/d EaMGKPur9eIz2E5OPMXZGFvVnDlyx46GS77QTz/v9iqjM1RyD8HA+9jBLjkIpWygR3SC Agsw== X-Gm-Message-State: AOAM531+prhVORMoyUgqiH59l+MteNOrqyQURKQiO2AOC6UiWLu56Otd 9q72FzNBXrzRlE2q9+MHUB2VrmVlcx4rikCP3FU= X-Google-Smtp-Source: ABdhPJxTy6tFxXoRTEcHD2U7itiAk1UqgcbD+GIro5oZ65OOdagO9Y4G4JP7ObGMOyyys5QHvSTjQ2+w/U+BvS5EW7Q= X-Received: from samitolvanen1.mtv.corp.google.com ([2620:15c:201:2:f464:6db6:3d47:ed14]) (user=samitolvanen job=sendgmr) by 2002:a25:b904:0:b0:663:e71e:1916 with SMTP id x4-20020a25b904000000b00663e71e1916mr19474561ybj.117.1654904132211; Fri, 10 Jun 2022 16:35:32 -0700 (PDT) Date: Fri, 10 Jun 2022 16:35:00 -0700 In-Reply-To: <20220610233513.1798771-1-samitolvanen@google.com> Message-Id: <20220610233513.1798771-8-samitolvanen@google.com> Mime-Version: 1.0 References: <20220610233513.1798771-1-samitolvanen@google.com> X-Developer-Key: i=samitolvanen@google.com; a=openpgp; fpr=35CCFB63B283D6D3AEB783944CB5F6848BBC56EE X-Developer-Signature: v=1; a=openpgp-sha256; l=1572; h=from:subject; bh=jl9DoMc+4oRrqZLAq39OlbrQ/0d/T8NfhRiPohw7q0M=; b=owEB7QES/pANAwAKAUy19oSLvFbuAcsmYgBio9Ut8FBG9LlQYcuQASRpKpCEiZFqDFuo2OISqNmD PZHD7ayJAbMEAAEKAB0WIQQ1zPtjsoPW0663g5RMtfaEi7xW7gUCYqPVLQAKCRBMtfaEi7xW7htGC/ 9S64HtVNUNx8wUV9jEnq0eOMIRwIfRD2KvOlklON0r7+HT+G3Pc3gUkJCk10zTrCdF9O6RvedaSLQ1 /APpiaRGnwUDzGRmTSr52h8ENGvOZT91UiUJS4Yw2DGcde7NhGS1BuoTLxP4l7z6QKu5QRjQ6iMvbf NRG2A7T8qWteCX3yLVRGQqSwq3usqGFdb+pXAaSjumRGoRftE0xL3ac+4NC4xX+mH3548juVL43+Cw aHMxz7BmXUffA7onVHE1txP0Zgg0LFxpupHSuoUepfjBuWucPFc8S1ocJKoFoJSSV6pVwHkap5ABEO BWbEeGFkI/kwG2N6kjEIsvWU7SYxiBwkY6ZrU6SY0yr1QlEnSuIYgeihNeV/eezgPXpmEmLA3K2rOs k77a1zmGXN/DmKK0/SQ6tnXd8KBpEf1y+W+5D/S3Oxxc/2zfRRBUshgafKlNTufhcex9IWhrCQmgVo INo3nzmG8TKawDTcvMlv4YBLBK3gqIeVjCwmORqhDtl9Y= X-Mailer: git-send-email 2.36.1.476.g0c4daa206d-goog Subject: [RFC PATCH v3 07/20] 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220610_163533_728757_D51F11E4 X-CRM114-Status: GOOD ( 12.89 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.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 666a7f4bc137..b6b375112a2a 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);