Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp4874620rdb; Fri, 15 Sep 2023 15:23:55 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGE4hA26YnadsXkuiVBWgi4cPMu1qSdlRcETrwedi92zWLaPPfT3yG50AZSRLzx3aFyWatr X-Received: by 2002:a05:6358:5908:b0:142:d40b:817c with SMTP id g8-20020a056358590800b00142d40b817cmr3576948rwf.2.1694816635567; Fri, 15 Sep 2023 15:23:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694816635; cv=none; d=google.com; s=arc-20160816; b=nmPteKVUPMHQbfhwiO/2BHojh/DgKpuPLjwdECIS/UL+RoNdzK3aZs28JZG37b+YnX qoTJvLl8z/fSeOYefRKOzXWScIEizVEQPpYEgtrBh/HkfCRrbamZxMlTlyJ+bbL3ho1+ l6wJlAjx/cltUS0DgkjM078X3ilbVBBoP1cMXUwc7/tAlDwjdJUitbARlyzv+73APYft xgcnXbuB+2DoBNwbwGNmtXGYAywgftkvQuONrVKjT1C8yfHoMNAgcs5wq6oAoPrR9FdF s6pxZap4vsDLXw966pBQrQgyhwVdSUN4UF2Vk8rfwbGpeXtZwNdYa4DLvtSvg/OnHUGD UFuA== 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=jkCUL0RKzftwVLtOw4nOB5BWk9sREif9OtWvVaTnu0k=; fh=0T/Cz/6kfzyq4MPg6wrhuDkAsXxv4Wnv+2jNEKRU/s0=; b=SD7ry1kiv6ite385f0JkTy/xbelZxYeOQK1gUvvLxZ5ZB1AM5bqlteozICoTpNwQUs Gu7oLwbE1guX9ul4g095ZnscwuPiY00T5v6356B6NEZAF4rZTM45/pS8RhRsVX18E1Im dIc+z+2LTVeDf7P9EtNGVpXs8CBebEK/E6Fzs0awqswhFhy2noVp23paDSIEvgzEXMGt Bpr9wf4XqnOKZUQjjnbf7sisVeUlT8wZbiJ6okFWCVtueTW3IDKZ8JI4utiytiEv1Kk+ 5lBFs/WYA0kB4IIYxjxha0HMdV4HD99Z0S+Q7zdfG2t7f06GZH/T6288OFQodjwW2lZM qrBw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=aeWfvU2U; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id m9-20020a654389000000b0056fbf85c743si3696647pgp.790.2023.09.15.15.23.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 15:23:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=aeWfvU2U; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 03EE783FEB91; Fri, 15 Sep 2023 14:09:57 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237722AbjIOVJY (ORCPT + 99 others); Fri, 15 Sep 2023 17:09:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58206 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237863AbjIOVJB (ORCPT ); Fri, 15 Sep 2023 17:09:01 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2B3B8D3 for ; Fri, 15 Sep 2023 14:08:56 -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=jkCUL0RKzftwVLtOw4nOB5BWk9sREif9OtWvVaTnu0k=; b=aeWfvU2UpK+D5Qk1SJC9+vBv4l A6mPBNqQ6QOjao2AnsbHcHf/fBLBQkHAweyg78Qg69poLPzMBFhmJllkKOKTbpovSnkDJMq3yOgDW fYH53XwESfbameeMqSuzZuoS+4q8Ki35MHqykVKUIJdAD4OlLMlI22l1d5lGzffeZ9LLBqAszGiIP gO763rmbHagSnj8gDwfB0hfmFPDlKQj9VTwuv4kvWtposyGmfEPvEsVJKsu1mdBSfhWO+iJy6dBzS ph0aET6OxkwV9rORAK4Mci9RuVAFWpWMu3Gr1yrHkl/PFIjfT+FQEHkvD5Mpo2Tfx6sjcF9nOECFL SvEYl0XQ==; 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 1qhG3Y-00C3p2-7A; Fri, 15 Sep 2023 21:08:52 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 1000) id D43113003F2; Fri, 15 Sep 2023 23:08:51 +0200 (CEST) Date: Fri, 15 Sep 2023 23:08:51 +0200 From: Peter Zijlstra To: Linus Torvalds Cc: Bartosz Golaszewski , Alexey Dobriyan , linux-kernel@vger.kernel.org, Linus Walleij , akpm@linux-foundation.org Subject: Re: Buggy __free(kfree) usage pattern already in tree Message-ID: <20230915210851.GA23174@noisy.programming.kicks-ass.net> References: <07c32bf1-6c1a-49d9-b97d-f0ae4a2b42ab@p183> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Fri, 15 Sep 2023 14:09:57 -0700 (PDT) On Fri, Sep 15, 2023 at 01:40:25PM -0700, Linus Torvalds wrote: > Not because I think it's necessarily any kind of final rule, but > because I think our whole cleanup thing is new enough that I think > we're better off being a bit inflexible, and having a syntax where a > simple "grep" ends up showing pretty much exactly what is going on wrt > the pairing. So in the perf-event conversion patches I do have this: struct task_struct *task __free(put_task) = NULL; ... if (pid != -1) { task = find_lively_task_by_vpid(pid); if (!task) return -ESRCH; } ... pattern. The having of task is fully optional in the code-flow. I suppose I can try and rewrite that a little something like: ... struct task_struct *task __free(put_task) = find_lively_task_by_vpid(pid); /* ensure pid==-1 returns NULL */ if (!task && pid > 0) return -ESRCH; ... But a little later in that same function I then have: do { struct rw_semaphore *exec_update_lock __free(up_read) = NULL; if (task) { err = down_read_interruptible(&task->signal->exec_update_lock); if (err) return err; exec_update_lock = &task->signal->exec_update_lock; if (!perf_check_permissions(&attr, task)) return -EACCESS; } ... stuff serialized against exec *if* this is a task event ... } while (0); And that might be a little harder to 'fix'. I suppose I'm saying that when thing truly are conditional, this is a useful pattern, but avoid where reasonably possible.