add patch forbid-overflowing-inode-code-when-resizing
[ext4-patch-queue.git] / handle-non-zero-e_value_offs-for-zero-length-xattrs
blob0cd8ea7cba10c7c9e088cace14d298007c20c1d9
1 ext4: correctly handle a zero-length xattr with a non-zero e_value_offs
3 Ext4 will always create ext4 extended attributes which do not have a
4 value (where e_value_size is zero) with e_value_offs set to zero.  In
5 most places e_value_offs will not be used in a substantive way if
6 e_value_size is zero.
8 There was one exception to this, which is in ext4_xattr_set_entry(),
9 where if there is a maliciously crafted file system where there is an
10 extended attribute with e_value_offs is non-zero and e_value_size is
11 0, the attempt to remove this xattr will result in a negative value
12 getting passed to memmove, leading to the following sadness:
14 [   41.225365] EXT4-fs (loop0): mounted filesystem with ordered data mode. Opts: (null)
15 [   44.538641] BUG: unable to handle kernel paging request at ffff9ec9a3000000
16 [   44.538733] IP: __memmove+0x81/0x1a0
17 [   44.538755] PGD 1249bd067 P4D 1249bd067 PUD 1249c1067 PMD 80000001230000e1
18 [   44.538793] Oops: 0003 [#1] SMP PTI
19 [   44.539074] CPU: 0 PID: 1470 Comm: poc Not tainted 4.16.0-rc1+ #1
20     ...
21 [   44.539475] Call Trace:
22 [   44.539832]  ext4_xattr_set_entry+0x9e7/0xf80
23     ...
24 [   44.539972]  ext4_xattr_block_set+0x212/0xea0
25     ...
26 [   44.540041]  ext4_xattr_set_handle+0x514/0x610
27 [   44.540065]  ext4_xattr_set+0x7f/0x120
28 [   44.540090]  __vfs_removexattr+0x4d/0x60
29 [   44.540112]  vfs_removexattr+0x75/0xe0
30 [   44.540132]  removexattr+0x4d/0x80
31     ...
32 [   44.540279]  path_removexattr+0x91/0xb0
33 [   44.540300]  SyS_removexattr+0xf/0x20
34 [   44.540322]  do_syscall_64+0x71/0x120
35 [   44.540344]  entry_SYSCALL_64_after_hwframe+0x21/0x86
37 https://bugzilla.kernel.org/show_bug.cgi?id=199347
39 This addresses CVE-2018-10840.
41 Reported-by: "Xu, Wen" <wen.xu@gatech.edu>
42 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
43 Reviewed-by: Andreas Dilger <adilger@dilger.ca>
44 Cc: stable@kernel.org
45 Fixes: dec214d00e0d7 ("ext4: xattr inode deduplication")
46 ---
47  fs/ext4/xattr.c | 2 +-
48  1 file changed, 1 insertion(+), 1 deletion(-)
50 diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c
51 index 499cb4b1fbd2..fc4ced59c565 100644
52 --- a/fs/ext4/xattr.c
53 +++ b/fs/ext4/xattr.c
54 @@ -1688,7 +1688,7 @@ static int ext4_xattr_set_entry(struct ext4_xattr_info *i,
56         /* No failures allowed past this point. */
58 -       if (!s->not_found && here->e_value_offs) {
59 +       if (!s->not_found && here->e_value_size && here->e_value_offs) {
60                 /* Remove the old value. */
61                 void *first_val = s->base + min_offs;
62                 size_t offs = le16_to_cpu(here->e_value_offs);