From patchwork Thu Feb 22 10:45:17 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kara X-Patchwork-Id: 10235125 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id A72BC60349 for ; Thu, 22 Feb 2018 10:45:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B0E4A28B60 for ; Thu, 22 Feb 2018 10:45:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A570928B68; Thu, 22 Feb 2018 10:45:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 334B728B60 for ; Thu, 22 Feb 2018 10:45:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753442AbeBVKp1 (ORCPT ); Thu, 22 Feb 2018 05:45:27 -0500 Received: from mx2.suse.de ([195.135.220.15]:36032 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753438AbeBVKp0 (ORCPT ); Thu, 22 Feb 2018 05:45:26 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 2ABB8AEA0; Thu, 22 Feb 2018 10:45:25 +0000 (UTC) Received: by quack2.suse.cz (Postfix, from userid 1000) id 869991E04FE; Thu, 22 Feb 2018 11:45:22 +0100 (CET) From: Jan Kara To: Cc: Steve Kenton , =?UTF-8?q?Pali=20Roh=C3=A1r?= , Jan Kara Subject: [PATCH 3/5] udf: Clean up handling of invalid uid/gid Date: Thu, 22 Feb 2018 11:45:17 +0100 Message-Id: <20180222104519.30241-4-jack@suse.cz> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20180222104519.30241-1-jack@suse.cz> References: <20180222104519.30241-1-jack@suse.cz> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Current code relies on the fact that invalid uid/gid as defined by UDF 2.60 3.3.3.1 and 3.3.3.2 coincides with invalid uid/gid as used by the user namespaces implementation. Since this is only lucky coincidence, clean this up to avoid future surprises in case user namespaces implementation changes. Also this is more robust in presence of valid (from UDF point of view) uids / gids which do not map into current user namespace. Signed-off-by: Jan Kara --- fs/udf/inode.c | 21 +++++++++++++-------- fs/udf/udfdecl.h | 2 ++ 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/fs/udf/inode.c b/fs/udf/inode.c index 9021c15cec17..c80765d62f7e 100644 --- a/fs/udf/inode.c +++ b/fs/udf/inode.c @@ -1275,6 +1275,7 @@ static int udf_read_inode(struct inode *inode, bool hidden_inode) unsigned int indirections = 0; int bs = inode->i_sb->s_blocksize; int ret = -EIO; + uint32_t uid, gid; reread: if (iloc->partitionReferenceNum >= sbi->s_partitions) { @@ -1400,15 +1401,19 @@ static int udf_read_inode(struct inode *inode, bool hidden_inode) ret = -EIO; read_lock(&sbi->s_cred_lock); - i_uid_write(inode, le32_to_cpu(fe->uid)); - if (!uid_valid(inode->i_uid) || + uid = le32_to_cpu(fe->uid); + if (uid == UDF_INVALID_ID || UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_UID_SET)) - inode->i_uid = UDF_SB(inode->i_sb)->s_uid; + inode->i_uid = sbi->s_uid; + else + i_uid_write(inode, uid); - i_gid_write(inode, le32_to_cpu(fe->gid)); - if (!gid_valid(inode->i_gid) || + gid = le32_to_cpu(fe->gid); + if (gid == UDF_INVALID_ID || UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_GID_SET)) - inode->i_gid = UDF_SB(inode->i_sb)->s_gid; + inode->i_gid = sbi->s_gid; + else + i_gid_write(inode, gid); if (fe->icbTag.fileType != ICBTAG_FILE_TYPE_DIRECTORY && sbi->s_fmode != UDF_INVALID_MODE) @@ -1653,12 +1658,12 @@ static int udf_update_inode(struct inode *inode, int do_sync) } if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_UID_FORGET)) - fe->uid = cpu_to_le32(-1); + fe->uid = cpu_to_le32(UDF_INVALID_ID); else fe->uid = cpu_to_le32(i_uid_read(inode)); if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_GID_FORGET)) - fe->gid = cpu_to_le32(-1); + fe->gid = cpu_to_le32(UDF_INVALID_ID); else fe->gid = cpu_to_le32(i_gid_read(inode)); diff --git a/fs/udf/udfdecl.h b/fs/udf/udfdecl.h index f5e0fe78979e..68e8a64d22e0 100644 --- a/fs/udf/udfdecl.h +++ b/fs/udf/udfdecl.h @@ -48,6 +48,8 @@ extern __printf(3, 4) void _udf_warn(struct super_block *sb, #define UDF_EXTENT_LENGTH_MASK 0x3FFFFFFF #define UDF_EXTENT_FLAG_MASK 0xC0000000 +#define UDF_INVALID_ID ((uint32_t)-1) + #define UDF_NAME_PAD 4 #define UDF_NAME_LEN 254 #define UDF_NAME_LEN_CS0 255