Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp35636649rwd; Mon, 10 Jul 2023 10:10:37 -0700 (PDT) X-Google-Smtp-Source: APBJJlFr4g/IMapf0fBT0ehSKnVVAPHmg3zWYvgpDgAGVE3yfqk6UZ34mXgRdrEmDSn5vbcKVmtV X-Received: by 2002:a05:6358:7e82:b0:134:d66c:b027 with SMTP id o2-20020a0563587e8200b00134d66cb027mr12782331rwn.22.1689009037628; Mon, 10 Jul 2023 10:10:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689009037; cv=none; d=google.com; s=arc-20160816; b=P5cCZTGm3Kzn0MGxmyRbkblned9avJ/JNdQ1cMU4TRemhKqQjBueWpqP/JNoENk0Oe /J/8r0X6IhUh4dwUb9qm5FQdqsfv44NOImN2vTF9kAw6GHtNtIApAkkupfLOVOQDWvSD D3EboB4jY/Y3jINn2qUDItQ0RFR0biTaZsNUny6E4KgvzAN+Mcxa6wKml0QQbsP15L5/ PgG4gZG9rR4nB14flUV3MI0kN2geci3cCwa6hM5Yk4ocNoO3dVYUNpi2d4ta5KjEcBpA Gzg7b3H3Xhv1FTyVySTTNWhfqs6BAUxANTDc6QYrwUYDE/GjeiW9oUUUp6iox17vU+YL vXhQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=o/ehgTocRh8PtfBK/UyzCrWNPNCGdZG+dLn8RGUzHow=; fh=1Uzs878Ge4EpSCEzsuudeoptg5+hwhacbJywLgApV1M=; b=f/eF11EGN5IpgXO3QupHhA4EwTKKeQA1/gxV1SAO/rw7CqvNEKXV4JIFIqyx2t7IOp +thkPuR9GJ5/4JJ5XAgEjR9MjB/PWkIqugZ/4R2TvP55xnDOVtG3T3NIRlp4jRVDAcGs BdZdplEWCLxJ3u1e/5JuecZ5Wf6tsZSvOscjLz3OyThOoH6OSG7JMWAApv+7IN9an01x 23PamLRxmoi1Qs8Uz4W746/CD8UQR4nx0mLnOCK+0Muaglt7QBp3X3LG05jnBYMG8i8V xpuukRQkwT7DLxNhZ9lp3N9RR/QnyKPnDjLloW/90zeHVucT3IIIvk3PnonT1sAPJ2hq 9CSg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=fl7piA8C; 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 5-20020a630f45000000b00553854417d8si9335573pgp.617.2023.07.10.10.10.24; Mon, 10 Jul 2023 10:10:37 -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=@infradead.org header.s=casper.20170209 header.b=fl7piA8C; 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 S229595AbjGJQVR (ORCPT + 99 others); Mon, 10 Jul 2023 12:21:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37200 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229469AbjGJQVQ (ORCPT ); Mon, 10 Jul 2023 12:21:16 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AE93E11F; Mon, 10 Jul 2023 09:21:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=o/ehgTocRh8PtfBK/UyzCrWNPNCGdZG+dLn8RGUzHow=; b=fl7piA8CKhbdAICst5HXBpJ1Ca UgLFxqYkeiIkabyFc9DM/4cNa8urEJws1pGpFIVZQFaYMgzCeRjjN86B5c7FE1Zi0r0wkdauLtB0R 1K0StFLS6BRvsqnmUbZaA7kXHWoOZdJAT+9tAWz4sFucJAO2HeyVk85zNqaZYhjjdjpAAqWbGGn6y chi01CVAB/uXvBBUUZLiMYwYiJNZJONLEbGRvhdIdPBqdr/YzXdF22AS7ItWeJxJxQDQMGfqnaYMO VxsqahMbu5NqLs2Ar696eRP0xIKNJrO5rPbItddQLpoVG2QDhDGi9LgI8dn+USe8daIK8QM9giOPG kfkeT4rA==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1qItdK-00EkJA-SJ; Mon, 10 Jul 2023 16:21:06 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 746A43004AF; Mon, 10 Jul 2023 18:21:06 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 5B54E2B3B25DF; Mon, 10 Jul 2023 18:21:06 +0200 (CEST) Date: Mon, 10 Jul 2023 18:21:06 +0200 From: Peter Zijlstra To: "Masami Hiramatsu (Google)" Cc: Petr Pavlu , tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, hpa@zytor.com, samitolvanen@google.com, x86@kernel.org, linux-trace-kernel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [RFC PATCH 2/2] x86/kprobes: Prohibit probing on compiler generated CFI checking code Message-ID: <20230710162106.GC3040258@hirez.programming.kicks-ass.net> References: <168899125356.80889.17967397360941194229.stgit@devnote2> <168899127520.80889.15418363018799407058.stgit@devnote2> <20230710161643.GB3040258@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230710161643.GB3040258@hirez.programming.kicks-ass.net> X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE 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 On Mon, Jul 10, 2023 at 06:16:43PM +0200, Peter Zijlstra wrote: > diff --git a/kernel/cfi.c b/kernel/cfi.c > index 08caad776717..2656e6ffa013 100644 > --- a/kernel/cfi.c > +++ b/kernel/cfi.c > @@ -31,16 +31,22 @@ static inline unsigned long trap_address(s32 *p) > return (unsigned long)((long)p + (long)*p); > } > > -static bool is_trap(unsigned long addr, s32 *start, s32 *end) > +static long cfi_trap_distance(unsigned long addr, s32 *start, s32 *end) > { > + long dist = LONG_MAX; > s32 *p; > > for (p = start; p < end; ++p) { > - if (trap_address(p) == addr) > - return true; > + long d = trap_address(p) - addr; > + > + if (abs(dist) < abs(d)) { Not that I expect anybody will care, but that should obviously be: abs(d) < abs(dist) > + dist = d; > + if (dist == 0) > + return 0; > + } > } > > - return false; > + return dist; > }