Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp10073685rwb; Fri, 25 Nov 2022 00:16:08 -0800 (PST) X-Google-Smtp-Source: AA0mqf6TC8+9WEvV5B19lWKV8UH+usSisiqy2oTWdaHJvCWeCd5iojg/7nPTN6+u7lzw7N6kuvF1 X-Received: by 2002:aa7:cc08:0:b0:461:8a43:e93 with SMTP id q8-20020aa7cc08000000b004618a430e93mr32474596edt.275.1669364168108; Fri, 25 Nov 2022 00:16:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669364168; cv=none; d=google.com; s=arc-20160816; b=uDFioz13nk4hWIH1tMmdphuOp43fRKeHV+b4otFNynevEAxe+9B9woQt5y2TpGXjro fx8hsWBg75hgaeQOJI+9tyIAy0jTv1Xxff0d6QyZja8fCyVQoTIhUHs+4HBGQHOJiw1M H780d2Z4/qn3/KyLPR8/N/5de+nS+OrXMWW5yiDMWIPhhL7eHjC/yhsuMRTRT3+ODjVv y5M5o6L89Rq99ZNf9bQJRnS8n0qdGcYLlxDRCgO0IKO3W2nkgPChM1S4fAlPKjemlUF6 Jquv59fpENIQ5N3arhneH4LIy6lR9aBprtMoSVf+BnzOVGiMInSZiNwuyY7G2HJwAQZ0 913w== 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=8TV2H+mw2roghON9dZi8tjqa2D9zCsxjBsOv5fUqu44=; b=uqei0sWdI6eQetoBLmi6IUIAMfcdUChtIrxyhuXLOg8uT89PdVdl+UHSZw1VAwtyLq o3OLwlJSOhkseeXC6CUjF+/6XEvadNlC8Sa8PqM2Ed25b2Q67TdMODIm3jJla0ZbYTbd g87BUyCD9hdiMb+AKboS5W//HrueKfeskFpIV0BEoSJuj71F1TYjfb144qyQSzc7dUCd OtDq3TTOXGp4eHoqjTYoHww8VXnlDnn6BGoYQWDTiVG1M9xpbZsj9nn3x5gxc637aATt 7Hv2/nvatmCxJh5TMkvlCIljw1SccZ5Bwqx3A53eR0/WFzpIbhmN9Euus3ZdA1hGCKIC Xysw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=eiEI5OIf; 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 s27-20020a50ab1b000000b00461c9edc3a5si3053938edc.77.2022.11.25.00.15.45; Fri, 25 Nov 2022 00:16:08 -0800 (PST) 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=eiEI5OIf; 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 S229788AbiKYIAL (ORCPT + 87 others); Fri, 25 Nov 2022 03:00:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51418 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229628AbiKYIAG (ORCPT ); Fri, 25 Nov 2022 03:00:06 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9028A303D5; Fri, 25 Nov 2022 00:00:05 -0800 (PST) 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=8TV2H+mw2roghON9dZi8tjqa2D9zCsxjBsOv5fUqu44=; b=eiEI5OIfZpN2baAb5xqupaNWdT JusrNhWE3n/ggnWuzCJ0ElAOkkeZys1s0HHQe8iya1t/nqFkX4Ggn9NKO7MNAAM24Ci2iVd7kr9VK zqlsaAr+HyUUG4z+h+HLLIGa2FgQAUj4iqzSOQ/op2e3jHvABBy5AkcPUuOrF4fqCpxt8wU0qKV/f DQYw+9pyIv1yPSc+RO0O/VsImNwJG8GQ/ZQFdqpYLgu02+26haD97bFJ1Vij2izaVZoFF3Dmpsobp R8ON4Jf/rimYfwsPEpOKVH7m1y/mUxx1wiX8Z+ESCvx56NRqdfHE8+RHMMZgHOW6GUy6enZ8XI2UH Yt+Ynigw==; 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 1oyTcl-009Phg-38; Fri, 25 Nov 2022 07:59:51 +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 B703B300282; Fri, 25 Nov 2022 08:59:42 +0100 (CET) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 95BC62D52AC8A; Fri, 25 Nov 2022 08:59:42 +0100 (CET) Date: Fri, 25 Nov 2022 08:59:42 +0100 From: Peter Zijlstra To: Dmitry Safonov Cc: linux-kernel@vger.kernel.org, David Ahern , Eric Dumazet , Ard Biesheuvel , Bob Gilligan , "David S. Miller" , Dmitry Safonov <0x7f454c46@gmail.com>, Francesco Ruggeri , Hideaki YOSHIFUJI , Jakub Kicinski , Jason Baron , Josh Poimboeuf , Paolo Abeni , Salam Noureddine , Steven Rostedt , netdev@vger.kernel.org Subject: Re: [PATCH v6 1/5] jump_label: Prevent key->enabled int overflow Message-ID: References: <20221123173859.473629-1-dima@arista.com> <20221123173859.473629-2-dima@arista.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20221123173859.473629-2-dima@arista.com> 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 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 Wed, Nov 23, 2022 at 05:38:55PM +0000, Dmitry Safonov wrote: > 1. With CONFIG_JUMP_LABEL=n static_key_slow_inc() doesn't have any > protection against key->enabled refcounter overflow. > 2. With CONFIG_JUMP_LABEL=y static_key_slow_inc_cpuslocked() > still may turn the refcounter negative as (v + 1) may overflow. > > key->enabled is indeed a ref-counter as it's documented in multiple > places: top comment in jump_label.h, Documentation/staging/static-keys.rst, > etc. > > As -1 is reserved for static key that's in process of being enabled, > functions would break with negative key->enabled refcount: > - for CONFIG_JUMP_LABEL=n negative return of static_key_count() > breaks static_key_false(), static_key_true() > - the ref counter may become 0 from negative side by too many > static_key_slow_inc() calls and lead to use-after-free issues. > > These flaws result in that some users have to introduce an additional > mutex and prevent the reference counter from overflowing themselves, > see bpf_enable_runtime_stats() checking the counter against INT_MAX / 2. > > Prevent the reference counter overflow by checking if (v + 1) > 0. > Change functions API to return whether the increment was successful. > > Signed-off-by: Dmitry Safonov > Acked-by: Jakub Kicinski This looks good to me: Acked-by: Peter Zijlstra (Intel) What is the plan for merging this? I'm assuming it would want to go through the network tree, but as already noted earlier it depends on a patch I have in tip/locking/core. Now I checked, tip/locking/core is *just* that one patch, so it might be possible to merge that branch and this series into the network tree and note that during the pull request to Linus.