Received: by 2002:a05:7412:37c9:b0:e2:908c:2ebd with SMTP id jz9csp568928rdb; Tue, 19 Sep 2023 04:12:29 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFWRNWAuPMgdoRGn19OaGtaF5VJbRaHbgEtSY38vkpjXkuM+rvueyHowUsDff1ec3O7WH/G X-Received: by 2002:a92:c6c2:0:b0:34f:c9b4:5f9e with SMTP id v2-20020a92c6c2000000b0034fc9b45f9emr11658102ilm.19.1695121949472; Tue, 19 Sep 2023 04:12:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695121949; cv=none; d=google.com; s=arc-20160816; b=Zpx4Yx5JTN2z+T4qWOQ4iZ1gCMr1rZePTSUR4wDoFTrH1rOC7gk9TfyNGZHIakAJO4 APtB22/33KKilogFpzmswupstalod7jUmrkYJcebZRPtgfUoPBvjPCQYRCeFPrCm9ddg SayaeY13diSME8oCQ3VzzS9dhGSThk+PUbhCVNL6OVTLVIJI55kjxatYG7PAchw2+66Y Xq3T2aGxVnTrqnbF0TeOk7FZ6Pr6pz3Hne/xbp1A/89oca5MpGnklNdHEx6Mq7e5gpLL /acfrh2uuRUAP1OqR2lS2MkxGySlYYfflquZ4xzkhZMgDkM6UI+6rWn2I95cZsW8U/oA cvuA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=nWwOBXcgP9QHb+ZwLC4z/fad6HDujTXM9X3AXgFefao=; fh=d8T7HxciI6eyp/OeRO50TOPCwDQ47PYoY+X2myTwLJ0=; b=tCU3R3XjEmewZQ0ZUv3wyV1T0dJbtbyMzhSUry3FGj6nyB1sFICqFAq3WF/aHXzaav oxaFcv0+1ghXzKaXo1lR+rnrr7PpEkhG/zmj9TZ1Qj1BevFyWAd878gezDnndkbUUVNy v0TABazycW6FYD8Nvg2xnMNzG+ae7HrNedffJwlVLmOUwLo6AcgaU5VHhETWYPbrzcbM 4JGqPCCMqKINPJgp7T9V5NSPlbDwe7q501lQ5ocULRItKC7ap0PchQ7rGXUlC934lrG5 0eZXDXmddKeJ1hA33Vpt+D82Rnx+pJ1nKZ1IEL5H10hsqcfIpRsKEMr4M4zPOTk0dBSb Qz8Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@szeredi.hu header.s=google header.b=F3pgzF80; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=szeredi.hu Return-Path: Received: from pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id g184-20020a636bc1000000b0054ff53233f2si9277288pgc.567.2023.09.19.04.12.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Sep 2023 04:12:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; dkim=pass header.i=@szeredi.hu header.s=google header.b=F3pgzF80; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=szeredi.hu Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 19F5E8119797; Tue, 19 Sep 2023 01:02:43 -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 S229772AbjISICl (ORCPT + 99 others); Tue, 19 Sep 2023 04:02:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53598 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230186AbjISICi (ORCPT ); Tue, 19 Sep 2023 04:02:38 -0400 Received: from mail-lj1-x229.google.com (mail-lj1-x229.google.com [IPv6:2a00:1450:4864:20::229]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8D88B11A for ; Tue, 19 Sep 2023 01:02:30 -0700 (PDT) Received: by mail-lj1-x229.google.com with SMTP id 38308e7fff4ca-2c00b37ad84so29711441fa.0 for ; Tue, 19 Sep 2023 01:02:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=szeredi.hu; s=google; t=1695110549; x=1695715349; darn=vger.kernel.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=nWwOBXcgP9QHb+ZwLC4z/fad6HDujTXM9X3AXgFefao=; b=F3pgzF80ybykApF9N2exJ0huxmKEj/JwYyG9wZoIC+wUdSJA/bRF6YpfJc/mg/szkA OsImu0uqYiBUmx53o4mPonCr5nLtlyInVMv7EjTlXZBV/OW+jgLtaIHKQWItQCF9ulRs M+qXKlMomeIukmh0UgualD1oUS+FSCc1iTE1A= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695110549; x=1695715349; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=nWwOBXcgP9QHb+ZwLC4z/fad6HDujTXM9X3AXgFefao=; b=pDh2K2D/dZTQbj2xwdBKqi9vPd2xNWyZYxTKQtEeYB5cet76g8mtoGdcElvfOH0Hs3 LiPmiZXannoGUG8fL5UnELlRMx2KURRTT7wkz7vzaGFaxw+nak52ExF6d5Xr8TzCuNou eFcQ/iAK+E5CiGShw6xhF39sX+SK2PuSl2IO1v5Z1AftC2OftLmwJeNvLs9y12mtG3nt p1vo62nQj/0vqftyHVhp5ZgQhejbfawUvX1ZziXTQLTIzswgELLyFqDf2AnPPF1Z/wIV LVR9v4BvdRnMI75Q0hcZ+onOrtGUY7INvnSrQc2/YW+kIUCnS4b68QNwLlsJwop8hW8H O1Cg== X-Gm-Message-State: AOJu0YwhKQ5AAlc2Uzdn3Lg5xIjj0IjkAaRHoXTQM5nkry7z+BJLjNKg 50TyVgdIXINKEi7a48V4F8fvZx/IvDwkJLumWs9/UQ== X-Received: by 2002:a2e:9f0a:0:b0:2bc:be3c:9080 with SMTP id u10-20020a2e9f0a000000b002bcbe3c9080mr9595518ljk.27.1695110548691; Tue, 19 Sep 2023 01:02:28 -0700 (PDT) MIME-Version: 1.0 References: <20230914-salzig-manifest-f6c3adb1b7b4@brauner> <20230914-lockmittel-verknallen-d1a18d76ba44@brauner> <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> In-Reply-To: <20230919003800.93141-1-mattlloydhouse@gmail.com> From: Miklos Szeredi Date: Tue, 19 Sep 2023 10:02:17 +0200 Message-ID: Subject: Re: [RFC PATCH 2/3] add statmnt(2) syscall To: Matthew House Cc: Christian Brauner , 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 Content-Type: text/plain; charset="UTF-8" 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]); Tue, 19 Sep 2023 01:02:43 -0700 (PDT) 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. We are trying to create a simple interface, no? My proposal would need a helper like this: struct statmnt *statmount(uint64_t mnt_id, uint64_t mask, unsigned int flags) { size_t bufsize = 1 << 15; void *buf; int ret; for (;;) { buf = malloc(bufsize <<= 1); if (!buf) return NULL; ret = syscall(__NR_statmnt, mnt_id, mask, buf, bufsize, flags); if (!ret) return buf; free(buf); if (errno != EOVERFLOW) return NULL; } } Christian's would be (ignoring .fs_type for now): int statmount(uint64_t mnt_id, uint64_t mask, struct statmnt *st, unsigned int flags) { int ret; st->mnt_root_size = 1 << 15; st->mountpoint_size = 1 << 15; for (;;) { st->mnt_root = malloc(st->mnt_root_size <<= 1); st->mountpoint = malloc(st->mountpoint <<= 1); if (!st->mnt_root || !st->mountpoint) { free(st->mnt_root); free(st->mountpoint); return -1; } ret = syscall(__NR_statmnt, mnt_id, mask, st, sizeof(*st), flags); if (!ret || errno != EOVERFLOW) return ret; free(st->mnt_root); free(st->mountpoint); } } It's not hugely more complex, but more complex nonetheless. 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, while in the first example it is. Note that I'm not against having the prototype on the kernel interface take a typed pointer. If strings are not needed, both interfaces would work in exactly the same way. Thanks, Miklos