From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx2.suse.de ([195.135.220.15]:36033 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753441AbeBVKp0 (ORCPT ); Thu, 22 Feb 2018 05:45:26 -0500 From: Jan Kara To: Cc: Steve Kenton , =?UTF-8?q?Pali=20Roh=C3=A1r?= , Jan Kara Subject: [PATCH 2/5] udf: Apply uid/gid mount options also to new inodes & chown Date: Thu, 22 Feb 2018 11:45:16 +0100 Message-Id: <20180222104519.30241-3-jack@suse.cz> In-Reply-To: <20180222104519.30241-1-jack@suse.cz> References: <20180222104519.30241-1-jack@suse.cz> Sender: linux-fsdevel-owner@vger.kernel.org List-ID: Currently newly created files belong to current user despite uid= / gid= mount options. This is confusing to users (as owner of the file will change after remount / eviction from cache) and also inconsistent with e.g. FAT with the same mount option. So apply uid= and gid= also to newly created inodes and similarly as FAT disallow to change owner of the file in this case. Reported-by: Steve Kenton Signed-off-by: Jan Kara --- fs/udf/file.c | 10 ++++++++++ fs/udf/ialloc.c | 4 ++++ 2 files changed, 14 insertions(+) diff --git a/fs/udf/file.c b/fs/udf/file.c index 356c2bf148a5..cd31e4f6d6da 100644 --- a/fs/udf/file.c +++ b/fs/udf/file.c @@ -257,12 +257,22 @@ const struct file_operations udf_file_operations = { static int udf_setattr(struct dentry *dentry, struct iattr *attr) { struct inode *inode = d_inode(dentry); + struct super_block *sb = inode->i_sb; int error; error = setattr_prepare(dentry, attr); if (error) return error; + if ((attr->ia_valid & ATTR_UID) && + UDF_QUERY_FLAG(sb, UDF_FLAG_UID_SET) && + !uid_eq(attr->ia_uid, UDF_SB(sb)->s_uid)) + return -EPERM; + if ((attr->ia_valid & ATTR_GID) && + UDF_QUERY_FLAG(sb, UDF_FLAG_GID_SET) && + !gid_eq(attr->ia_gid, UDF_SB(sb)->s_gid)) + return -EPERM; + if ((attr->ia_valid & ATTR_SIZE) && attr->ia_size != i_size_read(inode)) { error = udf_setsize(inode, attr->ia_size); diff --git a/fs/udf/ialloc.c b/fs/udf/ialloc.c index b6e420c1bfeb..b7a0d4b4bda1 100644 --- a/fs/udf/ialloc.c +++ b/fs/udf/ialloc.c @@ -104,6 +104,10 @@ struct inode *udf_new_inode(struct inode *dir, umode_t mode) } inode_init_owner(inode, dir, mode); + if (UDF_QUERY_FLAG(sb, UDF_FLAG_UID_SET)) + inode->i_uid = sbi->s_uid; + if (UDF_QUERY_FLAG(sb, UDF_FLAG_GID_SET)) + inode->i_gid = sbi->s_gid; iinfo->i_location.logicalBlockNum = block; iinfo->i_location.partitionReferenceNum = -- 2.13.6