From mboxrd@z Thu Jan 1 00:00:00 1970 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C1E8FC43219 for ; Fri, 25 Nov 2022 14:28:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229951AbiKYO2m (ORCPT ); Fri, 25 Nov 2022 09:28:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51470 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229633AbiKYO2k (ORCPT ); Fri, 25 Nov 2022 09:28:40 -0500 Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 098811FF8D for ; Fri, 25 Nov 2022 06:28:39 -0800 (PST) Received: by mail-wr1-x42e.google.com with SMTP id v1so6988182wrt.11 for ; Fri, 25 Nov 2022 06:28:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=arista.com; s=google; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=lS8stYG6Frvb/BGcJu8YF7/dhbrkHyksUpy1OUW/W8o=; b=iLf+bm0YWyEWyekYREpUElP51zBlNPaWDVomF+ugXXNHI3HoMojdsP6OWb0Kxvp9Ql 20w/dpa2zHvxucLayRJvwCeb2lun3jvwNqiyQMzC91Mq0xxEFkNg1ncxxZmJgGSrnoct X8OIjqy3UwAkHd7od/eH9KDYIM8FSEmDZLizmfC3p8KeDgALXR22qkMFcQ6y4PeKFynJ MiZp2L25QPylIW0RBjT5OXz6yiLQAUqnOriavIvmC4EolycVfTVv7TL3KRcsBDLqeK5n NIqpykWn2GPyycoRO+hr9tsclBO75uNdAyxfUH1ug6I7WIECa8CtQYGGXtfgvf/jOEJ1 LIfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=lS8stYG6Frvb/BGcJu8YF7/dhbrkHyksUpy1OUW/W8o=; b=C3FwUvhzyd0HSAO0jECwwppCFzVMU88UqnA26tzsvq6UgM/vfQqHr3GmjsKADOjT/I zaB1igNRauZpqLcsDK4hYF71SH/GqHX1nsLyqaS4bUbu2O0NPsSR70JaW4OH3f1St+gE Ptgd3ulehxytfCuI42fGwolFGSOVwkPY0PTN38XMn3+isjRRhc7V+vae421LsjT1xhzN YhA+C6rnhrY4AqtbWaSpW5zjRcaBJ61CissgdZRXpBtAQCVuTdA4HL8oOuntU6y8ibsr xpDpN7YwZHGyEhpy8LV4eYKxg8/Mb5uudUznDj9OOkR/Jj1pvpbEG8jo4A0GoUbZtQ7m ccOw== X-Gm-Message-State: ANoB5pl1YbwYJRYY5YRt0d+E71+9GvDX6vNP4ypTikLMN1K4x1vPzvwf ai6IXPJx3rpUSRsOaYCVpTIPww== X-Google-Smtp-Source: AA0mqf7/pzzluGnCKQmm11BgI3tTNO02+C6KE6GeTiLRxeEFih/UD+ZhHhtfmgjjuNIHGli1CuGCOw== X-Received: by 2002:a5d:5187:0:b0:242:5ef:ce32 with SMTP id k7-20020a5d5187000000b0024205efce32mr2320626wrv.260.1669386517472; Fri, 25 Nov 2022 06:28:37 -0800 (PST) Received: from [10.83.37.24] ([217.173.96.166]) by smtp.gmail.com with ESMTPSA id e5-20020a05600c4e4500b003b492753826sm5249548wmq.43.2022.11.25.06.28.35 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 25 Nov 2022 06:28:36 -0800 (PST) Message-ID: <2081d2ac-b2b5-9299-7239-dc4348ec0d0a@arista.com> Date: Fri, 25 Nov 2022 14:28:30 +0000 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.5.0 Subject: Re: [PATCH v6 1/5] jump_label: Prevent key->enabled int overflow Content-Language: en-US To: Peter Zijlstra , Eric Dumazet , Jakub Kicinski Cc: linux-kernel@vger.kernel.org, Ard Biesheuvel , Bob Gilligan , Dmitry Safonov <0x7f454c46@gmail.com>, Francesco Ruggeri , Hideaki YOSHIFUJI , Jason Baron , Josh Poimboeuf , Paolo Abeni , Salam Noureddine , Steven Rostedt , netdev@vger.kernel.org, "David S. Miller" , David Ahern References: <20221123173859.473629-1-dima@arista.com> <20221123173859.473629-2-dima@arista.com> From: Dmitry Safonov In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 11/25/22 07:59, Peter Zijlstra wrote: > 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) Thank you, Peter! > 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. I initially thought it has to go through tip trees because of the dependence, but as you say it's just one patch. I was also asked by Jakub on v4 to wait for Eric's Ack/Review, so once I get a go from him, I will send all 6 patches for inclusion into -net tree, if that will be in time before the merge window. Thanks again for the review and ack, Dmitry