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 B8779C4167B for ; Tue, 5 Dec 2023 11:38:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1442131AbjLELig (ORCPT ); Tue, 5 Dec 2023 06:38:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58956 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345109AbjLELie (ORCPT ); Tue, 5 Dec 2023 06:38:34 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CB16885 for ; Tue, 5 Dec 2023 03:38:40 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 64A4AC433C8; Tue, 5 Dec 2023 11:38:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1701776320; bh=HpQfzKH9PkcgbFsZNKCTx0ikve2nD8WgZ8kDoy0hkBA=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=CWF7d+KkggDuCYM2ZU8EJIKTxe7uCccNTV72qrVHVEt6Q9Uuc/a6adZQAXfD9uQQR mrajWEOGXEhUvJssq7ok9NsIqToNwgakLRba7uZJ83ee2M1NxubiYugKhck/WOeVUd i3cD/49HSP56/Iqhx048G0eA3fX1z0WC80CDeqYTU8WrLbajgyLEG9ZVfokcGO90pq a/05lO9I274mHG7GxzwCX2xReZI4E5QKDm88rskarGW+U2KLvySzitr6m6e5aoPhX0 XAqVcx6W+IP7Usyp9EOdajaLItYeRdvsxLzsHOpMXDpdKz2lDfxNGxytfdmiWqMHSL J5CS2r67Mm8Aw== Date: Tue, 5 Dec 2023 12:38:35 +0100 From: Christian Brauner To: Kees Cook Cc: Al Viro , "Guilherme G. Piccoli" , Peter Zijlstra , linux-fsdevel@vger.kernel.org, Tony Luck , linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: Re: [PATCH 3/5] fs: Add DEFINE_FREE for struct inode Message-ID: <20231205-horchen-gemieden-8013e0f30883@brauner> References: <20231202211535.work.571-kees@kernel.org> <20231202212217.243710-3-keescook@chromium.org> <20231202212846.GQ38156@ZenIV> <202312021331.D2DFBF153@keescook> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <202312021331.D2DFBF153@keescook> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Dec 02, 2023 at 01:34:32PM -0800, Kees Cook wrote: > On Sat, Dec 02, 2023 at 09:28:46PM +0000, Al Viro wrote: > > On Sat, Dec 02, 2023 at 01:22:13PM -0800, Kees Cook wrote: > > > Allow __free(iput) markings for easier cleanup on inode allocations. > > > > NAK. That's a bloody awful idea for that particular data type, since > > 1) ERR_PTR(...) is not uncommon and passing it to iput() is a bug. > > Ah, sounds like instead of "if (_T)", you'd rather see > "if (!IS_ERR_OR_NULL(_T))" ? > > > 2) the common pattern is to have reference-consuming primitives, > > with failure exits normally *not* having to do iput() at all. > > This I'm not following. If I make a call to "new_inode(sb)" that I end > up not using, I need to call "iput()" in it... If we wanted to do this properly then we would need to emulate consume or move semantics like Rust has. So a cleanup function for inodes based on scope for example and then another primitive that transfers/moves ownership of that refcount to the consumer. Usually this is emulate by stuff like TAKE_POINTER() and similar stuff in userspace. But I'm not sure how pleasant it would be to do this cleanly.