From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1342B2951D2 for ; Mon, 12 May 2025 13:27:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747056466; cv=none; b=PnnswOJX5ASSq72jpchvASmeQPy1YnVEpfKWHKGvAe3S3msFmmF81L3xKT1uJdOuwW2Dj7OiAUhrvFfwf3SjAVlJFyXhvDFx8mOyQWTFsfMJkLZSeSsOUR3cyfGJLG1xjIOG7up4JdICnHTl3F0EXoWg24jFyWPAPXP7+xmcEGU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747056466; c=relaxed/simple; bh=gScTXsZRGDYE+022QBdwDbpPUwWWidavzWWjs4WLfnQ=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=NflTix5AD6ssEzRtkRBMzrFta4A48aJlsOPmvBSqzUfstAWon9OA1htDAB7qDhgGyinBHJocuprGFgBJzie8TzNopU2ougbUXQkpl1drxe7J2u5672X6Zh0YQQwsMIoslaQbOmzWJSHiyxdcrt3MBMBr9LQam7rqAv6Gzz2KIgk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=bkymATKQ; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="bkymATKQ" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1747056461; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=iGGf03vY07V5lmldCU9BJs4LhScCZSGAvX7drfDcFVs=; b=bkymATKQr4a7/hvpOIw8tU2gpHkeXZGCKCImvF05adIIFXCs1PZGu/IKwcJiU0GQe/Avhe O/36UbHMH6Onl7td4stosKlMX1T7a9osdmMJD6mSDxsxOvJPA3QR8zvUEwZdNfHLg89+61 59yhgNF0bJbknf086+ZMKGRDXlQeRS0= Received: from mail-ej1-f70.google.com (mail-ej1-f70.google.com [209.85.218.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-518-p6eirGLqN2WWqKVODEX_kQ-1; Mon, 12 May 2025 09:27:39 -0400 X-MC-Unique: p6eirGLqN2WWqKVODEX_kQ-1 X-Mimecast-MFC-AGG-ID: p6eirGLqN2WWqKVODEX_kQ_1747056459 Received: by mail-ej1-f70.google.com with SMTP id a640c23a62f3a-ab68fbe53a4so409764766b.2 for ; Mon, 12 May 2025 06:27:39 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1747056453; x=1747661253; h=in-reply-to: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=iGGf03vY07V5lmldCU9BJs4LhScCZSGAvX7drfDcFVs=; b=nIFp4KXfQ0PyX2FNvUwGCarMm3gI4STfwkMfdp7y5+m3BQcHlFq1ZxZil2HIS4Nixk YS4yEqRJtj1KvtAxNqU/Yp+vJIU++D4WpsHl8i8l8uu+hXyqftq9c1szNoWAk21kVXhN nFwORWq0p2Ze/OLfRQXMNFZod7+ltUr0i1Vu1o+ZSfjWOTF67awf29TXg4o+2JBB0NqE mc8l7PQuwb7iKYtfOAvM2IRv3YT4wQJ46OXKqzLlS37b/EUr4YmqGhjrw4jqqCN4kofU LOMgZJcPyYNMwFXsvIl7dUaFhdbnLmyRV2jLsLvJY3MCIUbIgixTUiNqCdNP1ygJWMpO TRZA== X-Gm-Message-State: AOJu0Yxhx1XG4eckd7w8hritPu5bb7mTZi5qWyTIz+1WuBRRopqarHoY UE4wCH4H/87Jo8otD/rnR7W4Y6A2bPVh7mAFUy/AaMa9wo5pO40xb/DBzlgvkqaAnndpK+RFrxl yhG7pD1X3TQFq8rRnlzb0XoREr2ffgAmclJVSi0nmMF1coMWNsYJ00JS50vs= X-Gm-Gg: ASbGncsAuWDqsxiPDpEgSldfmePHdl8ddSs7OTXy5V34Q01ESLCEDzIecLiouaLuXBY AEbg2VaXkWju6qHCqNZ41vWEu61GHEToTfrjD4zSe34n9H8X2iYUaVcpPJVby3reSEtOcdpn67W KBjF4V6GdTOgla0Lyequeqhoa6toZssD3uhW/ugxFuqDaeTAX9jNT0YZJXoB2G+lnkPDST1dDh+ 3dVm0KfN6ItzB2+UuLyrvAsq9/RAhto1Q18Q0gzzb5N3zn9+eWKQbtNAMOR89XGJfRYB2UlkxqN nbTwF5JmzKVEJivK+1J24U4tjZ0We4Ik+A2+yrTj X-Received: by 2002:a17:907:9445:b0:ad2:4fb7:6cd7 with SMTP id a640c23a62f3a-ad24fb76ef4mr525375266b.2.1747056453501; Mon, 12 May 2025 06:27:33 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHm4UNzZCaTm3fHiXFFpEAhvK4jv+cPjTSwVPTo38ODFU1cRFitMK9hJpp/EAl8sqqyR4widQ== X-Received: by 2002:a17:907:9445:b0:ad2:4fb7:6cd7 with SMTP id a640c23a62f3a-ad24fb76ef4mr525364866b.2.1747056452886; Mon, 12 May 2025 06:27:32 -0700 (PDT) Received: from thinky (109-92-26-237.static.isp.telekom.rs. [109.92.26.237]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ad21988d6bdsm610935066b.180.2025.05.12.06.27.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 May 2025 06:27:32 -0700 (PDT) Date: Mon, 12 May 2025 15:27:29 +0200 From: Andrey Albershteyn To: Richard Henderson , Matt Turner , Russell King , Catalin Marinas , Will Deacon , Geert Uytterhoeven , Michal Simek , Thomas Bogendoerfer , "James E.J. Bottomley" , Helge Deller , Madhavan Srinivasan , Michael Ellerman , Nicholas Piggin , Christophe Leroy , Naveen N Rao , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Christian Borntraeger , Sven Schnelle , Yoshinori Sato , Rich Felker , John Paul Adrian Glaubitz , "David S. Miller" , Andreas Larsson , Andy Lutomirski , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Chris Zankel , Max Filippov , Alexander Viro , Christian Brauner , Jan Kara , =?utf-8?Q?Micka=C3=ABl_Sala=C3=BCn?= , =?utf-8?Q?G=C3=BCnther?= Noack , Arnd Bergmann , Pali =?utf-8?B?Um9ow6Fy?= , Paul Moore , James Morris , "Serge E. Hallyn" , Stephen Smalley , Ondrej Mosnacek , Tyler Hicks , Miklos Szeredi , Amir Goldstein Cc: linux-alpha@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-m68k@lists.linux-m68k.org, linux-mips@vger.kernel.org, linux-parisc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-s390@vger.kernel.org, linux-sh@vger.kernel.org, sparclinux@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-security-module@vger.kernel.org, linux-api@vger.kernel.org, linux-arch@vger.kernel.org, selinux@vger.kernel.org, ecryptfs@vger.kernel.org, linux-unionfs@vger.kernel.org, linux-xfs@vger.kernel.org, Andrey Albershteyn Subject: Re: [PATCH v5 0/7] fs: introduce file_getattr and file_setattr syscalls Message-ID: References: <20250512-xattrat-syscall-v5-0-4cd6821e8ff7@kernel.org> Precedence: bulk X-Mailing-List: linux-alpha@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20250512-xattrat-syscall-v5-0-4cd6821e8ff7@kernel.org> On 2025-05-12 15:25:11, Andrey Albershteyn wrote: > This patchset introduced two new syscalls file_getattr() and > file_setattr(). These syscalls are similar to FS_IOC_FSSETXATTR ioctl() > except they use *at() semantics. Therefore, there's no need to open the > file to get a fd. > > These syscalls allow userspace to set filesystem inode attributes on > special files. One of the usage examples is XFS quota projects. > > XFS has project quotas which could be attached to a directory. All > new inodes in these directories inherit project ID set on parent > directory. > > The project is created from userspace by opening and calling > FS_IOC_FSSETXATTR on each inode. This is not possible for special > files such as FIFO, SOCK, BLK etc. Therefore, some inodes are left > with empty project ID. Those inodes then are not shown in the quota > accounting but still exist in the directory. This is not critical but in > the case when special files are created in the directory with already > existing project quota, these new inodes inherit extended attributes. > This creates a mix of special files with and without attributes. > Moreover, special files with attributes don't have a possibility to > become clear or change the attributes. This, in turn, prevents userspace > from re-creating quota project on these existing files. > > NAME > > file_getattr/file_setattr - get/set filesystem inode attributes > > SYNOPSIS > > #include /* Definition of SYS_* constants */ > #include > > long syscall(SYS_file_getattr, int dirfd, const char *pathname, > struct fsxattr *fsx, size_t size, unsigned int at_flags); > long syscall(SYS_file_setattr, int dirfd, const char *pathname, > struct fsxattr *fsx, size_t size, unsigned int at_flags); > > Note: glibc doesn't provide for file_getattr()/file_setattr(), > use syscall(2) instead. > > DESCRIPTION > > The syscalls take fd and path. If path is absolute, fd is not > used. If path is empty, fd can be AT_FDCWD or any valid fd which > will be used to get/set attributes on. > > This is an alternative to FS_IOC_FSGETXATTR/FS_IOC_FSSETXATTR > ioctl with a difference that file don't need to be open as we > can reference it with a path instead of fd. By having this we > can manipulated filesystem inode attributes not only on regular > files but also on special ones. This is not possible with > FS_IOC_FSSETXATTR ioctl as with special files we can not call > ioctl() directly on the filesystem inode using file descriptor. > > at_flags can be set to AT_SYMLINK_NOFOLLOW or AT_EMPTY_PATH. > > RETURN VALUE > > On success, 0 is returned. On error, -1 is returned, and errno > is set to indicate the error. > > ERRORS > > EINVAL Invalid at_flag specified (only > AT_SYMLINK_NOFOLLOW and AT_EMPTY_PATH is > supported). > > EINVAL Size was smaller than any known version of > struct fsxattr. > > EINVAL Invalid combination of parameters provided in > fsxattr for this type of file. > > E2BIG Size of input argument **struct fsxattr** is too > big. > > EBADF Invalid file descriptor was provided. > > EPERM No permission to change this file. > > EOPNOTSUPP Filesystem does not support setting attributes > on this type of inode > > HISTORY > > Added in Linux 6.15. > > EXAMPLE > > Create directory and file "mkdir ./dir && touch ./dir/foo" and then > execute the following program: > > #include > #include > #include > #include > #include > #include > #include > > int > main(int argc, char **argv) { > int dfd; > int error; > struct fsxattr fsx; > > dfd = open("./dir", O_RDONLY); > if (dfd == -1) { > printf("can not open ./dir"); > return dfd; > } > > error = syscall(467, dfd, "./foo", &fsx, 0); > if (error) { > printf("can not call 467: %s", strerror(errno)); > return error; > } > > printf("dir/foo flags: %d\n", fsx.fsx_xflags); > > fsx.fsx_xflags |= FS_XFLAG_NODUMP; > error = syscall(468, dfd, "./foo", &fsx, 0); > if (error) { > printf("can not call 468: %s", strerror(errno)); > return error; > } > > printf("dir/foo flags: %d\n", fsx.fsx_xflags); > > return error; > } > > SEE ALSO > > ioctl(2), ioctl_iflags(2), ioctl_xfs_fsgetxattr(2) > > --- > Changes in v5: > - Remove setting of LOOKUP_EMPTY flags which does not have any effect > - Return -ENOSUPP from vfs_fileattr_set() > - Add fsxattr masking (by Amir) > - Fix UAF issue dentry > - Fix getname_maybe_null() issue with NULL path > - Implement file_getattr/file_setattr hooks > - Return LSM return code from file_setattr > - Rename from getfsxattrat/setfsxattrat to file_getattr/file_setattr > - Link to v4: https://lore.kernel.org/r/20250321-xattrat-syscall-v4-0-3e82e6fb3264@kernel.org > > Changes in v4: > - Use getname_maybe_null() for correct handling of dfd + path semantic > - Remove restriction for special files on which flags are allowed > - Utilize copy_struct_from_user() for better future compatibility > - Add draft man page to cover letter > - Convert -ENOIOCTLCMD to -EOPNOSUPP as more appropriate for syscall > - Add missing __user to header declaration of syscalls > - Link to v3: https://lore.kernel.org/r/20250211-xattrat-syscall-v3-1-a07d15f898b2@kernel.org > > Changes in v3: > - Remove unnecessary "dfd is dir" check as it checked in user_path_at() > - Remove unnecessary "same filesystem" check > - Use CLASS() instead of directly calling fdget/fdput > - Link to v2: https://lore.kernel.org/r/20250122-xattrat-syscall-v2-1-5b360d4fbcb2@kernel.org > > v1: > https://lore.kernel.org/linuxppc-dev/20250109174540.893098-1-aalbersh@kernel.org/ > > Previous discussion: > https://lore.kernel.org/linux-xfs/20240520164624.665269-2-aalbersh@redhat.com/ > > --- > Amir Goldstein (1): > fs: prepare for extending file_get/setattr() > > Andrey Albershteyn (6): > fs: split fileattr related helpers into separate file > lsm: introduce new hooks for setting/getting inode fsxattr > selinux: implement inode_file_[g|s]etattr hooks > fs: split fileattr/fsxattr converters into helpers > fs: make vfs_fileattr_[get|set] return -EOPNOSUPP > fs: introduce file_getattr and file_setattr syscalls > > arch/alpha/kernel/syscalls/syscall.tbl | 2 + > arch/arm/tools/syscall.tbl | 2 + > arch/arm64/tools/syscall_32.tbl | 2 + > arch/m68k/kernel/syscalls/syscall.tbl | 2 + > arch/microblaze/kernel/syscalls/syscall.tbl | 2 + > arch/mips/kernel/syscalls/syscall_n32.tbl | 2 + > arch/mips/kernel/syscalls/syscall_n64.tbl | 2 + > arch/mips/kernel/syscalls/syscall_o32.tbl | 2 + > arch/parisc/kernel/syscalls/syscall.tbl | 2 + > arch/powerpc/kernel/syscalls/syscall.tbl | 2 + > arch/s390/kernel/syscalls/syscall.tbl | 2 + > arch/sh/kernel/syscalls/syscall.tbl | 2 + > arch/sparc/kernel/syscalls/syscall.tbl | 2 + > arch/x86/entry/syscalls/syscall_32.tbl | 2 + > arch/x86/entry/syscalls/syscall_64.tbl | 2 + > arch/xtensa/kernel/syscalls/syscall.tbl | 2 + > fs/Makefile | 3 +- > fs/ecryptfs/inode.c | 8 +- > fs/file_attr.c | 475 ++++++++++++++++++++++++++++ > fs/ioctl.c | 309 ------------------ > fs/overlayfs/inode.c | 2 +- > include/linux/fileattr.h | 26 ++ > include/linux/lsm_hook_defs.h | 2 + > include/linux/security.h | 16 + > include/linux/syscalls.h | 6 + > include/uapi/asm-generic/unistd.h | 8 +- > include/uapi/linux/fs.h | 3 + > security/security.c | 30 ++ > security/selinux/hooks.c | 14 + > 29 files changed, 621 insertions(+), 313 deletions(-) > --- > base-commit: 0d8d44db295ccad20052d6301ef49ff01fb8ae2d > change-id: 20250114-xattrat-syscall-6a1136d2db59 > > Best regards, > -- > Andrey Albershteyn > Ignore please, somehow b4 crashed with timeout on gmail -- - Andrey