From c282223ac21d9c25bb33040b4ef41048d1f5284a Mon Sep 17 00:00:00 2001 From: Theodore Ts'o Date: Thu, 10 May 2018 11:54:14 -0400 Subject: [PATCH] add patch use-XATTR_CREATE-in-ext4_initxattrs --- series | 1 + timestamps | 7 +++-- use-XATTR_CREATE-in-ext4_initxattrs | 56 +++++++++++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+), 3 deletions(-) create mode 100644 use-XATTR_CREATE-in-ext4_initxattrs diff --git a/series b/series index ad1b8ded..a633d9a3 100644 --- a/series +++ b/series @@ -1,6 +1,7 @@ # v4.17-rc4 make-ext4_getfsmap_find_fixed_metadata-static +use-XATTR_CREATE-in-ext4_initxattrs #################################################### # unstable patches diff --git a/timestamps b/timestamps index 593e55cc..ad0c5267 100755 --- a/timestamps +++ b/timestamps @@ -34,7 +34,8 @@ touch -d @1523242124 disable-writeback touch -d @1523242124 load-jmap-from-journal touch -d @1523242125 add-ext4-journal-lazy-mount-option touch -d @1524717946 stable-boundary -touch -d @1525967371 series touch -d @1525967404 make-ext4_getfsmap_find_fixed_metadata-static -touch -d @1525967410 status -touch -d @1525967487 timestamps +touch -d @1525967534 use-XATTR_CREATE-in-ext4_initxattrs +touch -d @1525967572 series +touch -d @1525967577 status +touch -d @1525967646 timestamps diff --git a/use-XATTR_CREATE-in-ext4_initxattrs b/use-XATTR_CREATE-in-ext4_initxattrs new file mode 100644 index 00000000..75d127f9 --- /dev/null +++ b/use-XATTR_CREATE-in-ext4_initxattrs @@ -0,0 +1,56 @@ +ext4: use XATTR_CREATE in ext4_initxattrs() + +From: Eryu Guan + +I hit ENOSPC error when creating new file in a newly created ext4 +with ea_inode feature enabled, if selinux is enabled and ext4 is +mounted without any selinux context. e.g. + + mkfs -t ext4 -O ea_inode -F /dev/sda5 + mount /dev/sda5 /mnt/ext4 + touch /mnt/ext4/testfile # got ENOSPC here + +It turns out that we run out of journal credits in +ext4_xattr_set_handle() when creating new selinux label for the +newly created inode. + +This is because that in __ext4_new_inode() we use +__ext4_xattr_set_credits() to calculate the reserved credits for new +xattr, with the 'is_create' argument being true, which implies less +credits in the ea_inode case. But we calculate the required credits +in ext4_xattr_set_handle() with 'is_create' being false, which means +we need more credits if ea_inode feature is enabled. So we don't +have enough credits and error out with ENOSPC. + +Fix it by simply calling ext4_xattr_set_handle() with XATTR_CREATE +flag in ext4_initxattrs(), so we end up with requiring less credits +than reserved. The semantic of XATTR_CREATE is "Perform a pure +create, which fails if the named attribute exists already." (from +setxattr(2)), which is fine in this case, because we only call +ext4_initxattrs() on newly created inode. + +Fixes: af65207c76ce ("ext4: fix __ext4_new_inode() journal credits calculation") +Cc: Tahsin Erdogan +Signed-off-by: Eryu Guan +Signed-off-by: Theodore Ts'o +--- + fs/ext4/xattr_security.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/fs/ext4/xattr_security.c b/fs/ext4/xattr_security.c +index 629001b28632..197a9d8a15ef 100644 +--- a/fs/ext4/xattr_security.c ++++ b/fs/ext4/xattr_security.c +@@ -43,7 +43,7 @@ ext4_initxattrs(struct inode *inode, const struct xattr *xattr_array, + err = ext4_xattr_set_handle(handle, inode, + EXT4_XATTR_INDEX_SECURITY, + xattr->name, xattr->value, +- xattr->value_len, 0); ++ xattr->value_len, XATTR_CREATE); + if (err < 0) + break; + } +-- +2.14.3 + + -- 2.11.4.GIT