add patch improve-code-readability-in-ext4_iget
[ext4-patch-queue.git] / check-for-valid-e_name_len-in-xattr-entries
blobd7c95aaf1ac93b560fbd56fbca7bc17c25330acb
1 ext4: check for NUL characters in extended attribute's name
3 Extended attribute names are defined to be NUL-terminated, so the name
4 must not contain a NUL character.  This is important because there are
5 places when remove extended attribute, the code uses strlen to
6 determine the length of the entry.  That should probably be fixed at
7 some point, but code is currently really messy, so the simplest fix
8 for now is to simply validate that the extended attributes are sane.
10 https://bugzilla.kernel.org/show_bug.cgi?id=200401
12 Reported-by: Wen Xu <wen.xu@gatech.edu>
13 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
14 Cc: stable@vger.kernel.org
15 ---
16  fs/ext4/xattr.c | 2 ++
17  1 file changed, 2 insertions(+)
19 diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c
20 index 723df14f4084..f36fc5d5b257 100644
21 --- a/fs/ext4/xattr.c
22 +++ b/fs/ext4/xattr.c
23 @@ -190,6 +190,8 @@ ext4_xattr_check_entries(struct ext4_xattr_entry *entry, void *end,
24                 struct ext4_xattr_entry *next = EXT4_XATTR_NEXT(e);
25                 if ((void *)next >= end)
26                         return -EFSCORRUPTED;
27 +               if (strnlen(e->e_name, e->e_name_len) != e->e_name_len)
28 +                       return -EFSCORRUPTED;
29                 e = next;
30         }