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 8BAD2CD54AB for ; Tue, 19 Sep 2023 09:07:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231143AbjISJHw (ORCPT ); Tue, 19 Sep 2023 05:07:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44608 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230477AbjISJHv (ORCPT ); Tue, 19 Sep 2023 05:07:51 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BA848EC; Tue, 19 Sep 2023 02:07:45 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 50CF5C433C8; Tue, 19 Sep 2023 09:07:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1695114465; bh=B/Kioz3f57QDGw85DtiGtnUTyVRNwLeq2/Ex7+Ek1iw=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=jpjM+7H48CgdX5cq5vTfg1JsM1JSl8Hss8/ZKcySHZIHl2GAIoKjqO0BvawtpgLn2 Vj4qIXupZpioMYlg80kzFkhZQiFsmuKzuM+yIetGbJ+P97b4qFWt6ou7ddUBwuVKCb 5XiwKS1JkF0RTOgGzfAoSyOLhWkTtbguwzivGItlnlgBB0blE2s4Bh0X0roGzSabGJ IvALVx1LdHT1Fo+HeyidZbBDgIZSJ6+2lIRLq3m96q1z6H9xP4ahhy8Jl4Q0YO3gWT EqS6KOsOUPKbovR10LFE58pqjprrLEu1vRx+E6TXobKtMWgGUe8jbUH/6dQhZqzSBS noE/I2NXjNWdQ== Date: Tue, 19 Sep 2023 11:07:39 +0200 From: Christian Brauner To: Miklos Szeredi Cc: Matthew House , Miklos Szeredi , Linus Torvalds , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-api@vger.kernel.org, linux-man@vger.kernel.org, linux-security-module@vger.kernel.org, Karel Zak , Ian Kent , David Howells , Al Viro , Christian Brauner , Amir Goldstein Subject: Re: [RFC PATCH 2/3] add statmnt(2) syscall Message-ID: <20230919-abfedern-halfen-c12583ff93ac@brauner> References: <20230918-grafik-zutreffen-995b321017ae@brauner> <20230918-hierbei-erhielten-ba5ef74a5b52@brauner> <20230918-stuhl-spannend-9904d4addc93@brauner> <20230918-bestialisch-brutkasten-1fb34abdc33c@brauner> <20230919003800.93141-1-mattlloydhouse@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-api@vger.kernel.org On Tue, Sep 19, 2023 at 10:02:17AM +0200, Miklos Szeredi wrote: > On Tue, 19 Sept 2023 at 02:38, Matthew House wrote: > > > One natural solution is to set either of the two lengths to the expected > > size if the provided buffer are too small. That way, the caller learns both > > which of the buffers is too small, and how large they need to be. Replacing > > a provided size with an expected size in this way already has precedent in > > existing syscalls: > > This is where the thread started. Knowing the size of the buffer is > no good, since the needed buffer could change between calls. The same problem would exist for the single buffer. Realistically, users will most often simply use a fixed size PATH_MAX buffer that will cover most cases and fallback to allocating a larger buffer in case things go awry. I don't think we need to make this atomic either. Providing a hint for the required buffer size in case this fails is good enough and should be a rather rare occurence and is exactly how other variable-sized buffers are handled. > Also having the helper allocate buffers inside the struct could easily > result in leaks since it's not obvious what the caller needs to free, I don't think we need to be overly concerned with how userspace implements the wrapper here. Leaks can occur in both scenarios and low-level userspace can use automatic cleanup macros (we even support it in the kernel since v6.5) to harden against this. Really, the main things I care about are 64 bit alignment of the whole struct, typed __u64 pointers with __u32 size for mnt_root and mnt_point and that we please spell out "mount" and not use "mnt": so statmount because the new mount api uses "mount" (move_mount(), mount_setattr(), fsmount(), MOUNT_ATTR_*) almost everywhere.