Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp10746890rwb; Fri, 25 Nov 2022 07:25:20 -0800 (PST) X-Google-Smtp-Source: AA0mqf6CyQECJtpcaygI/EhMZd9XJutPWzFlDChhy3Au/1a6hxt40zuZOVVQeTov5AbTw1yICEKJ X-Received: by 2002:a05:6a00:4186:b0:56b:a9bd:ee5f with SMTP id ca6-20020a056a00418600b0056ba9bdee5fmr41642338pfb.80.1669389919990; Fri, 25 Nov 2022 07:25:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669389919; cv=none; d=google.com; s=arc-20160816; b=rUnBGV+oJEVHIENhfWyxJ9cbgG3inNI5ZEqF7xzE3UF25P42EbCHXi81q4z2T3PyqY DdDmwIjE4X4fPqy2DVXWZDfUOHkDD3m04WAZMC5shdYz25A148U+UzsbbBjG/3pTdwh9 6DZHY9gjfe+hwj0Km4lKqui5uSTepTUwKO7VMX+N9txcMO5UYZ6bpp1DwC3fSI0vVGgb RzZZp5Hy5p+EN/xMmYi1x527H/ztuQSwhZtc1uudZl0vCbGCgIGMPDKNmDSOkLPx/mCJ C+hRkaOLeuTbQD6pNan1XpB5qIX3f38S1xy6Wez/J877nzBbiMFAlM4e6T9FRU/FfXrc ARwg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=lS8stYG6Frvb/BGcJu8YF7/dhbrkHyksUpy1OUW/W8o=; b=TRSAFOoifHDzSOpl7ZY+VfPMaRq1w+sA4oNRzUvB1/6k4YTzR9V2LONZijGrZ8OTlK dqQtFYDFklmMbVYT8brplnKD/PLGtRfAybzJvK5kZw8RmjO3+ffTUg9cwHuMtYs5GHkK d63QOR3+d3aYcelLtNLjNZYY74BONUB5l0N0lF06UhXbHskkonvaWWYUl2+NH2oJ2QCA PlG42IRPoYx3cYeIMqYZq931PB9cYwy3HEAs0lI2BLbjJ1iLXGyRwF74JLGwA6bIcmRl 20Rf2klcNZbD924kncmYYEdOmqRO/YnDOJnevcCmGXad1pqA4yvMlWdJiDOlC8fRNC0J JT8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@arista.com header.s=google header.b=iLf+bm0Y; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=arista.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s9-20020a170902b18900b0018919169bc4si3489490plr.430.2022.11.25.07.25.08; Fri, 25 Nov 2022 07:25:19 -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=@arista.com header.s=google header.b=iLf+bm0Y; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=arista.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229575AbiKYO2l (ORCPT + 85 others); Fri, 25 Nov 2022 09:28:41 -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-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 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A, RCVD_IN_DNSWL_NONE,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 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