Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp6583308rwb; Tue, 22 Nov 2022 15:50:10 -0800 (PST) X-Google-Smtp-Source: AA0mqf59J00009NwHcsSQJIMbSOmVhGBs75uXzV04NPDaSzSsgynMdot/u5ENMk032NZHlgaPb1p X-Received: by 2002:a17:906:2dc2:b0:7ae:c1af:a078 with SMTP id h2-20020a1709062dc200b007aec1afa078mr22533361eji.294.1669161010093; Tue, 22 Nov 2022 15:50:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669161010; cv=none; d=google.com; s=arc-20160816; b=cFBFDtFz73KKrvpbL99QG/sMGvU36+gzr3F81sPGots8WwVsx6FExRsiEFUblfIIPw fKFZzQdXplqQtDGJIIGXIhluJdlWymgl4xVBzBuWrUGKQ+lFd4rV2SMWQdrh059pPQ7U F3DW8DH6UIB6Awr0TwH8N1mIQ/+uZKSxwK8OMOrWyxd4ClyizaaBvZXPlY/SRrkwhy/V Und3cmtrvMeAKB+lejE8Ez0P6d1zyVI16MFtZXqtfFulGMUJl8/5ZBs53HbrhewTH/QX XgswtYtOMTc3kvalSAmIOWCGdrO/HjPY7n0s2cnOQ4dOb9p8WjbAed+tWKviWPmT2X72 FHjA== 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-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=4Br32V4f5RhJzAJZzqIlTw5MxWMCxMPceRuTf9fFBWs=; b=zKxzn8WvADUPVokfY1QnAfgujHRcl4CsVVY5eSgg0K37BsUTOWJpCKlmzNnd0E6ECm uhsEEeYQJQMWLWevBUq1tzkCnh0bDuSko5UZz+Of0NybYVx199hx2bM9nTQNfIXmxWL1 HKjUyg56r0kQBcupcjafdlJ0CRaBR1RgTrV8mE/ZfsyPa5aiKeW3wf3NH+2PqNOSjPj8 wmamdv7Ead1shUwFTeLk1Ona4Vrq/ut2UwkxE0wIg6LfZSbHJkS+ONJNoFNj+jpIcZfC FUVW01uUR+66LLKmJb5VQg44TgLKLkhos50v9kzES+tPTN9MC3DECHiCYbrzzdBZ8Quf QHew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@fromorbit-com.20210112.gappssmtp.com header.s=20210112 header.b=LMp1DNYW; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id xj10-20020a170906db0a00b007adef1dceffsi14393639ejb.677.2022.11.22.15.49.40; Tue, 22 Nov 2022 15:50:10 -0800 (PST) Received-SPF: pass (google.com: domain of linux-ext4-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=@fromorbit-com.20210112.gappssmtp.com header.s=20210112 header.b=LMp1DNYW; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230009AbiKVXpX (ORCPT + 99 others); Tue, 22 Nov 2022 18:45:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54954 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235058AbiKVXpV (ORCPT ); Tue, 22 Nov 2022 18:45:21 -0500 Received: from mail-pf1-x42a.google.com (mail-pf1-x42a.google.com [IPv6:2607:f8b0:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 046F9C7239 for ; Tue, 22 Nov 2022 15:45:20 -0800 (PST) Received: by mail-pf1-x42a.google.com with SMTP id y203so15820590pfb.4 for ; Tue, 22 Nov 2022 15:45:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fromorbit-com.20210112.gappssmtp.com; s=20210112; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=4Br32V4f5RhJzAJZzqIlTw5MxWMCxMPceRuTf9fFBWs=; b=LMp1DNYW9KAAMAhwIRp13A+UoP5f9oi+tOL9pTcPwVL3Hc6Ia0RKrsPyHf7sk3dYlL v9YR+AZs0izub2IeIbLi9+6o8cIngufh1uDpzVlhQ/ZFDkXxqwXovqRsjKBm6NZFGvv6 pSeTyc8+Xrg5pYq9dVwahpyuRyB+A0L7WHBm9FYVIm3CSim0mFWLdFJcXn1W/Cirm8wU 4cx6I/5Z9/oLvxF/W/DNvYvSDm5Y1x5ZXSK3G4AXZe853DkbvzdSe2ugzOjJtso17frU aC8o3HsIYiTKdAMhTgI75zsB1Xqbrkav8T2gO/YrQ38GZirJO2OPKZh8DErpWJLFpzvk XPlg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-transfer-encoding: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=4Br32V4f5RhJzAJZzqIlTw5MxWMCxMPceRuTf9fFBWs=; b=6eVVlUCL0pOd3XrxpJ9Q1CU4NmxSJT/rxfoMWKOJuTsK2jdR/iCcyCl5derupKTTey vl0TVQW0AE0Y6YaklWo5rsrD72VsIOlMCseAWKDEo1bTKPydExWjIND9lILlq1lRSJW5 mq1mf14rRrDO5vSMQsbBDEFdCyV2Yt4pzrk6SVwkbHZX01HUsX2+hjW3YplNxrQY/XiL ZkWtYG6ICW7NysYJ+jog5yT09sGpj/0yGGBqwELsIAQWzsgcnuPaJT6qIn+LjxJecL9x 4UoQ+He4RJBSnYveW2w2RR/LX+NSESCKLtzfqzoj1uSr803XBvY9ZYS9aAaO1/g7BwMg +A2w== X-Gm-Message-State: ANoB5pm+WTvfqcy68omHCyVJ2T1r7JYbO6RCPQHRdKKr1lNAeTxzH3YA PuDd62rYp7+GAFVMS2B6DEqVDA== X-Received: by 2002:a63:1626:0:b0:470:2c90:d89f with SMTP id w38-20020a631626000000b004702c90d89fmr7904405pgl.253.1669160719359; Tue, 22 Nov 2022 15:45:19 -0800 (PST) Received: from dread.disaster.area (pa49-186-65-106.pa.vic.optusnet.com.au. [49.186.65.106]) by smtp.gmail.com with ESMTPSA id e126-20020a621e84000000b00573769811d6sm6800188pfe.44.2022.11.22.15.45.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Nov 2022 15:45:18 -0800 (PST) Received: from dave by dread.disaster.area with local (Exim 4.92.3) (envelope-from ) id 1oxcx1-00HS2f-47; Wed, 23 Nov 2022 10:45:15 +1100 Date: Wed, 23 Nov 2022 10:45:15 +1100 From: Dave Chinner To: "Darrick J. Wong" Cc: Catherine Hoang , linux-xfs@vger.kernel.org, linux-ext4 , Theodore Ts'o , linux-fsdevel , linux-api@vger.kernel.org Subject: Re: [PATCH v1] xfs_spaceman: add fsuuid command Message-ID: <20221122234515.GT3600936@dread.disaster.area> References: <20221109222335.84920-1-catherine.hoang@oracle.com> <20221117215125.GH3600936@dread.disaster.area> <20221121233357.GO3600936@dread.disaster.area> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE 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-ext4@vger.kernel.org On Mon, Nov 21, 2022 at 10:21:57PM -0800, Darrick J. Wong wrote: > [adding Ted, the ext4 list, fsdevel, and api, because why not?] > > On Tue, Nov 22, 2022 at 10:33:57AM +1100, Dave Chinner wrote: > > On Thu, Nov 17, 2022 at 03:58:06PM -0800, Darrick J. Wong wrote: > > > On Fri, Nov 18, 2022 at 08:51:25AM +1100, Dave Chinner wrote: > > > > On Thu, Nov 17, 2022 at 12:37:33PM -0800, Darrick J. Wong wrote: > > > > > On Wed, Nov 09, 2022 at 02:23:35PM -0800, Catherine Hoang wrote: > > > > > > Add support for the fsuuid command to retrieve the UUID of a mounted > > > > > > filesystem. > > > > > > > > > > > > Signed-off-by: Catherine Hoang > > > > > > --- > > > > > > > If you're really unlucky, the C compiler will put the fsuuid right > > > > > before the call frame, which is how stack smashing attacks work. It > > > > > might also lay out bp[] immediately afterwards, which will give you > > > > > weird results as the unparse function overwrites its source buffer. The > > > > > C compiler controls the stack layout, which means this can go bad in > > > > > subtle ways. > > > > > > > > > > Either way, gcc complains about this (albeit in an opaque manner)... > > > > > > > > > > In file included from ../include/xfs.h:9, > > > > > from ../include/libxfs.h:15, > > > > > from fsuuid.c:7: > > > > > In function ‘platform_uuid_unparse’, > > > > > inlined from ‘fsuuid_f’ at fsuuid.c:45:3: > > > > > ../include/xfs/linux.h:100:9: error: ‘uuid_unparse’ reading 16 bytes from a region of size 0 [-Werror=stringop-overread] > > > > > 100 | uuid_unparse(*uu, buffer); > > > > > | ^~~~~~~~~~~~~~~~~~~~~~~~~ > > > > > ../include/xfs/linux.h: In function ‘fsuuid_f’: > > > > > ../include/xfs/linux.h:100:9: note: referencing argument 1 of type ‘const unsigned char *’ > > > > > In file included from ../include/xfs/linux.h:13, > > > > > from ../include/xfs.h:9, > > > > > from ../include/libxfs.h:15, > > > > > from fsuuid.c:7: > > > > > /usr/include/uuid/uuid.h:107:13: note: in a call to function ‘uuid_unparse’ > > > > > 107 | extern void uuid_unparse(const uuid_t uu, char *out); > > > > > | ^~~~~~~~~~~~ > > > > > cc1: all warnings being treated as errors > > > > > > > > > > ...so please allocate the struct fsuuid object dynamically. > > > > > > > > So, follow common convention and you'll get it wrong, eh? That a > > > > score of -4 on Rusty's API Design scale. > > > > > > > > http://sweng.the-davies.net/Home/rustys-api-design-manifesto > > > > > > > > Flex arrays in user APIs like this just look plain dangerous to me. > > > > > > > > Really, this says that the FSUUID API should have a fixed length > > > > buffer size defined in the API and the length used can be anything > > > > up to the maximum. > > > > > > > > We already have this being added for the ioctl API: > > > > > > > > #define UUID_SIZE 16 > > > > > > > > So why isn't the API definition this: > > > > > > > > struct fsuuid { > > > > __u32 fsu_len; > > > > __u32 fsu_flags; > > > > __u8 fsu_uuid[UUID_SIZE]; > > > > }; > > > > > > > > Or if we want to support larger ID structures: > > > > > > > > #define MAX_FSUUID_SIZE 256 > > > > > > > > struct fsuuid { > > > > __u32 fsu_len; > > > > __u32 fsu_flags; > > > > __u8 fsu_uuid[MAX_FSUUID_SIZE]; > > > > }; > > > > > > > > Then the structure can be safely placed on the stack, which means > > > > "the obvious use is (probably) the correct one" (a score of 7 on > > > > Rusty's API Design scale). It also gives the kernel a fixed upper > > > > bound that it can use to validate the incoming fsu_len variable > > > > against... > > > > > > Too late now, this already shipped in 6.0. Changing the struct size > > > would change the ioctl number, which is a totally new API. This was > > > already discussed back in July on fsdevel/api. > > > > It is certainly not too late - if we are going to lift this to the > > VFS, then we can simply make it a new ioctl. The horrible ext4 ioctl > > can ber left to rot in ext4 and nobody else ever needs to care that > > it exists. > > You're wrong. This was discussed **multiple times** this summer on > the fsdevel and API lists. You had plenty of opportunity to make these > suggestions about the design, and yet you did not: > > https://lore.kernel.org/linux-api/20220701201123.183468-1-bongiojp@gmail.com/ > https://lore.kernel.org/linux-api/20220719065551.154132-1-bongiojp@gmail.com/ > https://lore.kernel.org/linux-api/20220719234131.235187-1-bongiojp@gmail.com/ > https://lore.kernel.org/linux-api/20220721224422.438351-1-bongiojp@gmail.com/ There's good reason for that: this was posted and reviewed as *an EXT4 specific API*. Why are you expecting XFS developers to closely review a patchset that was titled "Add ioctls to get/set the ext4 superblock uuid."? There was -no reasons- for me to pay attention to it, and I have enough to keep up with without having to care about the minutae of what ext4 internal information is being exposing to userspace. However, now it's being proposed as a *generic VFS API*, and so it's now important enough for developers from other filesystems to look at this ioctl API. > Jeremy built the functionality and followed the customary process, > sending four separate revisions for reviews. He adapted his code based > on our feedback about how to future-proof it by adding an explicit > length parameter, and got it merged into ext4 in 6.0-rc1. *As an EXT4 modification*, not a generic VFS ioctl. > Now you want Catherine and I to tear down his work and initiate a design > review of YET ANOTHER NEW IOCTL just so the API can hit this one design > point you care about, and then convince Ted to go back and redo all the > work that has already been done. All this to extract 16 bytes from the > kernel in a slightly different style than the existing XFS fsgeometry > ioctl. I'm not asking you to tear anything down. Just leave the ext4 ioctl as it is currently defined and nothing existing breaks or needs reworking. All I'm asking is that instead of lifting the ext4 ioctl verbatim, you lift it with a fixed maximum size for the uuid data array to replace the flex array. It's a *trivial change to make*, and yes, I know that this means it's not the same as the ext4 ioctl. But, really, who cares that it will be a different ioctl? Nobody but ext4 utilities will be using the ext4 ioctl, and we expect generic block/fs utilities and applications to use the VFS definition of the ioctl, not the ext4 specific one. > This was /supposed/ to be a simple way for a less experienced staffer to > gain some experience wiring up an existing ioctl. And, well, I hope she > doesn't take away that developing for Linux is institutionally broken > and frustrating, because that's what I've taken away from the last 2+ > years of being here. When we lift stuff from filesystem specific scope (where few people care about API warts) to generic VFS scope that the whole world is expected to see, use and understand, you should expect a larger number of experienced developers to scrutinise it. The wider scope of the API means the "acceptibility bar" is set higher. Just because the code change is simple, it doesn't mean the issues surrounding the code change are simple or straight forward. Just because it went through a review on the ext4 list it doesn't mean the API or implementation is flawless. The point I'm making is that lifting fs ioctl APIs verbatim is a *known broken process* that leads to future pain fixing all the problems inherited from the original fs specific API and implementation. If we want to lift functionality to be generic VFS UAPI and at the time of lifting we find problems with the UAPI and/or implementation, then we need to fix the problems before we expose the new VFS API to the entire world. Repeat past mistakes, or learn from them. Your choice... -Dave. -- Dave Chinner david@fromorbit.com