Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp1722701rwd; Tue, 13 Jun 2023 13:12:13 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6ksTzgtFL3qZI9qWTp2xdUyNZuCVnLgnflRYhbSfO8iNCDjcOhEimgfYw4kBpzoWt2U9tm X-Received: by 2002:a17:907:5ca:b0:977:e2a6:47ce with SMTP id wg10-20020a17090705ca00b00977e2a647cemr13887192ejb.35.1686687133656; Tue, 13 Jun 2023 13:12:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686687133; cv=none; d=google.com; s=arc-20160816; b=SjGeC0Je8RUNbfpkdYYkQBq1iAjRWtVFIt0WjzSiGCRl/9rCOHmB6pa+Jx8i/nM0PP O8k0kpju1uzRmybjhrahRWG9fzVqEpRVZL/4236UG1SgEBDOYG6JlPjlj+dqYB8Knlnu D1vP9jJc/NpKCbrKDV9Au0GR1liOyWgBu3Muo9Gh+gnef0V3ehnEbBMEhxp4AWv6HBQC 6/BnL3Pt/l15s4QMUp5UTrF1eUWudgL7ciltyGqlULCZb8VC0+GrW218l3tHnpz2F0lh EHpvyeu8crpJ6G65cZtk9MVORUqo5G0g6aG0+h4NS+NhH8QmHKfkNkAo74MjMtLU4O6j bI0w== 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=mxeuPCO3GTvztmCaqFwBCrXNFMyoav37TQYPe5N2X2Q=; b=FmBAQRMafsi1ldWc4Jhr5sUdoT6bTpKMV4TGkUI3VDbtIn8Gbk0fi2tZP3yTfrCyZ4 CNSvuLpDGrbMRA4t5TASz7jCHyvZGP5q8QfY12yJvtrNYjmajUzkrpl3O7QttRDcWeS4 3Ssu9hJYijU2gBB+qA7/5eCqYwpx0hHO60tJyzn1Z614Ak5xkccXft8YuO7morZEH5oV k0p3CMAJFMD6zy0vbw4oor6bA43hyNQfxOmFfQpJj6TB2zyC0HMhAx84QF6VgGq+i+LJ 5uiBgGJc32DNxNkh0rokbIyp/4idNRYhQB+x+FJAAAsC0ZKOpEuSNOaWR8jeflaPc6Zi B87Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=ZXwqdQSU; 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=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id kb9-20020a1709070f8900b0094f4a88b558si7817939ejc.456.2023.06.13.13.11.48; Tue, 13 Jun 2023 13:12:13 -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=@chromium.org header.s=google header.b=ZXwqdQSU; 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=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229642AbjFMTqe (ORCPT + 99 others); Tue, 13 Jun 2023 15:46:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44162 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231206AbjFMTqb (ORCPT ); Tue, 13 Jun 2023 15:46:31 -0400 Received: from mail-pf1-x429.google.com (mail-pf1-x429.google.com [IPv6:2607:f8b0:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 573FD19A for ; Tue, 13 Jun 2023 12:46:30 -0700 (PDT) Received: by mail-pf1-x429.google.com with SMTP id d2e1a72fcca58-6662fcaac93so132955b3a.2 for ; Tue, 13 Jun 2023 12:46:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1686685590; x=1689277590; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=mxeuPCO3GTvztmCaqFwBCrXNFMyoav37TQYPe5N2X2Q=; b=ZXwqdQSU/HiRRBmiMo0Q4BulnluPAh2ryLShUC8dzGZsPXV27BS3mYaNw52krhQxmi FDxiku3oDSIq7ETXuQ8zuIR6vPTTTiy5Uh+q09OiBHP7jNeYHGe8a87/wG4jR/UkKFXO m0LB4L/wA3k4VB+TGrW72v2AVbhniQkqNzr60= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686685590; x=1689277590; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=mxeuPCO3GTvztmCaqFwBCrXNFMyoav37TQYPe5N2X2Q=; b=dOsWX31NcCY4k4zoyd2EkLnR/br2OMLpeuKI2jkFhgZJr/n5jEKJtI9chBC2gTMlXp ujBlFUrmLaPvmt4Lif6yJqHOSkb2nfz5hsci/3y7zhUyUl/XdTJlCqABDfGb8fPfSEIM DGN5HS7dXRyp6TkEtOIpCM4sKaLuljbWGn7vBzA0XY5dk776p4SI+DM8guM0j2PDnzrW yE4zRYkx7rP1iAq3F8njAIplP/IU4iXuuzNWxHo61eoNRo0Pzubqfg8PyjyeTvD88tr6 1vYCd42nDBrU1aS6ku3ivTHhLpmDjkfqkgpkP12XzKQrsssSwviIaYYxncb999jtSBO9 9zZA== X-Gm-Message-State: AC+VfDzXLK2zadtsZckc1Y9QUWJFHjHe3E1NzU/8LwoJElODwpM+m7X5 wo2joyvq2JVXmgU9nn6ynEmS0w== X-Received: by 2002:a05:6a00:1783:b0:662:c48b:47e2 with SMTP id s3-20020a056a00178300b00662c48b47e2mr19702410pfg.19.1686685589881; Tue, 13 Jun 2023 12:46:29 -0700 (PDT) Received: from www.outflux.net (198-0-35-241-static.hfc.comcastbusiness.net. [198.0.35.241]) by smtp.gmail.com with ESMTPSA id t12-20020a62ea0c000000b00643355ff6a6sm9215426pfh.99.2023.06.13.12.46.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Jun 2023 12:46:29 -0700 (PDT) Date: Tue, 13 Jun 2023 12:46:29 -0700 From: Kees Cook To: Peter Zijlstra Cc: torvalds@linux-foundation.org, gregkh@linuxfoundation.org, pbonzini@redhat.com, masahiroy@kernel.org, nathan@kernel.org, ndesaulniers@google.com, nicolas@fjasle.eu, catalin.marinas@arm.com, will@kernel.org, vkoul@kernel.org, trix@redhat.com, ojeda@kernel.org, mingo@redhat.com, longman@redhat.com, boqun.feng@gmail.com, dennis@kernel.org, tj@kernel.org, cl@linux.com, acme@kernel.org, mark.rutland@arm.com, alexander.shishkin@linux.intel.com, jolsa@kernel.org, namhyung@kernel.org, irogers@google.com, adrian.hunter@intel.com, juri.lelli@redhat.com, vincent.guittot@linaro.org, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de, bristot@redhat.com, vschneid@redhat.com, paulmck@kernel.org, frederic@kernel.org, quic_neeraju@quicinc.com, joel@joelfernandes.org, josh@joshtriplett.org, mathieu.desnoyers@efficios.com, jiangshanlai@gmail.com, rientjes@google.com, vbabka@suse.cz, roman.gushchin@linux.dev, 42.hyeyoo@gmail.com, apw@canonical.com, joe@perches.com, dwaipayanray1@gmail.com, lukas.bulwahn@gmail.com, john.johansen@canonical.com, paul@paul-moore.com, jmorris@namei.org, serge@hallyn.com, linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, dmaengine@vger.kernel.org, llvm@lists.linux.dev, linux-perf-users@vger.kernel.org, rcu@vger.kernel.org, linux-security-module@vger.kernel.org, tglx@linutronix.de, ravi.bangoria@amd.com, error27@gmail.com, luc.vanoostenryck@gmail.com Subject: Re: [PATCH v3 03/57] locking: Introduce __cleanup() based infrastructure Message-ID: <202306131244.E8DF4CA166@keescook> References: <20230612090713.652690195@infradead.org> <20230612093537.614161713@infradead.org> <20230613105522.GU4253@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230613105522.GU4253@hirez.programming.kicks-ass.net> 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,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=unavailable 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 Tue, Jun 13, 2023 at 12:55:22PM +0200, Peter Zijlstra wrote: > On Mon, Jun 12, 2023 at 11:07:16AM +0200, Peter Zijlstra wrote: > > > --- /dev/null > > +++ b/include/linux/cleanup.h > > @@ -0,0 +1,167 @@ > > +/* SPDX-License-Identifier: GPL-2.0 */ > > +#ifndef __LINUX_GUARDS_H > > +#define __LINUX_GUARDS_H > > + > > +#include > > + > > +/* > > + * DEFINE_FREE(name, type, free): > > + * simple helper macro that defines the required wrapper for a __free() > > + * based cleanup function. @free is an expression using '_T' to access > > + * the variable. > > + * > > + * __free(name): > > + * variable attribute to add a scoped based cleanup to the variable. > > + * > > no_free_ptr(var): > like a non-atomic xchg(var, NULL), such that the cleanup > function will be inhibited -- provided it sanely deals with a > NULL value. > > > + * return_ptr(p): > > + * returns p while inhibiting the __free(). > > + * > > + * Ex. > > + * > > + * DEFINE_FREE(kfree, void *, if (_T) kfree(_T)) > > + * > > + * struct obj *p = kmalloc(...); > > That should obviously have been: > > struct obj *p __free(kfree) = kmalloc(...); Okay, good. I noticed that too. :) I also didn't see any users of the kfree helpers (maybe I missed them?) Maybe add at least one conversion just to have an example conversion for it too? -Kees -- Kees Cook