From patchwork Thu May 9 15:14:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Albershteyn X-Patchwork-Id: 13659800 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.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 4E31315B108 for ; Thu, 9 May 2024 15:15:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715267723; cv=none; b=dc+VhplYa+0zGL/yX1enKoqov3SVlB14VDVqOo2uFBW6oLogeXMsiOmhzpGUzRRcsX/g9qieW6KuKn/Ntjj1lUxIFlLzEL/xML6qWukODCk+K1anV3XoaxNDtqgGBnBqJlSbMIeJdiP+NMUlaN08YjwV23kRUACVK3SOe3txYNc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715267723; c=relaxed/simple; bh=1NL1/dDvDNU2Zbas8ECSCxdIjF5qA2fFI3IHXBmleAo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CklsuFxw4V2ni2TxbQQ8kHAISWDQ9X2AqSLRKDCZMT4kUeFAEC/hAG+BvpkWAD6uUN2F1qXdKLHeLUNtb0LYNvtE0zeJKQwkupMvwexGkzlbsjzrjFd5xX2uLSCOT/MWmVg1ZqM95Pf8FqL0JTM9YhlUg3zNsniNUOAyYK6w+Rs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none 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=cyN4vKgN; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none 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="cyN4vKgN" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1715267718; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0fnY+juoMhGcmaJz2MhrrIFayrEdo/RaxaccJjWuLCA=; b=cyN4vKgNFrm+jTF7WrMmsiEy5iMwkewAbYhwmbP8rNwFX9qZK19yMKMsFJJzZABE61fJGm 7tdcJYuRsIqAudIHbXo4LEj2kLgbiSpGO6vcViO5yCc5EkZNrQ0HduMDCJGHY49A595RBJ ATGBSfrVn5kUTSRNW4gjVgRvpd12tYE= Received: from mail-ej1-f69.google.com (mail-ej1-f69.google.com [209.85.218.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-611-itEBC8woOgOMNtxvtRIVLg-1; Thu, 09 May 2024 11:15:16 -0400 X-MC-Unique: itEBC8woOgOMNtxvtRIVLg-1 Received: by mail-ej1-f69.google.com with SMTP id a640c23a62f3a-a59c0ecd59cso74685266b.2 for ; Thu, 09 May 2024 08:15:16 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715267715; x=1715872515; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=0fnY+juoMhGcmaJz2MhrrIFayrEdo/RaxaccJjWuLCA=; b=Pc2l5yZ7Q2trUNxyvZMPmV+cwwRnewyAZKzqzQS5aPSS0HVng2DgTtEzQZRfjua4DS 6S0A+/LHDv3mMbYWtRU1k4mSJIvdeGoByI0ysfDi3JYlhJnQt8RNt1pfPnegw9PQ6GMx KFk3zMdk4RbwxkgeCIZuH07LddyUTwRyCQ7RkypVwOuK0ngqsmfAUONRww9D6pDNuVHe 3c2UA6jXygGueOIAe7kQ9ZzXhUtLnbY/vHtXGZhYqniMgWGRSx6oi1RXwLuQoxST8Usu FFl67O9wuOFe+P1T7oSbVmG6cwjsG+7GuXPR6Vt/d9/j2b1985s+/Cyphl8S1AGVDaPd laWQ== X-Forwarded-Encrypted: i=1; AJvYcCWKvll7rEr8k2bLmBO+qEjJjUpzx45YYao5gY9u08nte5vjt+WP3cN45TPMGbDZG7UfPW0zrLkRbpNV1hcqEaggC1riiu0gD8NM X-Gm-Message-State: AOJu0YzKzwS83L01/gUym5Yw4ORDZ+5tGrPyr5GVkucfLjplu94oR8kM SZU1X4Z/Dlm7NAniyLeftwYX9jKalnEp6nxgaJ2Xy/yGQpEghoT1sPdjMObnfXHiOjBLssiRewM KQcZd1xKqhIq7u56h0fqZKo+sHaMAutWBEpyP9gMynz6xTInIpE0869iVs5o4p9HB X-Received: by 2002:a17:906:ef08:b0:a59:afdd:590a with SMTP id a640c23a62f3a-a59fb9c6b4emr654984466b.56.1715267714911; Thu, 09 May 2024 08:15:14 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEFmt7o0/NdAkyXCCoTiql70At8Tw5rG4AotCEnIbBl27agWLZSfEbyq0lrwzJ0gzNYP9udWQ== X-Received: by 2002:a17:906:ef08:b0:a59:afdd:590a with SMTP id a640c23a62f3a-a59fb9c6b4emr654979766b.56.1715267714233; Thu, 09 May 2024 08:15:14 -0700 (PDT) Received: from thinky.redhat.com ([109.183.6.197]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a5a17b01785sm82035866b.164.2024.05.09.08.15.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 May 2024 08:15:13 -0700 (PDT) From: Andrey Albershteyn To: linux-fsdevel@vgre.kernel.org, linux-xfs@vger.kernel.org Cc: Andrey Albershteyn Subject: [PATCH 1/4] fs: export copy_fsxattr_from_user() Date: Thu, 9 May 2024 17:14:57 +0200 Message-ID: <20240509151459.3622910-3-aalbersh@redhat.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240509151459.3622910-2-aalbersh@redhat.com> References: <20240509151459.3622910-2-aalbersh@redhat.com> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Export copy_fsxattr_from_user(). This function will be used in further patch by XFS in XFS_IOC_SETFSXATTRAT ioctl. Signed-off-by: Andrey Albershteyn --- fs/ioctl.c | 11 +++++++++-- include/linux/fileattr.h | 1 + 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/fs/ioctl.c b/fs/ioctl.c index 1d5abfdf0f22..2017c928194e 100644 --- a/fs/ioctl.c +++ b/fs/ioctl.c @@ -559,8 +559,14 @@ int copy_fsxattr_to_user(const struct fileattr *fa, struct fsxattr __user *ufa) } EXPORT_SYMBOL(copy_fsxattr_to_user); -static int copy_fsxattr_from_user(struct fileattr *fa, - struct fsxattr __user *ufa) +/** + * copy_fsxattr_from_user - copy fsxattr from userspace. + * @fa: fileattr pointer + * @ufa: fsxattr user pointer + * + * Return: 0 on success, or -EFAULT on failure. + */ +int copy_fsxattr_from_user(struct fileattr *fa, struct fsxattr __user *ufa) { struct fsxattr xfa; @@ -575,6 +581,7 @@ static int copy_fsxattr_from_user(struct fileattr *fa, return 0; } +EXPORT_SYMBOL(copy_fsxattr_from_user); /* * Generic function to check FS_IOC_FSSETXATTR/FS_IOC_SETFLAGS values and reject diff --git a/include/linux/fileattr.h b/include/linux/fileattr.h index 47c05a9851d0..3c4f8c75abc0 100644 --- a/include/linux/fileattr.h +++ b/include/linux/fileattr.h @@ -34,6 +34,7 @@ struct fileattr { }; int copy_fsxattr_to_user(const struct fileattr *fa, struct fsxattr __user *ufa); +int copy_fsxattr_from_user(struct fileattr *fa, struct fsxattr __user *ufa) void fileattr_fill_xflags(struct fileattr *fa, u32 xflags); void fileattr_fill_flags(struct fileattr *fa, u32 flags); From patchwork Thu May 9 15:14:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Albershteyn X-Patchwork-Id: 13659801 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.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 B29EE15E7F2 for ; Thu, 9 May 2024 15:15:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715267723; cv=none; b=l5u8j2Ej9w+Ie4jcsB0aGQ9uEyLG+ctkdkhCFelE2kkw93K98oEUVx2jNYPB7fGbm6fPHogFllgBcDGQPj4el1WFrDA3SFZvEyqkLKMAjGtD7R3F72x+z0SoczVc3oWMiHkiEBCO53kgplds4zNdtBHh479uJ8dnaP6x/fG7XPc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715267723; c=relaxed/simple; bh=fFM0/KvDvt5Y5FvHpzFj4UyoZ0PlkPOytftVHOSGlFc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YyoArqM4VYWcddzipbHqMnp5qWjQdwf4H1Qc/EuMqSm4DCXaffCXBMTCMetmFMiNDBh3/WURMQkQSevpSkokJTZALQIlfWrLGh5YWXe+qdMtFoA6NOOVUbWSC6/3kIHyz1MN4PO9920357j0Keh8xcszb1FZGVpH1hQd3dFa+FI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none 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=UMWUHExd; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none 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="UMWUHExd" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1715267718; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=bVAoqP60G64zUWYOq6YFxYCBZUQsiboflHYjc+CThqg=; b=UMWUHExd/TrBIMXrv8C8Yzan4E6hleevrf9roxnOYkupEIMwxSatO/jPaBhNXmHSGhi4w4 SXMhFIPq0ebpgFvAIWK3JYp8YbDCadyABqZuOlCrrcEjHZgrOW0gjv0tobOtfrd8Uhrmwp 7CflbOftEYmmqYoEs1cCehSmIrSZksc= Received: from mail-lf1-f72.google.com (mail-lf1-f72.google.com [209.85.167.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-695-YEGwjO-tM0SE4k9XQtkeXg-1; Thu, 09 May 2024 11:15:17 -0400 X-MC-Unique: YEGwjO-tM0SE4k9XQtkeXg-1 Received: by mail-lf1-f72.google.com with SMTP id 2adb3069b0e04-516d46e1bafso743442e87.2 for ; Thu, 09 May 2024 08:15:17 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715267716; x=1715872516; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=bVAoqP60G64zUWYOq6YFxYCBZUQsiboflHYjc+CThqg=; b=g2+cCanklZYXEPxnMkj5QJEEopsCi9AKD+fkZHOFmuJ40d7XmC0Hh/PQ92qGNMMwpO eTU/7UcyaQ0WD6rbCJj2zQKmN7krGbuooheV0+YXQPqipIwdvGDcpI2KEC4jD5iir0km /fjLSF5BiVAJyuVUQQfpwRibdMJsBgBX4bEKk3AftLIPFEhjBEkoyCJfyrBDoMA8Ppee 4A51p0PGT0OeFdIdZERlG5hqG/cgzhdlTV/g/8VI4bgCDUDHzYSeMXAHvN66JR+/Hx6I Bl+N7ZNJKhKq+2Q/+C7FHdVbw47co1hRn6KLbMQK49NX6vzh6zKiH1YQa4b82W3VeA4d 3Xtw== X-Forwarded-Encrypted: i=1; AJvYcCVTBZV7WlVEoaSEh+oLzRLzEOhuZAJmZrKH/ZBIwKtUbdZf9b/OIWTSk8xJBOvKROKy5wfFT2HJ+i7wg0GbAeNB8WEghDVmY5+k X-Gm-Message-State: AOJu0Yzdd83kC1HtR1VX3VhN7yjREv30QY5cDo+Ng3QtsN5Ypa+QKAmY 8cLmj4wdP2dsEWXFF6IA00i9z2ezwmy6UNM+m0fK4+4XnSmdbVh0lxJXFwEMQZWnrN6Ih7mrZuY mXKDWub5cti6MsthK38wfDIvRG0JD4MFY4hjFUTeHmGftsYE6V44MaTDB X-Received: by 2002:a19:2d04:0:b0:51c:cc1b:a8f6 with SMTP id 2adb3069b0e04-5217c566fa6mr4688813e87.20.1715267715502; Thu, 09 May 2024 08:15:15 -0700 (PDT) X-Google-Smtp-Source: AGHT+IED5UjVNgGIK4ztNZsNrbCNwOsZkMbo8b6l5A4/xZn7J8iHlQJs90qL6QRpE5kELHeJvC3WVQ== X-Received: by 2002:a19:2d04:0:b0:51c:cc1b:a8f6 with SMTP id 2adb3069b0e04-5217c566fa6mr4688795e87.20.1715267714882; Thu, 09 May 2024 08:15:14 -0700 (PDT) Received: from thinky.redhat.com ([109.183.6.197]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a5a17b01785sm82035866b.164.2024.05.09.08.15.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 May 2024 08:15:14 -0700 (PDT) From: Andrey Albershteyn To: linux-fsdevel@vgre.kernel.org, linux-xfs@vger.kernel.org Cc: Andrey Albershteyn Subject: [PATCH 2/4] xfs: allow renames of project-less inodes Date: Thu, 9 May 2024 17:14:58 +0200 Message-ID: <20240509151459.3622910-4-aalbersh@redhat.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240509151459.3622910-2-aalbersh@redhat.com> References: <20240509151459.3622910-2-aalbersh@redhat.com> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Identical problem as worked around in commit e23d7e82b707 ("xfs: allow cross-linking special files without project quota") exists with renames. Renaming special file without project ID is not possible inside PROJINHERIT directory. Special files inodes can not have project ID set from userspace and are skipped during initial project setup. Those inodes are left project-less in the project directory. New inodes created after project initialization do have an ID. Creating hard links or renaming those project-less inodes then fails on different ID check. Add workaround to allow renames of special files without project ID. Signed-off-by: Andrey Albershteyn --- fs/xfs/xfs_inode.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/fs/xfs/xfs_inode.c b/fs/xfs/xfs_inode.c index 58fb7a5062e1..508113515eec 100644 --- a/fs/xfs/xfs_inode.c +++ b/fs/xfs/xfs_inode.c @@ -3275,8 +3275,19 @@ xfs_rename( */ if (unlikely((target_dp->i_diflags & XFS_DIFLAG_PROJINHERIT) && target_dp->i_projid != src_ip->i_projid)) { - error = -EXDEV; - goto out_trans_cancel; + /* + * Project quota setup skips special files which can + * leave inodes in a PROJINHERIT directory without a + * project ID set. We need to allow renames to be made + * to these "project-less" inodes because userspace + * expects them to succeed after project ID setup, + * but everything else should be rejected. + */ + if (!special_file(VFS_I(src_ip)->i_mode) || + src_ip->i_projid != 0) { + error = -EXDEV; + goto out_trans_cancel; + } } /* RENAME_EXCHANGE is unique from here on. */ From patchwork Thu May 9 15:14:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Albershteyn X-Patchwork-Id: 13659802 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 8448615ECD5 for ; Thu, 9 May 2024 15:15:21 +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=1715267725; cv=none; b=eY89L8/gQjrDBGuiVaEM7OiIIzD/A6O4ODQYqSI3MtTZ6BTmIF2XgNVnLf8BxrxAt+/c98ROJWS1R5GVC0KmfbFvT+81ApmG1C0ABJbWYBQ4lhTGXRALip5ISnYLZ8msQts7kgGJOKt2vkquDDi7dH38lwzjdGiCIQwe5T1PVeY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715267725; c=relaxed/simple; bh=wGabgN3ViS3LXGqK8MnV4GfVAMac01Bfl0X3YtuibEs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VjMlsODy+5rTOCOno5s6oazowMsjQ+RDF1/owooA/T7dz4UffjFRFF9jEyOspLTWjyxxUV8srKquncY3eDlcxLpuujQNPLAJmfyeAPOh0kSRPmwb1uwhibqLeKRxWhfmqqPEPvekHx4YawB7GIyEescV0ivSLJbGBkkPemYuyBY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none 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=YrbCoI9I; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none 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="YrbCoI9I" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1715267719; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0e4X6nrV5BTjLlYzfcEyH6Yfdvhy00a+8JJmOec3j+c=; b=YrbCoI9ImmdCPNvvfdbnsDEZmoxMNS56th3k0A5vgYSwImkJz4y8B+J+hrzbiU5b1I9NPn 1C6h/yRdFE1tGRkDmtoUU41svjAHCQqF2EwkwoMpugM34kh+j065WAhMop7mHr9UUx1FEL I9PBfCPwZh2IxrQG3zBFaNYFIeNOuiE= Received: from mail-ej1-f69.google.com (mail-ej1-f69.google.com [209.85.218.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-508-P0O4wKwFMUuU7yYtqbxHRA-1; Thu, 09 May 2024 11:15:17 -0400 X-MC-Unique: P0O4wKwFMUuU7yYtqbxHRA-1 Received: by mail-ej1-f69.google.com with SMTP id a640c23a62f3a-a59a0014904so56760466b.2 for ; Thu, 09 May 2024 08:15:17 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715267717; x=1715872517; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=0e4X6nrV5BTjLlYzfcEyH6Yfdvhy00a+8JJmOec3j+c=; b=atHimgo7XpYcx7ogSM84HezT6UuuqA2qkHVhfQWblurDCUXq94KaM7gvsrsJd83dZc cqJsZmEoqTQ1ogH9R+LoyepjgScab4WeuFfha2jyu1v+2SMHFIvyiFgXMX0xZRQ7sANr XYouxxuk+okOLpBVcTJTAsrewfO2+aYtGnXnoi7NA4E9g9PuAlD9WywqaLc6c6lL00nb B3YKhC4XBkAHGgAsomFv1Nf/5BQA2VhBRWG6utpgGwdzzrwDYWLPtO8oCDh/f3ESkLmT i19nWPy+i5V2xp82nqSApNrjxlFIGD4vd10VIUjFY3ED8aT1AsqgOt/jLs+c0LOTB61H bmvg== X-Forwarded-Encrypted: i=1; AJvYcCWxBA2V+SIOaJwIy4bxZs1Wor9OxJYCT2CS1qPp97usZAUc1Z/p9I3QurruOjCsSjwAhDNIR59ONpQSTTMdQGUM2uMgf6pax083 X-Gm-Message-State: AOJu0YyJFaO8Z2M94GP5aTE4BKx77SRGkbv5WzxQP8aYbdCBGnydJt7s 2XA0ltY+lSGl52xtI8hVZPAft6Tj/1yA2/ihVK/InnRSq7mF3JfUvy/nWBQ425jGcZTPWisQX7E Qbojppuxm9XGHh/HLW0qEDkkcRw3Xukery/FReTm5VIuSeVaGcBwVHci5 X-Received: by 2002:a17:906:5017:b0:a59:aa69:9794 with SMTP id a640c23a62f3a-a59fb94d56fmr353853666b.18.1715267716512; Thu, 09 May 2024 08:15:16 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE+xUZ3ZGPToiQTnNEgrEyiek4dg5ec3coG1773rz+tUoLYHjA19/LQvzfB5EZwFn5YJfJSNQ== X-Received: by 2002:a17:906:5017:b0:a59:aa69:9794 with SMTP id a640c23a62f3a-a59fb94d56fmr353851766b.18.1715267716021; Thu, 09 May 2024 08:15:16 -0700 (PDT) Received: from thinky.redhat.com ([109.183.6.197]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a5a17b01785sm82035866b.164.2024.05.09.08.15.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 May 2024 08:15:15 -0700 (PDT) From: Andrey Albershteyn To: linux-fsdevel@vgre.kernel.org, linux-xfs@vger.kernel.org Cc: Andrey Albershteyn Subject: [PATCH 3/4] xfs: allow setting xattrs on special files Date: Thu, 9 May 2024 17:14:59 +0200 Message-ID: <20240509151459.3622910-5-aalbersh@redhat.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240509151459.3622910-2-aalbersh@redhat.com> References: <20240509151459.3622910-2-aalbersh@redhat.com> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 As XFS didn't have ioctls for special files setting an inode extended attributes was rejected for them in xfs_fileattr_set(). Same applies for reading. With XFS's project quota directories this is necessary. When project is setup, xfs_quota opens and calls FS_IOC_SETFSXATTR on every inode in the directory. However, special files are skipped due to open() returning a special inode for them. So, they don't even get to this check. The further patch introduces XFS_IOC_SETFSXATTRAT which will call xfs_fileattr_set/get() on a special file. This patch add handling of setting xflags and project ID for special files. Signed-off-by: Andrey Albershteyn --- fs/xfs/xfs_ioctl.c | 96 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 92 insertions(+), 4 deletions(-) diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c index f0117188f302..515c9b4b862d 100644 --- a/fs/xfs/xfs_ioctl.c +++ b/fs/xfs/xfs_ioctl.c @@ -459,9 +459,6 @@ xfs_fileattr_get( { struct xfs_inode *ip = XFS_I(d_inode(dentry)); - if (d_is_special(dentry)) - return -ENOTTY; - xfs_ilock(ip, XFS_ILOCK_SHARED); xfs_fill_fsxattr(ip, XFS_DATA_FORK, fa); xfs_iunlock(ip, XFS_ILOCK_SHARED); @@ -721,6 +718,97 @@ xfs_ioctl_setattr_check_projid( return 0; } +static int +xfs_fileattr_spec_set( + struct mnt_idmap *idmap, + struct dentry *dentry, + struct fileattr *fa) +{ + struct xfs_inode *ip = XFS_I(d_inode(dentry)); + struct xfs_mount *mp = ip->i_mount; + struct xfs_trans *tp; + struct xfs_dquot *pdqp = NULL; + struct xfs_dquot *olddquot = NULL; + int error; + + if (!fa->fsx_valid) + return -EOPNOTSUPP; + + if (fa->fsx_extsize || + fa->fsx_nextents || + fa->fsx_cowextsize) + return -EOPNOTSUPP; + + error = xfs_ioctl_setattr_check_projid(ip, fa); + if (error) + return error; + + /* + * If disk quotas is on, we make sure that the dquots do exist on disk, + * before we start any other transactions. Trying to do this later + * is messy. We don't care to take a readlock to look at the ids + * in inode here, because we can't hold it across the trans_reserve. + * If the IDs do change before we take the ilock, we're covered + * because the i_*dquot fields will get updated anyway. + */ + if (fa->fsx_valid && XFS_IS_QUOTA_ON(mp)) { + error = xfs_qm_vop_dqalloc(ip, VFS_I(ip)->i_uid, + VFS_I(ip)->i_gid, fa->fsx_projid, + XFS_QMOPT_PQUOTA, NULL, NULL, &pdqp); + if (error) + return error; + } + + tp = xfs_ioctl_setattr_get_trans(ip, pdqp); + if (IS_ERR(tp)) { + error = PTR_ERR(tp); + goto error_free_dquots; + } + + error = xfs_ioctl_setattr_xflags(tp, ip, fa); + if (error) + goto error_trans_cancel; + + /* + * Change file ownership. Must be the owner or privileged. CAP_FSETID + * overrides the following restrictions: + * + * The set-user-ID and set-group-ID bits of a file will be cleared upon + * successful return from chown() + */ + + if ((VFS_I(ip)->i_mode & (S_ISUID | S_ISGID)) && + !capable_wrt_inode_uidgid(idmap, VFS_I(ip), CAP_FSETID)) + VFS_I(ip)->i_mode &= ~(S_ISUID | S_ISGID); + + /* Change the ownerships and register project quota modifications */ + if (ip->i_projid != fa->fsx_projid) { + if (XFS_IS_PQUOTA_ON(mp)) { + olddquot = + xfs_qm_vop_chown(tp, ip, &ip->i_pdquot, pdqp); + } + ip->i_projid = fa->fsx_projid; + } + + error = xfs_trans_commit(tp); + + /* + * Release any dquot(s) the inode had kept before chown. + */ + xfs_qm_dqrele(olddquot); + xfs_qm_dqrele(pdqp); + + return error; + +error_trans_cancel: + xfs_trans_cancel(tp); +error_free_dquots: + xfs_qm_dqrele(pdqp); + return error; + + return 0; +} + int xfs_fileattr_set( struct mnt_idmap *idmap, @@ -737,7 +825,7 @@ xfs_fileattr_set( trace_xfs_ioctl_setattr(ip); if (d_is_special(dentry)) - return -ENOTTY; + return xfs_fileattr_spec_set(idmap, dentry, fa); if (!fa->fsx_valid) { if (fa->flags & ~(FS_IMMUTABLE_FL | FS_APPEND_FL | From patchwork Thu May 9 15:15:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Albershteyn X-Patchwork-Id: 13659803 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 8C3A815ECEF for ; Thu, 9 May 2024 15:15:21 +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=1715267725; cv=none; b=Flfs+WPNjJ7p3wtlbD/N45OZZVcryTmDQxghYzG6ShC5HGPshFasiAT2WCI+8XScYe1xMUklYsDJwy1f3cGGwH4EO+249yuYn5tWSjz5+/TiJ4yhuWAhGlmLQBmEn11mxwX4Z59XrG1NC/OJ+io5kP+eM2fPXB1w9wp0LNs1d5U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715267725; c=relaxed/simple; bh=B+MXNH6SjKJPDVfwlZCqff4StUEqeP2tU28dLpP82KU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HwnG6bxMjikmaTVnCs8u10GWChn98XxFnZvt4O1DrTJlezKIME2wedBP71+bCXPiV5nLIYvxmyejvZsAOrFQxxfssG05YKUpHWnZLaJDrETefCR0Xvr9OPaVVeexqgxJbTpHOmrNrPgFphfxN4uPcRCPTzd24NCdmUWV/BWViKY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none 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=ND6fYyTI; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none 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="ND6fYyTI" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1715267720; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=RY+ugPrDK83tQomk3xmQyphPy5GlvX952C2zVFWwL9A=; b=ND6fYyTICvGbN78Gd2Ww33QMolE3etpDjiv7B/Gp7mdxbVSpKPQTF0/HZVnGdB+BU18N1F 0IcrgibP5lVOiijqqyMzHdTwB0DmNqc+WyFVnSdxoSviv6sonqIOjd7JGiWniJXf5yGfsc Y1qPOXbldtc03nIO4Ol8CGAmLgi38kc= Received: from mail-ej1-f71.google.com (mail-ej1-f71.google.com [209.85.218.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-18-g8jaVV2EMSWgHft5EyZQJA-1; Thu, 09 May 2024 11:15:18 -0400 X-MC-Unique: g8jaVV2EMSWgHft5EyZQJA-1 Received: by mail-ej1-f71.google.com with SMTP id a640c23a62f3a-a592c35ac06so104578066b.0 for ; Thu, 09 May 2024 08:15:18 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715267717; x=1715872517; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=RY+ugPrDK83tQomk3xmQyphPy5GlvX952C2zVFWwL9A=; b=WzbbsQ8ET5yvXbixusuU6Uox3tFnpi1YqI9qkDCKmIWeS81MG399+pT+6tMHd+Pi2j lysmmToS1NvWQu0cMJzZgluZhsPONhIv/jXJwXABWup5D3g6tSndCAv3xDVFEhnyWu8c 7xvDQy614solknN6YXju5S5o+V6xm5+xt0FD8P8woWWuJzpwnA5ad2VBx+ba1bxaU53C l7Jt7VQDtPX5tXtvDmyCY0I2O8GqCXMPFLADD7ErxZbb3+S6fd8vSMjRzWU9ygU4B46O 89bfKY+liVfqG91WuR2AReIbp8gBpEDZY3vQ9yuaBeLTIa/JnELNB3msjVIK2HbtWxxt e7/Q== X-Forwarded-Encrypted: i=1; AJvYcCXhnaC0p/oU+uXllhcXwXVhpl2zII2izTJq7ZMuMo/UC7tnJmVL8RvdYkcRCS8w2mkarjtHJV+27h6u9aJXnS9bXtMfxgcTip4v X-Gm-Message-State: AOJu0YzgCcEx9RuM75WxA5Ud0wXbqk5bs0M6wqpJfB1EPLXd2TLsnKN1 sj+n73hyPQagYmH6UUrRFu8xz6Um+jpVldlG3LszCbLYGCI9STvV2TspFNvYCLOAN7Y0DciaEeR 7FcNERHs11JzIpn0xRulJYcSVW8zFT3R+h1E+zUfCNJUYuhRI82jCYKWL X-Received: by 2002:a17:906:2a11:b0:a59:a85c:a5ca with SMTP id a640c23a62f3a-a5a2d18b04amr940666b.7.1715267717239; Thu, 09 May 2024 08:15:17 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGSiXphLOfsmbMLx7yciNd95cjz6zMV0Vui4i9K4qSbDDKW3Q5leA26X5GzVYRPu8Dd9WV0Lw== X-Received: by 2002:a17:906:2a11:b0:a59:a85c:a5ca with SMTP id a640c23a62f3a-a5a2d18b04amr937766b.7.1715267716702; Thu, 09 May 2024 08:15:16 -0700 (PDT) Received: from thinky.redhat.com ([109.183.6.197]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a5a17b01785sm82035866b.164.2024.05.09.08.15.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 May 2024 08:15:16 -0700 (PDT) From: Andrey Albershteyn To: linux-fsdevel@vgre.kernel.org, linux-xfs@vger.kernel.org Cc: Andrey Albershteyn Subject: [PATCH 4/4] xfs: add XFS_IOC_SETFSXATTRAT and XFS_IOC_GETFSXATTRAT Date: Thu, 9 May 2024 17:15:00 +0200 Message-ID: <20240509151459.3622910-6-aalbersh@redhat.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240509151459.3622910-2-aalbersh@redhat.com> References: <20240509151459.3622910-2-aalbersh@redhat.com> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 XFS has project quotas which could be attached to a directory. All new inodes in these directories inherit project ID. 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. as opening them return special inode from VFS. Therefore, some inodes are left with empty project ID. This patch adds new XFS ioctl which allows userspace, such as xfs_quota, to set project ID on special files. This will let xfs_quota set ID on all inodes and also reset it when project is removed. Signed-off-by: Andrey Albershteyn --- fs/xfs/libxfs/xfs_fs.h | 11 +++++ fs/xfs/xfs_ioctl.c | 86 ++++++++++++++++++++++++++++++++++++++++ include/linux/fileattr.h | 2 +- 3 files changed, 98 insertions(+), 1 deletion(-) diff --git a/fs/xfs/libxfs/xfs_fs.h b/fs/xfs/libxfs/xfs_fs.h index 97996cb79aaa..f68e98005d4b 100644 --- a/fs/xfs/libxfs/xfs_fs.h +++ b/fs/xfs/libxfs/xfs_fs.h @@ -670,6 +670,15 @@ typedef struct xfs_swapext struct xfs_bstat sx_stat; /* stat of target b4 copy */ } xfs_swapext_t; +/* + * Structure passed to XFS_IOC_GETFSXATTRAT/XFS_IOC_GETFSXATTRAT + */ +struct xfs_xattrat_req { + struct fsxattr __user *fsx; /* XATTR to get/set */ + __u32 dfd; /* parent dir */ + const char __user *path; +}; + /* * Flags for going down operation */ @@ -997,6 +1006,8 @@ struct xfs_getparents_by_handle { #define XFS_IOC_BULKSTAT _IOR ('X', 127, struct xfs_bulkstat_req) #define XFS_IOC_INUMBERS _IOR ('X', 128, struct xfs_inumbers_req) #define XFS_IOC_EXCHANGE_RANGE _IOWR('X', 129, struct xfs_exchange_range) +#define XFS_IOC_GETFSXATTRAT _IOR ('X', 130, struct xfs_xattrat_req) +#define XFS_IOC_SETFSXATTRAT _IOW ('X', 131, struct xfs_xattrat_req) /* XFS_IOC_GETFSUUID ---------- deprecated 140 */ diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c index 515c9b4b862d..d54dba9128a0 100644 --- a/fs/xfs/xfs_ioctl.c +++ b/fs/xfs/xfs_ioctl.c @@ -1408,6 +1408,74 @@ xfs_ioctl_fs_counts( return 0; } +static int +xfs_xattrat_get( + struct file *dir, + const char __user *pathname, + struct xfs_xattrat_req *xreq) +{ + struct path filepath; + struct xfs_inode *ip; + struct fileattr fa; + int error = -EBADF; + + memset(&fa, 0, sizeof(struct fileattr)); + + if (!S_ISDIR(file_inode(dir)->i_mode)) + return error; + + error = user_path_at(xreq->dfd, pathname, 0, &filepath); + if (error) + return error; + + ip = XFS_I(filepath.dentry->d_inode); + + xfs_ilock(ip, XFS_ILOCK_SHARED); + xfs_fill_fsxattr(ip, XFS_DATA_FORK, &fa); + xfs_iunlock(ip, XFS_ILOCK_SHARED); + + error = copy_fsxattr_to_user(&fa, xreq->fsx); + + path_put(&filepath); + return error; +} + +static int +xfs_xattrat_set( + struct file *dir, + const char __user *pathname, + struct xfs_xattrat_req *xreq) +{ + struct fileattr fa; + struct path filepath; + struct mnt_idmap *idmap = file_mnt_idmap(dir); + int error = -EBADF; + + if (!S_ISDIR(file_inode(dir)->i_mode)) + return error; + + error = copy_fsxattr_from_user(&fa, xreq->fsx); + if (error) + return error; + + error = user_path_at(xreq->dfd, pathname, 0, &filepath); + if (error) + return error; + + error = mnt_want_write(filepath.mnt); + if (error) { + path_put(&filepath); + return error; + } + + fa.fsx_valid = true; + error = vfs_fileattr_set(idmap, filepath.dentry, &fa); + + mnt_drop_write(filepath.mnt); + path_put(&filepath); + return error; +} + /* * These long-unused ioctls were removed from the official ioctl API in 5.17, * but retain these definitions so that we can log warnings about them. @@ -1652,6 +1720,24 @@ xfs_file_ioctl( sb_end_write(mp->m_super); return error; } + case XFS_IOC_GETFSXATTRAT: { + struct xfs_xattrat_req xreq; + + if (copy_from_user(&xreq, arg, sizeof(struct xfs_xattrat_req))) + return -EFAULT; + + error = xfs_xattrat_get(filp, xreq.path, &xreq); + return error; + } + case XFS_IOC_SETFSXATTRAT: { + struct xfs_xattrat_req xreq; + + if (copy_from_user(&xreq, arg, sizeof(struct xfs_xattrat_req))) + return -EFAULT; + + error = xfs_xattrat_set(filp, xreq.path, &xreq); + return error; + } case XFS_IOC_EXCHANGE_RANGE: return xfs_ioc_exchange_range(filp, arg); diff --git a/include/linux/fileattr.h b/include/linux/fileattr.h index 3c4f8c75abc0..8598e94b530b 100644 --- a/include/linux/fileattr.h +++ b/include/linux/fileattr.h @@ -34,7 +34,7 @@ struct fileattr { }; int copy_fsxattr_to_user(const struct fileattr *fa, struct fsxattr __user *ufa); -int copy_fsxattr_from_user(struct fileattr *fa, struct fsxattr __user *ufa) +int copy_fsxattr_from_user(struct fileattr *fa, struct fsxattr __user *ufa); void fileattr_fill_xflags(struct fileattr *fa, u32 xflags); void fileattr_fill_flags(struct fileattr *fa, u32 flags);