Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp662529pxb; Fri, 16 Apr 2021 15:11:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJySq9TOeVPx1d0AjqpLMdzV+D72Pi+9X/3CQs7bLD37DpNivx9HtW6ZT2uBoEj1qnhjpUJK X-Received: by 2002:a17:906:ece1:: with SMTP id qt1mr10582931ejb.385.1618611080769; Fri, 16 Apr 2021 15:11:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618611080; cv=none; d=google.com; s=arc-20160816; b=NXaD5tZRV0ajHsfSCGpNwOpKzX7OeY1usguAtKcu8WADaTMFdgFVPeuPlXhstFoFoC igrhx84Ub2MZ62BLVrOgKEpATrGRIp7FOERPVBD/tg7g96X/53tayh49zBfAyJFqWEDU bsKDOumTMA6AfBlCI0oxGeB/4OV+/1qFEyE2r4F/qqKOCUH9XQsnx0tFp1KC8pBKBBwB toJG6J78E9X34M01VkXe34VV2MMNp0j+5XvSS+LcJuA3fFInoicn606pxbLqQpb6Jk20 K0pFq/EiikN2wUWFhx5F4r6FjUktw6H8KqjC0PQD/+KKJE8fbsnLsLzI1rafhBhYWWuN gDvA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=KvvOpfTc4a7owgj9qx4TrZM/bIZMtNXq+vl9JoXOzqI=; b=cZCzepoWNe3muweq3L2EILABsh+yMpIzjiPWz2i52U/jzjvE57Nv2pe4E4D8MWnGp8 x5EanSYLdCmdoZdyLyBHmE5LUaqgG14E+pbmVLlprM4hm/T6YPdVtR6IbPlNLv809Rzy 2+C3uR/v0Ek3D8miE83jHPFej9AKY/KbooUkK/BYRrBSXUPBFZP1HaLyNEXuWzYUny6r 4mtnfSJreQp4aZkrIFtkYGjfLhp/Y18D2DakgBkLRA5zaCe+wfxOXxP724wgyUFJ3Och P4ETDk/CukTG97PlCI3qE0anvyqWRqZthGX2bjQswiAbah1jD3IkdLyWZIJaRfOzeSjs uCcQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=nuw2AQJB; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b32si3528316edf.305.2021.04.16.15.10.57; Fri, 16 Apr 2021 15:11:20 -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=@google.com header.s=20161025 header.b=nuw2AQJB; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234774AbhDPVuB (ORCPT + 99 others); Fri, 16 Apr 2021 17:50:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56792 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233514AbhDPVuB (ORCPT ); Fri, 16 Apr 2021 17:50:01 -0400 Received: from mail-yb1-xb2f.google.com (mail-yb1-xb2f.google.com [IPv6:2607:f8b0:4864:20::b2f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E82B5C061756 for ; Fri, 16 Apr 2021 14:49:35 -0700 (PDT) Received: by mail-yb1-xb2f.google.com with SMTP id v72so10976518ybe.11 for ; Fri, 16 Apr 2021 14:49:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=KvvOpfTc4a7owgj9qx4TrZM/bIZMtNXq+vl9JoXOzqI=; b=nuw2AQJBvaPpIDkYxZ/NyiGn3Xw6BAmH4ZACrt503WkvveO2ZmrQs/l6tkL2yvPVOs ZfcRm33b3c9vz4ZxWDxFUqbT+sQQ6IsdNl+w3TxlNYqQsTT3RRW4HyOIZU5pSBODCmS7 Q7lSFc+1pQ77Sf9LxHdw4amSSaWYCK8Zo7nZBvru2a8ueqopVz5Evp3DMTn7ugiyrIuq egnoGaWRynQP8dCEVHpHHJC4VP0ylIco0Aky6JicnvJXX0G0t3Jm1FOt4ySjIEGKPAmF vKKfcVX/FD245FrBxXtFFXQ5HqG63Xe+H9MLVOj8HV2l6oXmpR+Wo27tqSQHVtUg51t9 /w0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=KvvOpfTc4a7owgj9qx4TrZM/bIZMtNXq+vl9JoXOzqI=; b=ttF0EJdxJVj79J43D+ic2rLMwj5FaODDd1UjZLUOST9ssTUGNUKYQXzfY1qac5jMEu /lZh9Jf1bwlA3JmU8/UsP9jpyhntRG83RtNIsWtlA+OWBHU7Mvlc7VeygiMBiqOB0/Ek TLp48/gb+p/oM3q8b+ChWNckttvG1Uebr0r2WjXcy1QWMSsi9N0ZpxBqubV8+3E5QZ0c QYRGRt6t0DAdkEAci79/hTl7NFcq1m7gBafJypXdJPb/OzK/u063n8LLR5cBMvceQz9g UlysAZiVD4/Xb5KD57IQ5ZWrm79CZ0aens79iQoCkQ52TpW1QRtTVMnzz5HXUzEAKYGp g67w== X-Gm-Message-State: AOAM533WUIjK0pVuCpa3Wj72R+1bxY/pudK2tuYxV2DKPewfYnbPhjrD eBZKJ6c5RfhlgyLzEjZy2x9DrbNDyGTaV7+wG7vPlg== X-Received: by 2002:a25:7085:: with SMTP id l127mr1733643ybc.293.1618609774803; Fri, 16 Apr 2021 14:49:34 -0700 (PDT) MIME-Version: 1.0 References: <20210416203844.3803177-1-samitolvanen@google.com> <20210416203844.3803177-6-samitolvanen@google.com> <20210416211855.GD22348@zn.tnic> In-Reply-To: <20210416211855.GD22348@zn.tnic> From: Sami Tolvanen Date: Fri, 16 Apr 2021 14:49:23 -0700 Message-ID: Subject: Re: [PATCH 05/15] x86: Implement function_nocfi To: Borislav Petkov Cc: X86 ML , Kees Cook , Josh Poimboeuf , Peter Zijlstra , Nathan Chancellor , Nick Desaulniers , Sedat Dilek , linux-hardening@vger.kernel.org, LKML , clang-built-linux Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Apr 16, 2021 at 2:18 PM Borislav Petkov wrote: > > On Fri, Apr 16, 2021 at 01:38:34PM -0700, Sami Tolvanen wrote: > > With CONFIG_CFI_CLANG, the compiler replaces function addresses in > > instrumented C code with jump table addresses. This change implements > > the function_nocfi() macro, which returns the actual function address > > instead. > > > > Signed-off-by: Sami Tolvanen > > --- > > arch/x86/include/asm/page.h | 14 ++++++++++++++ > > 1 file changed, 14 insertions(+) > > > > diff --git a/arch/x86/include/asm/page.h b/arch/x86/include/asm/page.h > > index 7555b48803a8..5499a05c44fc 100644 > > --- a/arch/x86/include/asm/page.h > > +++ b/arch/x86/include/asm/page.h > > @@ -71,6 +71,20 @@ static inline void copy_user_page(void *to, void *fr= om, unsigned long vaddr, > > extern bool __virt_addr_valid(unsigned long kaddr); > > #define virt_addr_valid(kaddr) __virt_addr_valid((unsigned long)= (kaddr)) > > > > +#ifdef CONFIG_CFI_CLANG > > Almost every patch is talking about this magical config symbol but it > is nowhere to be found. How do I disable it, is there a Kconfig entry > somewhere, etc, etc? As I mentioned in the cover letter, this series is based on linux-next. I forgot to include a link to the original patch series that adds CONFIG_CFI_CLANG, but I'll be sure to point to it in the next version. Sorry about the confusion. > > +/* > > + * With CONFIG_CFI_CLANG, the compiler replaces function address > > + * references with the address of the function's CFI jump table > > + * entry. The function_nocfi macro always returns the address of the > > + * actual function instead. > > + */ > > +#define function_nocfi(x) ({ \ > > + void *addr; \ > > + asm("leaq " __stringify(x) "(%%rip), %0\n\t" : "=3Dr" (addr)); = \ > > + addr; \ > > +}) > > Also, eww. > > It seems all these newfangled things we get, mean obfuscating code even > more. What's wrong with using __nocfi instead? That's nicely out of the > way so slap that in front of functions. __nocfi only disables CFI checking in a function, the compiler still changes function addresses to point to the CFI jump table, which is why we need function_nocfi(). > Also, did you even build this on, say, 32-bit allmodconfig? > > Oh well. > > In file included from ./include/linux/ftrace.h:22:0, > from ./include/linux/init_task.h:9, > from init/init_task.c:2: > ./include/linux/ftrace.h: In function =E2=80=98ftrace_init_nop=E2=80=99: > ./arch/x86/include/asm/ftrace.h:9:40: error: implicit declaration of func= tion =E2=80=98function_nocfi=E2=80=99 [-Werror=3Dimplicit-function-declarat= ion] This is defined in linux-next, but I do see another issue, which I'll fix in v2. Note that CFI_CLANG itself cannot be selected on 32-bit x86. Sami