From patchwork Sat Mar 3 00:59:14 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Biggers X-Patchwork-Id: 880965 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-ext4-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="kAHGn1ms"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3ztSW821GYz9s9F for ; Sat, 3 Mar 2018 11:59:48 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S964832AbeCCA7r (ORCPT ); Fri, 2 Mar 2018 19:59:47 -0500 Received: from mail-it0-f65.google.com ([209.85.214.65]:54249 "EHLO mail-it0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S964827AbeCCA7p (ORCPT ); Fri, 2 Mar 2018 19:59:45 -0500 Received: by mail-it0-f65.google.com with SMTP id w63so3628694ita.3 for ; Fri, 02 Mar 2018 16:59:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=LKLsYavo830LpQAPaWLVA0t0i4kRO+mc2R9Dbg3xzSQ=; b=kAHGn1msTIFWjBrmon7+67ub7CPvTUPZ9u0UMkU+1T7cufSYXhA24NFYGh7xmy8l8S QUlhkg7rWMNwL/0A0T6GUZtenCiYYNjXFfHjbcSXrlxMcWsHlxzeD6LIhxgXuKsc+B6T J1Ik27pqfIdFMqppkdUEYGfRYAtPrRidwPLjmWlRKx1oSbRGvctFHa2Oae2kcZfsatOD 6Qbg4xac8UprivmI2PzdhhK4MxMF5Mpzl9bRpWeZun7aBjs0d7UkqRBIJi39L176uZOv mf+GUWQ8ZoZ/MWjahpat8JqrYDSaTkWz4lhvsbFu52kBpxcijYlyK6uxoO2Hy19+7Jw3 DGgQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=LKLsYavo830LpQAPaWLVA0t0i4kRO+mc2R9Dbg3xzSQ=; b=X1/z7gt6eF2FfBnO37eZyJ+5XLOfIS1IH5CajTLV8o78uu+m4J0tz2algW7gPguN9A JhtcHlaKAbcJ54P0VK2/cEN5zYhIXYZK/wAora4Mw4uuIGXCowx/iTGcHQEZKXQnPm+H 2fyYSZk0Wsj3OhJ450+RJL6xTlFBjV35ojpQs8QtMvpoTGdcPToKXUqdvLzUzBfXIeTq H75V93/wtwNFlqKcPkCPts9GSlU4SLoMsZ7mWVRi8B1M7GIHwBEY+eTVytl9jVFlZJmL P3+WXVcnQpTvGzWYKzDCJUEz2Mrea27XT/F3nudzurPl0fbZ8z/ZyoTjnYlx5MjRsYCJ iAvQ== X-Gm-Message-State: AElRT7FyHZYcN0S1DEJpLlO6oarDedGoOyLmkZ28wX4Wwne+flxFYWdy JtanF/FSpJGyIEZW1UWIFsSRIz5G X-Google-Smtp-Source: AG47ELsSwNYlaMJHybnMs8j9aeRkLgx/WyOSmNzMOgaeYkuWXREZpCGVSvfpK/5hQ4OMw0skEn07qw== X-Received: by 10.36.66.209 with SMTP id i200mr3792561itb.61.1520038784704; Fri, 02 Mar 2018 16:59:44 -0800 (PST) Received: from ebiggers-linuxstation.kir.corp.google.com ([2620:15c:17:3:dc28:5c82:b905:e8a8]) by smtp.gmail.com with ESMTPSA id p135sm1382972itg.44.2018.03.02.16.59.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 02 Mar 2018 16:59:44 -0800 (PST) From: Eric Biggers To: linux-ext4@vger.kernel.org Cc: Eric Biggers Subject: [PATCH 01/10] libext2fs: forbid creating symlinks using entire block Date: Fri, 2 Mar 2018 16:59:14 -0800 Message-Id: <20180303005923.152761-2-ebiggers3@gmail.com> X-Mailer: git-send-email 2.16.2.395.g2e18187dfd-goog In-Reply-To: <20180303005923.152761-1-ebiggers3@gmail.com> References: <20180303005923.152761-1-ebiggers3@gmail.com> Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org From: Eric Biggers ext2fs_symlink() didn't count the NUL terminator when limiting the symlink target length to fs->blocksize, so it could create symlinks using the entire block. Such symlinks are problematic because if block_size == PAGE_SIZE (as is usually the case), then when following such a symlink the kernel will truncate the last byte because it needs to ensure the symlink page is NUL-terminated (see page_get_link()). Perhaps for that reason, e2fsck considers such symlinks to be invalid (although only if they use the traditional block list rather than an extent tree, which seems to be another bug). Fix this by counting the NUL terminator, thereby decreasing the maximum accepted symlink target length by 1. Note that this matches the kernel's behavior in ext4_symlink(). This breaks the test 'f_create_symlinks' which was using debugfs to create a 1024-byte symlink (not counting the NUL terminator) on a 1024-byte block filesystem. Fix it by removing the leading '/' from the test's symlink targets so that their lengths are decreased by 1. Fixes: f01c1a6bce5e ("libext2fs: add the ext2fs_symlink() function") Signed-off-by: Eric Biggers --- lib/ext2fs/symlink.c | 15 ++++++++------- tests/f_create_symlinks/expect | 26 +++++++++++++------------- tests/f_create_symlinks/script | 4 ++-- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/lib/ext2fs/symlink.c b/lib/ext2fs/symlink.c index 607396de..13bca6e9 100644 --- a/lib/ext2fs/symlink.c +++ b/lib/ext2fs/symlink.c @@ -41,9 +41,12 @@ errcode_t ext2fs_symlink(ext2_filsys fs, ext2_ino_t parent, ext2_ino_t ino, EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS); - /* The Linux kernel doesn't allow for links longer than a block */ + /* + * The Linux kernel doesn't allow for links longer than a block + * (counting the NUL terminator) + */ target_len = strnlen(target, fs->blocksize + 1); - if (target_len > fs->blocksize) { + if (target_len >= fs->blocksize) { retval = EXT2_ET_INVALID_ARGUMENT; goto cleanup; } @@ -51,10 +54,10 @@ errcode_t ext2fs_symlink(ext2_filsys fs, ext2_ino_t parent, ext2_ino_t ino, /* * Allocate a data block for slow links */ - retval = ext2fs_get_mem(fs->blocksize+1, &block_buf); + retval = ext2fs_get_mem(fs->blocksize, &block_buf); if (retval) goto cleanup; - memset(block_buf, 0, fs->blocksize+1); + memset(block_buf, 0, fs->blocksize); strncpy(block_buf, target, fs->blocksize); memset(&inode, 0, sizeof(struct ext2_inode)); @@ -87,9 +90,7 @@ errcode_t ext2fs_symlink(ext2_filsys fs, ext2_ino_t parent, ext2_ino_t ino, ext2fs_inode_size_set(fs, &inode, target_len); /* The time fields are set by ext2fs_write_new_inode() */ - inlinelink = !fastlink && - ext2fs_has_feature_inline_data(fs->super) && - (target_len < fs->blocksize); + inlinelink = !fastlink && ext2fs_has_feature_inline_data(fs->super); if (fastlink) { /* Fast symlinks, target stored in inode */ strcpy((char *)&inode.i_block, target); diff --git a/tests/f_create_symlinks/expect b/tests/f_create_symlinks/expect index 44093855..1794e0a7 100644 --- a/tests/f_create_symlinks/expect +++ b/tests/f_create_symlinks/expect @@ -6,40 +6,40 @@ Pass 4: Checking reference counts Pass 5: Checking group summary information test_filesys: 11/128 files (0.0% non-contiguous), 441/1024 blocks Exit status is 0 -debugfs -R "symlink /l_30 /xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" test.img -debugfs -R "symlink /l_70 /xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" test.img -debugfs -R "symlink /l_500 /xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx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xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" test.img ext2fs_symlink: Invalid argument passed to ext2 library while creating symlink "l_1500" symlink: Invalid argument passed to ext2 library debugfs -R "stat /l_30" test.img Inode: 12 Type: symlink Mode: 0777 Flags: 0x0 Generation: 0 Version: 0x00000000:00000000 -User: 0 Group: 0 Project: 0 Size: 31 +User: 0 Group: 0 Project: 0 Size: 30 File ACL: 0 Links: 1 Blockcount: 0 Fragment: Address: 0 Number: 0 Size: 0 Size of extra inode fields: 32 -Fast link dest: "/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" +Fast link dest: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" debugfs -R "stat /l_70" test.img Inode: 13 Type: symlink Mode: 0777 Flags: 0x10000000 Generation: 0 Version: 0x00000000:00000000 -User: 0 Group: 0 Project: 0 Size: 71 +User: 0 Group: 0 Project: 0 Size: 70 File ACL: 0 Links: 1 Blockcount: 0 Fragment: Address: 0 Number: 0 Size: 0 Size of extra inode fields: 32 Extended attributes: - system.data (11) -Fast link dest: "/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" + system.data (10) +Fast link dest: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" debugfs -R "stat /l_500" test.img Inode: 14 Type: symlink Mode: 0777 Flags: 0x80000 Generation: 0 Version: 0x00000000:00000000 -User: 0 Group: 0 Project: 0 Size: 501 +User: 0 Group: 0 Project: 0 Size: 500 File ACL: 0 Links: 1 Blockcount: 2 Fragment: Address: 0 Number: 0 Size: 0 @@ -49,7 +49,7 @@ EXTENTS: debugfs -R "stat /l_1023" test.img Inode: 15 Type: symlink Mode: 0777 Flags: 0x80000 Generation: 0 Version: 0x00000000:00000000 -User: 0 Group: 0 Project: 0 Size: 1024 +User: 0 Group: 0 Project: 0 Size: 1023 File ACL: 0 Links: 1 Blockcount: 2 Fragment: Address: 0 Number: 0 Size: 0 diff --git a/tests/f_create_symlinks/script b/tests/f_create_symlinks/script index 779d92ed..73f95a6e 100644 --- a/tests/f_create_symlinks/script +++ b/tests/f_create_symlinks/script @@ -24,8 +24,8 @@ sed -f $cmd_dir/filter.sed -e "s;$TMPFILE;test.img;" $OUT.new >> $OUT rm -f $OUT.new for i in 30 70 500 1023 1024 1500; do - echo "debugfs -R \"symlink /l_$i /$(perl -e "print 'x' x $i;")\" test.img" >> $OUT - $DEBUGFS -w -R "symlink /l_$i /$(perl -e "print 'x' x $i;")" $TMPFILE \ + echo "debugfs -R \"symlink /l_$i $(perl -e "print 'x' x $i;")\" test.img" >> $OUT + $DEBUGFS -w -R "symlink /l_$i $(perl -e "print 'x' x $i;")" $TMPFILE \ 2>&1 | sed -f $cmd_dir/filter.sed >> $OUT done From patchwork Sat Mar 3 00:59:15 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Biggers X-Patchwork-Id: 880967 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-ext4-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="tP8oj+AJ"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3ztSWB0gg5z9s9D for ; Sat, 3 Mar 2018 11:59:50 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S964835AbeCCA7s (ORCPT ); Fri, 2 Mar 2018 19:59:48 -0500 Received: from mail-it0-f68.google.com ([209.85.214.68]:35104 "EHLO mail-it0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S964828AbeCCA7r (ORCPT ); Fri, 2 Mar 2018 19:59:47 -0500 Received: by mail-it0-f68.google.com with SMTP id v194so3952123itb.0 for ; Fri, 02 Mar 2018 16:59:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=MA6KRCUYd0xJnp9ER4VSlIiq/KdeFtsVt2Mwl+TltwA=; b=tP8oj+AJGpB2ruWobivUsOCLAIuqgiU9BJngA9/TKaldclfIA+4xaJ77K8RWq0HR9v OUrw9L7Oc+mPScRVL67Fxa6CHvFdq2qDLTkuncTBKxBZKlNSNnj9u0ZdXJIWFm/CFVDe FqBvM3Jrgy4Gwv0E51gNalIN/K2yU2QaJT9iEZ1e8ZWduz/G3egGic7N0G6ckNuN3zL+ qfFBTzEKUEjXRPFxycePTiKv3FmtpQZKguCjM3fqjJWQfqbugR5iBEotFppOVUmJfXMj J7Tgn3GQ3GIYFLNC59mRMaLy8OoEyvcW0WmlI9w/tgS/JlETFWelmBn5+JuhJB8jg1wK 7jQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=MA6KRCUYd0xJnp9ER4VSlIiq/KdeFtsVt2Mwl+TltwA=; b=adYharv1ZAdt0ivNIZtom23iPwAS+c4OBv+cmxP127bybUIafOLYldmfDtscRhycPF gO7kU7UnCGKw7WVfgi4cjmyI0Q7IvA5EKD2MA26XhICx/u+2WB6RbSKvh0w+1stO7rAv Ix8P9+OfKr+lg2rw9oeRhksgponrQmafMQlrqsQLmkKGX3iE9vZiPSSP7QitR58mw0kP 2LdE+6Eiko/D/c/5owcI/FK32ZK2fYYIf49nFStK6XF3kA/p1X77tnfXVYQNKPAIi063 RWmeKEVQR+bzUSkD90im+L7sCm67ApGOt3qrHejRHPbHThLKu82LuYJHvcHbQ626Rcz3 ynKQ== X-Gm-Message-State: AElRT7FCRDCGxKkx2F7UjyWy3WrEUUHBGq9rDa00B73kzCFrXVmmPbYb rHTeGG7I08BRJmMHP8O+6gANz6UZ X-Google-Smtp-Source: AG47ELs1UU14LY19ZIkjydpbufbriA66lT0xerpp25Hd5KW/6BdTAKj14X24W4jd27o8DuLo6pmCBg== X-Received: by 10.36.83.142 with SMTP id n136mr5157214itb.0.1520038786286; Fri, 02 Mar 2018 16:59:46 -0800 (PST) Received: from ebiggers-linuxstation.kir.corp.google.com ([2620:15c:17:3:dc28:5c82:b905:e8a8]) by smtp.gmail.com with ESMTPSA id p135sm1382972itg.44.2018.03.02.16.59.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 02 Mar 2018 16:59:45 -0800 (PST) From: Eric Biggers To: linux-ext4@vger.kernel.org Cc: Eric Biggers Subject: [PATCH 02/10] libext2fs: make sure the system.data xattr gets created Date: Fri, 2 Mar 2018 16:59:15 -0800 Message-Id: <20180303005923.152761-3-ebiggers3@gmail.com> X-Mailer: git-send-email 2.16.2.395.g2e18187dfd-goog In-Reply-To: <20180303005923.152761-1-ebiggers3@gmail.com> References: <20180303005923.152761-1-ebiggers3@gmail.com> Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org From: Eric Biggers Both the kernel and e2fsck expect that if an inode has inline data, then it contains a "system.data" xattr -- even if i_size <= 60 so the data fits entirely in i_block. But if a symlink of exactly 60 bytes (not counting a NUL terminator) was created using ext2fs_symlink() and the inline data feature was enabled, then the symlink inode ended up with inline data but without a system.data xattr. This is possible because "fast" symlinks store a NUL terminator but inline data symlinks do not. So 60 bytes is too long for a real fast symlink, but still short enough to fit the entire target in i_block as a "slow" symlink using inline data. Some places use ext2fs_inline_data_init() to ensure the system.data xattr is created, but the symlink path does not. Fix this by making ext2fs_inline_data_set() set system.data to an empty string when i_size <= 60. Fixes: 54e880b870f7 ("libext2fs: handle inline data in read/write function") Signed-off-by: Eric Biggers --- lib/ext2fs/inline_data.c | 50 +++++++++++++++++----------------- tests/f_create_symlinks/expect | 20 +++++++++++--- tests/f_create_symlinks/script | 4 +-- 3 files changed, 43 insertions(+), 31 deletions(-) diff --git a/lib/ext2fs/inline_data.c b/lib/ext2fs/inline_data.c index 7215c517..0cf80b9a 100644 --- a/lib/ext2fs/inline_data.c +++ b/lib/ext2fs/inline_data.c @@ -535,7 +535,10 @@ errcode_t ext2fs_inline_data_set(ext2_filsys fs, ext2_ino_t ino, void *buf, size_t size) { struct ext2_inode inode_buf; - struct ext2_inline_data data; + struct ext2_inline_data data = { + .fs = fs, + .ino = ino, + }; errcode_t retval; size_t free_ea_size, existing_size, free_inode_size; @@ -548,37 +551,34 @@ errcode_t ext2fs_inline_data_set(ext2_filsys fs, ext2_ino_t ino, if (size <= EXT4_MIN_INLINE_DATA_SIZE) { memcpy((void *)inode->i_block, buf, size); - return ext2fs_write_inode(fs, ino, inode); - } - - retval = ext2fs_xattr_inode_max_size(fs, ino, &free_ea_size); - if (retval) - return retval; + } else { + retval = ext2fs_xattr_inode_max_size(fs, ino, &free_ea_size); + if (retval) + return retval; - retval = ext2fs_inline_data_size(fs, ino, &existing_size); - if (retval) - return retval; + retval = ext2fs_inline_data_size(fs, ino, &existing_size); + if (retval) + return retval; - if (existing_size < EXT4_MIN_INLINE_DATA_SIZE) - free_inode_size = EXT4_MIN_INLINE_DATA_SIZE - existing_size; - else - free_inode_size = 0; + if (existing_size < EXT4_MIN_INLINE_DATA_SIZE) { + free_inode_size = EXT4_MIN_INLINE_DATA_SIZE - + existing_size; + } else { + free_inode_size = 0; + } - if (size != existing_size && - size > existing_size + free_ea_size + free_inode_size) - return EXT2_ET_INLINE_DATA_NO_SPACE; + if (size != existing_size && + size > existing_size + free_ea_size + free_inode_size) + return EXT2_ET_INLINE_DATA_NO_SPACE; - memcpy((void *)inode->i_block, buf, EXT4_MIN_INLINE_DATA_SIZE); + memcpy((void *)inode->i_block, buf, EXT4_MIN_INLINE_DATA_SIZE); + if (size > EXT4_MIN_INLINE_DATA_SIZE) + data.ea_size = size - EXT4_MIN_INLINE_DATA_SIZE; + data.ea_data = (char *) buf + EXT4_MIN_INLINE_DATA_SIZE; + } retval = ext2fs_write_inode(fs, ino, inode); if (retval) return retval; - data.fs = fs; - data.ino = ino; - if (size > EXT4_MIN_INLINE_DATA_SIZE) - data.ea_size = size - EXT4_MIN_INLINE_DATA_SIZE; - else - data.ea_size = 0; - data.ea_data = (char *) buf + EXT4_MIN_INLINE_DATA_SIZE; return ext2fs_inline_data_ea_set(&data); } diff --git a/tests/f_create_symlinks/expect b/tests/f_create_symlinks/expect index 1794e0a7..3033f8aa 100644 --- a/tests/f_create_symlinks/expect +++ b/tests/f_create_symlinks/expect @@ -7,6 +7,7 @@ Pass 5: Checking group summary information test_filesys: 11/128 files (0.0% non-contiguous), 441/1024 blocks Exit status is 0 debugfs -R "symlink /l_30 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" test.img +debugfs -R "symlink /l_60 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" test.img debugfs -R "symlink /l_70 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" test.img debugfs -R "symlink /l_500 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx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xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" test.img @@ -25,9 +26,20 @@ Links: 1 Blockcount: 0 Fragment: Address: 0 Number: 0 Size: 0 Size of extra inode fields: 32 Fast link dest: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" -debugfs -R "stat /l_70" test.img +debugfs -R "stat /l_60" test.img Inode: 13 Type: symlink Mode: 0777 Flags: 0x10000000 Generation: 0 Version: 0x00000000:00000000 +User: 0 Group: 0 Project: 0 Size: 60 +File ACL: 0 +Links: 1 Blockcount: 0 +Fragment: Address: 0 Number: 0 Size: 0 +Size of extra inode fields: 32 +Extended attributes: + system.data (0) +Fast link dest: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" +debugfs -R "stat /l_70" test.img +Inode: 14 Type: symlink Mode: 0777 Flags: 0x10000000 +Generation: 0 Version: 0x00000000:00000000 User: 0 Group: 0 Project: 0 Size: 70 File ACL: 0 Links: 1 Blockcount: 0 @@ -37,7 +49,7 @@ Extended attributes: system.data (10) Fast link dest: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" debugfs -R "stat /l_500" test.img -Inode: 14 Type: symlink Mode: 0777 Flags: 0x80000 +Inode: 15 Type: symlink Mode: 0777 Flags: 0x80000 Generation: 0 Version: 0x00000000:00000000 User: 0 Group: 0 Project: 0 Size: 500 File ACL: 0 @@ -47,7 +59,7 @@ Size of extra inode fields: 32 EXTENTS: (0):153 debugfs -R "stat /l_1023" test.img -Inode: 15 Type: symlink Mode: 0777 Flags: 0x80000 +Inode: 16 Type: symlink Mode: 0777 Flags: 0x80000 Generation: 0 Version: 0x00000000:00000000 User: 0 Group: 0 Project: 0 Size: 1023 File ACL: 0 @@ -65,5 +77,5 @@ Pass 2: Checking directory structure Pass 3: Checking directory connectivity Pass 4: Checking reference counts Pass 5: Checking group summary information -test_filesys: 15/128 files (0.0% non-contiguous), 443/1024 blocks +test_filesys: 16/128 files (0.0% non-contiguous), 443/1024 blocks Exit status is 0 diff --git a/tests/f_create_symlinks/script b/tests/f_create_symlinks/script index 73f95a6e..1a97216a 100644 --- a/tests/f_create_symlinks/script +++ b/tests/f_create_symlinks/script @@ -23,13 +23,13 @@ echo Exit status is $status >> $OUT.new sed -f $cmd_dir/filter.sed -e "s;$TMPFILE;test.img;" $OUT.new >> $OUT rm -f $OUT.new -for i in 30 70 500 1023 1024 1500; do +for i in 30 60 70 500 1023 1024 1500; do echo "debugfs -R \"symlink /l_$i $(perl -e "print 'x' x $i;")\" test.img" >> $OUT $DEBUGFS -w -R "symlink /l_$i $(perl -e "print 'x' x $i;")" $TMPFILE \ 2>&1 | sed -f $cmd_dir/filter.sed >> $OUT done -for i in 30 70 500 1023 1024 1500; do +for i in 30 60 70 500 1023 1024 1500; do echo "debugfs -R \"stat /l_$i\" test.img" >> $OUT $DEBUGFS -R "stat /l_$i" $TMPFILE 2>&1 | \ sed -f $cmd_dir/filter.sed | grep -v "time: " >> $OUT From patchwork Sat Mar 3 00:59:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Biggers X-Patchwork-Id: 880968 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-ext4-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="NRD8jU2F"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3ztSWC2yXGz9s92 for ; Sat, 3 Mar 2018 11:59:51 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S964836AbeCCA7u (ORCPT ); Fri, 2 Mar 2018 19:59:50 -0500 Received: from mail-io0-f196.google.com ([209.85.223.196]:44354 "EHLO mail-io0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S964833AbeCCA7s (ORCPT ); Fri, 2 Mar 2018 19:59:48 -0500 Received: by mail-io0-f196.google.com with SMTP id h23so12434854iob.11 for ; Fri, 02 Mar 2018 16:59:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=qNwJ+e1qZ3CQ/5VDtohMlBSLG4W7peUdiIiitioh4Wk=; b=NRD8jU2Fl6NraIsPY1W3qsfyeiRZZMN7f4k/ebmyYfWr1wF8sibRpc4AB2Jim7hwha 3qr3I5OE4nVroCktWRhoQIgt58skK1d2D5FnETzWzMkBsofdOw0prkWCo5Sneq+B3xTv kkhjr4MFdjqIaOzrpMf5PMW2Uubm8e6qGAi2X7R4iycXqK6Y75UzU5UdOHXrbq8Mw7ob RkNdcR4L1+DwXPxHZLws8S3jhXqU/ifrn7OUEaQbX2bayfirtNxQtqi1OvLYs9RWMvia 2Ij3iTQQvPVWqcRhFRMOl+OW431Plvg2K7dhwZZXTz/B98nkTeYKu+fOSxTOOaJwoa4Q 9mHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=qNwJ+e1qZ3CQ/5VDtohMlBSLG4W7peUdiIiitioh4Wk=; b=rmKqNyTzgRI7mKCK4R6OlBjX9bJ/+/zfWajepK/C74/iSmbrQ5RtMK828lG3zVjihv ilsOLtnWcBMSKjpC4sVXIXgr2X/rzKD6F73XlsyRyX43W/BuupALIKM+F+ZpriCRbI4X +8OFg1wdsIwgKmZ+CZIKa6h0bssdmhm2Zd0NwRvqZ+F9zpTo1w3pVqCq8Frs/vaTfd+k HbRaA2+hvo1/jEKDB7ou8d6epxROozDu/ScrZX6ciQbqWE0qQIU+6BJQlpUedF02sre7 GaO8+4UH0wtjMyCMdgr69NnBb1riIBvNWT3aIkLfp4P3gZMe3ARn0M+HdioKpt9sIt73 KNow== X-Gm-Message-State: APf1xPBezze7U0eRuuzyuAF/k2uANVierq3NNNAehe3pLEq0PSwuOZQk j7PKqOdICCcICFaHEDMA3dblQUK4 X-Google-Smtp-Source: AG47ELsKKn37x22NCvRjWj6F8iSUptDp06+7D+pCb5UVYZjFX7a4tmLe3M86e4ViWbZH04c+J338gA== X-Received: by 10.107.24.194 with SMTP id 185mr9245437ioy.157.1520038787690; Fri, 02 Mar 2018 16:59:47 -0800 (PST) Received: from ebiggers-linuxstation.kir.corp.google.com ([2620:15c:17:3:dc28:5c82:b905:e8a8]) by smtp.gmail.com with ESMTPSA id p135sm1382972itg.44.2018.03.02.16.59.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 02 Mar 2018 16:59:47 -0800 (PST) From: Eric Biggers To: linux-ext4@vger.kernel.org Cc: Eric Biggers Subject: [PATCH 03/10] e2fsck: fix reading fscrypt_symlink_data.len Date: Fri, 2 Mar 2018 16:59:16 -0800 Message-Id: <20180303005923.152761-4-ebiggers3@gmail.com> X-Mailer: git-send-email 2.16.2.395.g2e18187dfd-goog In-Reply-To: <20180303005923.152761-1-ebiggers3@gmail.com> References: <20180303005923.152761-1-ebiggers3@gmail.com> Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org From: Eric Biggers The ciphertext length field stored at the beginning of encrypted symlink targets is 16-bit. But e2fsck_pass1_check_symlink() is reading it as 32-bit. This was apparently left over from an earlier on-disk format that was not merged. Fix it. This bug caused a small proportion of encrypted symlinks with 4092-byte targets to be considered invalid by e2fsck, but otherwise had no effect. Fixes: 62ad24802c6e ("e2fsck: handle encrypted directories which are indexed using htree") Signed-off-by: Eric Biggers --- e2fsck/pass1.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/e2fsck/pass1.c b/e2fsck/pass1.c index 5015d938..b101df0a 100644 --- a/e2fsck/pass1.c +++ b/e2fsck/pass1.c @@ -249,7 +249,7 @@ int e2fsck_pass1_check_symlink(ext2_filsys fs, ext2_ino_t ino, return 0; if (inode->i_flags & EXT4_ENCRYPT_FL) { - len = ext2fs_le32_to_cpu(*((__u32 *)buf)) + 4; + len = ext2fs_le16_to_cpu(*((__u16 *)buf)) + 2; } else { len = strnlen(buf, fs->blocksize); } From patchwork Sat Mar 3 00:59:17 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Biggers X-Patchwork-Id: 880969 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-ext4-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="Btar3Prs"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3ztSWF33Vwz9s92 for ; Sat, 3 Mar 2018 11:59:53 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S964838AbeCCA7w (ORCPT ); Fri, 2 Mar 2018 19:59:52 -0500 Received: from mail-io0-f193.google.com ([209.85.223.193]:42916 "EHLO mail-io0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S964828AbeCCA7u (ORCPT ); Fri, 2 Mar 2018 19:59:50 -0500 Received: by mail-io0-f193.google.com with SMTP id u84so12441358iod.9 for ; Fri, 02 Mar 2018 16:59:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=aMML14jsGfhG1zsp6n8NkABYDVF7nmhupkAcMu8GFzA=; b=Btar3PrshOBXTSE/DhA4PRiBt5LcccLhiQ/Kw+WnG3gInw534O4rlF3SDuA34rDB8N z2SKTUIQJD2drpjle+uFRy8YQuXmRyCSslCB3x5nF8CDhSKoBa8PsxJVMo1VLgQbq1in IGPWqz6a1oAeYtfplFBksrKy5QnAkX/4YTC9GNrzDgfzVHEYXYvTQA29qq479BA5X6ci XEleyTPdOqwrP/bUDheBmMJiEbIJzVBDUGZiNtQh6Fep/jlqThaYYfS20Q96GK1m+JVF Gv65PliE25Itux4L0rfxdW2WV1XZf1AQmhZ8QN9FDAOT47Dwwpl/55pRTNb3vamMJhgI WpTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=aMML14jsGfhG1zsp6n8NkABYDVF7nmhupkAcMu8GFzA=; b=Mq4fOSJCveCRV9IIVcNtCUa+iX58+P0VhEAtzOuSCTjVQmtJ75tXzShatLr4gBjJ1U GzEc+5FgQTuuNXFYh0opX50HzfMy4XK8GjL49B0rBBw7j8YXFNBfZbN7rGx95fcOVOKN ygrQy4harS134r52Gki0BOdRIQ6BoP8Tc7q7Q956cTvKC6H2O27WxJysU2irHtEGWTIi fhWRS35O206lPoyc7qvJt+t/r6Z7NhoLnAjGDQPERd6rfZluC84+uA/uyqXnAO1qRLbD llZBFppM8W1MBKopBbGwtyEq8PRCla7iunnN+LztuZ3NjNyYi8pFxzVEyBbloEULp7nv 2LKQ== X-Gm-Message-State: AElRT7EJDTKIsmtBJ5TEtK2+l5otZbmhYRwXoCw7UW4BRgP/jAAv/xnP FmTa0f6oS7VObt+zjw7JR52LhyxE X-Google-Smtp-Source: AG47ELsSsZ3mVkNbB+MNjbrMaewVtG8VvNxpeul7SwIKggYGlvG3dkdAPeOR/hBh1MIcesg54BnrFg== X-Received: by 10.107.150.1 with SMTP id y1mr9491480iod.100.1520038789246; Fri, 02 Mar 2018 16:59:49 -0800 (PST) Received: from ebiggers-linuxstation.kir.corp.google.com ([2620:15c:17:3:dc28:5c82:b905:e8a8]) by smtp.gmail.com with ESMTPSA id p135sm1382972itg.44.2018.03.02.16.59.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 02 Mar 2018 16:59:48 -0800 (PST) From: Eric Biggers To: linux-ext4@vger.kernel.org Cc: Eric Biggers Subject: [PATCH 04/10] e2fsck: validate that fscrypt_symlink_data.len is not too large Date: Fri, 2 Mar 2018 16:59:17 -0800 Message-Id: <20180303005923.152761-5-ebiggers3@gmail.com> X-Mailer: git-send-email 2.16.2.395.g2e18187dfd-goog In-Reply-To: <20180303005923.152761-1-ebiggers3@gmail.com> References: <20180303005923.152761-1-ebiggers3@gmail.com> Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org From: Eric Biggers Make e2fsck start validating that the ciphertext length stored in the header of an encrypted symlink target, plus the header itself, is no larger than a filesystem block. Previously e2fsck only verified that this size is not exactly equal to a filesystem block. This was sufficient for unencrypted symlinks, where the "actual length" is computed using strnlen(), but not for encrypted symlinks; the kernel also considers encrypted symlinks with too-large ciphertext length to be invalid. Signed-off-by: Eric Biggers --- e2fsck/pass1.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/e2fsck/pass1.c b/e2fsck/pass1.c index b101df0a..723acf09 100644 --- a/e2fsck/pass1.c +++ b/e2fsck/pass1.c @@ -253,7 +253,7 @@ int e2fsck_pass1_check_symlink(ext2_filsys fs, ext2_ino_t ino, } else { len = strnlen(buf, fs->blocksize); } - if (len == fs->blocksize) + if (len >= fs->blocksize) return 0; } if (len != inode->i_size) From patchwork Sat Mar 3 00:59:18 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Biggers X-Patchwork-Id: 880970 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-ext4-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="EYU40IkK"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3ztSWH4PkPz9s92 for ; Sat, 3 Mar 2018 11:59:55 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S964844AbeCCA7y (ORCPT ); Fri, 2 Mar 2018 19:59:54 -0500 Received: from mail-io0-f193.google.com ([209.85.223.193]:45837 "EHLO mail-io0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S964833AbeCCA7v (ORCPT ); Fri, 2 Mar 2018 19:59:51 -0500 Received: by mail-io0-f193.google.com with SMTP id m22so12419268iob.12 for ; Fri, 02 Mar 2018 16:59:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=nDVHRff/fJtgRK8Bk5eHOEU2OtlxWCQj0dyO7PGY1Ak=; b=EYU40IkK1L8FwYIbBjCPoUmIyL5t0+E26TB106VzWJyHOysAmGgLgccUE+urIDMBD5 UUYJkbWz7NitckxhamvTfIHTcSHJYB4ruAo1Yp/ZEdWoZxkUO2JxmOn4usoeEzGeujM1 pGSWkSiWW8mp7nDOZvgqd0aO1D9hRjwHjT88pQr+v/SYhAsaMMpwQLsWzX8+nGr94WFD Y6gdea0/1GFdOvG104qwyFsfn6UmuHka9oNXAThtO8cNaPj3Oy4LDNHYYGo6anAlUajL RagJCJNWeTdsWLMhJpRBPo40JsNxhBT3QVXnmFm7+cG2k3fAH5QxYdo9JwE/EncXnw9x nBiw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=nDVHRff/fJtgRK8Bk5eHOEU2OtlxWCQj0dyO7PGY1Ak=; b=dqyegGK/BW/VsEP7ICZYG2/2uF3FheMGLNG7TAWkx0Ek1d5ZEss74PfEmMRUZDZig/ XC4ZaIV/l4L5b9OlSy9f9AE4LDaWkArLCLG++ArpGEd3qzMJf5b5FKP+tkFUoqlOc7Pq toj8o0QFYRPUm/buUPNlKKnfDzKUckMMzJlNgCuknhuV07oR1MVz+N3FmN+h/eUd10Rf azCoJvC2w+FNc2KPp+OZ28gbcAauGshLR8C5V/VZ486zwhHKOlMU9f3h174KhRAbkk1K jyL2G6Wsgsiv5g1xcYZdxlcavxbTzjSsV6OqN5VXICwLuPi0J+8qD9N0zS6M4Atkslt6 t03w== X-Gm-Message-State: APf1xPDmjE6660aDeSs0UtXpbYPCSZz1NumFDIEvazGuK3M4SfRVi8Oe tJrYQJIXwxv/HF26H3BZHcH29LCe X-Google-Smtp-Source: AG47ELv61VfWkNdIF78PzO68zNndQA6Fbdqg09NS3su8X15tNiK2euf0QxHMb+3ezDI9ogX0DK8s1A== X-Received: by 10.107.212.7 with SMTP id l7mr8625608iog.70.1520038790852; Fri, 02 Mar 2018 16:59:50 -0800 (PST) Received: from ebiggers-linuxstation.kir.corp.google.com ([2620:15c:17:3:dc28:5c82:b905:e8a8]) by smtp.gmail.com with ESMTPSA id p135sm1382972itg.44.2018.03.02.16.59.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 02 Mar 2018 16:59:50 -0800 (PST) From: Eric Biggers To: linux-ext4@vger.kernel.org Cc: Eric Biggers Subject: [PATCH 05/10] e2fsck: validate fscrypt_symlink_data.len for fast symlinks too Date: Fri, 2 Mar 2018 16:59:18 -0800 Message-Id: <20180303005923.152761-6-ebiggers3@gmail.com> X-Mailer: git-send-email 2.16.2.395.g2e18187dfd-goog In-Reply-To: <20180303005923.152761-1-ebiggers3@gmail.com> References: <20180303005923.152761-1-ebiggers3@gmail.com> Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org From: Eric Biggers Both fast and slow encrypted symlinks are prefixed with the ciphertext length field (fscrypt_symlink_data.len). But e2fsck was only checking it for slow symlinks. Start checking it for fast symlinks too. This matches the kernel handling of encrypted symlinks. Signed-off-by: Eric Biggers --- e2fsck/pass1.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/e2fsck/pass1.c b/e2fsck/pass1.c index 723acf09..d9df28ed 100644 --- a/e2fsck/pass1.c +++ b/e2fsck/pass1.c @@ -183,6 +183,7 @@ int e2fsck_pass1_check_device_inode(ext2_filsys fs EXT2FS_ATTR((unused)), int e2fsck_pass1_check_symlink(ext2_filsys fs, ext2_ino_t ino, struct ext2_inode *inode, char *buf) { + unsigned int buflen; unsigned int len; int i; ext2_extent_handle_t handle; @@ -232,9 +233,8 @@ int e2fsck_pass1_check_symlink(ext2_filsys fs, ext2_ino_t ino, if (inode->i_size >= sizeof(inode->i_block)) return 0; - len = strnlen((char *)inode->i_block, sizeof(inode->i_block)); - if (len == sizeof(inode->i_block)) - return 0; + buf = (char *)inode->i_block; + buflen = sizeof(inode->i_block); } else { if ((inode->i_size >= fs->blocksize) || (inode->i_block[0] < fs->super->s_first_data_block) || @@ -248,14 +248,17 @@ int e2fsck_pass1_check_symlink(ext2_filsys fs, ext2_ino_t ino, if (io_channel_read_blk64(fs->io, inode->i_block[0], 1, buf)) return 0; - if (inode->i_flags & EXT4_ENCRYPT_FL) { - len = ext2fs_le16_to_cpu(*((__u16 *)buf)) + 2; - } else { - len = strnlen(buf, fs->blocksize); - } - if (len >= fs->blocksize) - return 0; + buflen = fs->blocksize; } + + if (inode->i_flags & EXT4_ENCRYPT_FL) + len = ext2fs_le16_to_cpu(*(__u16 *)buf) + 2; + else + len = strnlen(buf, buflen); + + if (len >= buflen) + return 0; + if (len != inode->i_size) if ((inode->i_flags & EXT4_ENCRYPT_FL) == 0) return 0; From patchwork Sat Mar 3 00:59:19 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Biggers X-Patchwork-Id: 880971 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-ext4-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="Fj3F+TUj"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3ztSWJ2c5sz9s9D for ; Sat, 3 Mar 2018 11:59:56 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S964839AbeCCA7z (ORCPT ); Fri, 2 Mar 2018 19:59:55 -0500 Received: from mail-io0-f193.google.com ([209.85.223.193]:42919 "EHLO mail-io0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S964828AbeCCA7x (ORCPT ); Fri, 2 Mar 2018 19:59:53 -0500 Received: by mail-io0-f193.google.com with SMTP id u84so12441439iod.9 for ; Fri, 02 Mar 2018 16:59:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Qx9hTUtOgJEew2ZhdjV0EhV8qmXwrAthkfhiiboyHWk=; b=Fj3F+TUjqYpwCjHiwpB3ES0KUljH1ZIhCtsiMStc4yJyeHN/OEW7S2oZ9mu3+DAdhf UnEwLksybp1qcDZYNEGt8CYg3J35IB7dD9zKnn2WJWga9aRNW2s2/WyI7Gc1RRZ0gpB2 zIjpOtebSH203vAN7zm9jE6c0+pem87ZzDkevgfFeQtEVnxizw22T3OnqUA4J74gaEcu 86rusjFz/RD+VonaAl5g4PpnjTpRmUKlFdLGyX9bA0KMfoniU4xMj4lbfthOlNjjIrzL jWacfNzwRFxecZ1oEcbXvO4F17dtJhMzDRATEpa4Ivv7EEY+mHwS0buRYadci2hTluPI +nfg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Qx9hTUtOgJEew2ZhdjV0EhV8qmXwrAthkfhiiboyHWk=; b=VOrfUgTwtFace3LlhVVsQKgxGhHJcPECDuiF18C2BZO/Ljw8L7LqnyVzzae6ZPXzEN Orks0eihaFYBguas+ELvBG43++1wm3AGRQsAUn/1JwOVffMW4VajNVky1W4Qmueozi+8 G4YRc0Uqr/JibYjcpbVYaWxOC69hdVsYJd6Bk01FTapI8CsaEKLJj0uRgsyiXEFZeCcr /7rpTu7JquURO1FtSw7Qc2yinlHqHGPO8+ZF4QOK9yI+gLl1w9mkP32O/2qXs+BL3/cE F/V6HxKkPrxh66P1BIfJ+Phl7Xle82ujswwIZGm9Hg1KX2jmgjQg3TQL9asNCmKGQ+jp vpVw== X-Gm-Message-State: AElRT7GSZljyO5TuW9qUT3t7eXJXdYdUIaxCBq9keFudp8qRPFMEF9vK x9Wpv8U0FOabzTIakAZc7Nly05T+ X-Google-Smtp-Source: AG47ELvzfcwvTMiacKlWLAUbA4KNwby9sugvHhduNtY/Pvhx/kyKaH23mX6ljAUrkYzKoekYz8I6gg== X-Received: by 10.107.51.78 with SMTP id z75mr2682548ioz.291.1520038792488; Fri, 02 Mar 2018 16:59:52 -0800 (PST) Received: from ebiggers-linuxstation.kir.corp.google.com ([2620:15c:17:3:dc28:5c82:b905:e8a8]) by smtp.gmail.com with ESMTPSA id p135sm1382972itg.44.2018.03.02.16.59.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 02 Mar 2018 16:59:52 -0800 (PST) From: Eric Biggers To: linux-ext4@vger.kernel.org Cc: Eric Biggers Subject: [PATCH 06/10] e2fsck: require i_size == fscrypt_symlink_data.len + 2 Date: Fri, 2 Mar 2018 16:59:19 -0800 Message-Id: <20180303005923.152761-7-ebiggers3@gmail.com> X-Mailer: git-send-email 2.16.2.395.g2e18187dfd-goog In-Reply-To: <20180303005923.152761-1-ebiggers3@gmail.com> References: <20180303005923.152761-1-ebiggers3@gmail.com> Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org From: Eric Biggers e2fsck validates that unencrypted symlinks have their strlen() equal to i_size. But it skips the equivalent check of i_size == fscrypt_symlink_data.len + 2 for encrypted symlinks. Actually, the encrypted symlink header is redundant with i_size and shouldn't exist. But it's there, and the kernel does in fact use the length in the header instead of i_size -- so e2fsck should validate the header. Thus, remove the exception for encrypted symlinks, so e2fsck will now require i_size == fscrypt_symlink_data.len + 2. I think the exception was only there originally because for encrypted fast symlinks we were calculating the length using strnlen() which was wrong. But that was fixed by the previous patch. Signed-off-by: Eric Biggers --- e2fsck/pass1.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/e2fsck/pass1.c b/e2fsck/pass1.c index d9df28ed..6a6c5969 100644 --- a/e2fsck/pass1.c +++ b/e2fsck/pass1.c @@ -260,8 +260,7 @@ int e2fsck_pass1_check_symlink(ext2_filsys fs, ext2_ino_t ino, return 0; if (len != inode->i_size) - if ((inode->i_flags & EXT4_ENCRYPT_FL) == 0) - return 0; + return 0; return 1; } From patchwork Sat Mar 3 00:59:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Biggers X-Patchwork-Id: 880973 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-ext4-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="KSAL9mI0"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3ztSWN2V3bz9s9D for ; Sat, 3 Mar 2018 12:00:00 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S964854AbeCCA76 (ORCPT ); Fri, 2 Mar 2018 19:59:58 -0500 Received: from mail-io0-f195.google.com ([209.85.223.195]:34255 "EHLO mail-io0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S964843AbeCCA7y (ORCPT ); Fri, 2 Mar 2018 19:59:54 -0500 Received: by mail-io0-f195.google.com with SMTP id e7so12468821ioj.1 for ; Fri, 02 Mar 2018 16:59:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=GV+WROqkp0epLJbzCBS9VawWJjVcwCplh/+irgq6FFE=; b=KSAL9mI0Aesykl8g4Wd0WvBL6ZDPQZ5A3px7kbCJinrd9yZN49S0vqdzlrnVXtOFCE +FdIQvBmTVCgqvZsuC68y3B7WqY9goT48IJf6BxT7eQKoI1LqUVg11e5hbxBa+4LA5Z2 rruT9nBxVjDl4Y7dRW8HGEzDczwmBe7EfHpYHv+qRyNd6+1QmtUCwV0zdmA5BudRmId6 +o2ly3qIY9y83FU/1N0eSElGuQshgfMJqZtXV7DuMS+7cuociC4jtR+CQx64RRCU15Xn KXwQRcKNfKTGb0bPyhXcnQsxhiKxfSUXS63C1qhbq0vTvaIhEQKm/qyhcL11foHcNYpX O1OQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=GV+WROqkp0epLJbzCBS9VawWJjVcwCplh/+irgq6FFE=; b=GQGgltIHsHppSa116IWq8E1axJyZinvSBmMkWzLYsBlJJI19qPHi6HNgjJfo//6jpP 59Oh152e5qLeB7w40yJXeulT4ltFIjGTk0vFUCgpmBp9eFFs2itQ8JPSbPw4JEcGZuTa w+GxV5fAWMnEfOUkLc0aiJZC13YkcFkmBGqhnhAq8xk9s3sAOZjfRocYSZaOjpM0z/f7 cDxP4oRuQOu5aU3oF7EcFroI2WFLpdYFVnOF0In35sDhd4ycdkrRdGWK5aNfqAAtmDti ZNZjRnS3ykYaUI1Mrd/MqeS0slNRVutgNE2KcG/Ng84LxesMoXxBKBZaiZ2+p6c6W3a9 F97w== X-Gm-Message-State: AElRT7E8O2RKu9ReIJxnBnyUFxNXBvtiFKMzBgwldqOeZLPAp+lCQ8Qe BNBjRx9z9LAzuoGLJsFtCbXnWa8Q X-Google-Smtp-Source: AG47ELvSZO0t5Fx4PjI4l5FtMGsyXGJYDRJh+ta+72PEXka4UwFq4qhfAAYGiDHiTZtts92hC8zKDQ== X-Received: by 10.107.163.78 with SMTP id m75mr6091629ioe.26.1520038794006; Fri, 02 Mar 2018 16:59:54 -0800 (PST) Received: from ebiggers-linuxstation.kir.corp.google.com ([2620:15c:17:3:dc28:5c82:b905:e8a8]) by smtp.gmail.com with ESMTPSA id p135sm1382972itg.44.2018.03.02.16.59.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 02 Mar 2018 16:59:53 -0800 (PST) From: Eric Biggers To: linux-ext4@vger.kernel.org Cc: Eric Biggers Subject: [PATCH 07/10] e2fsck: drop redundant checks of symlink i_size Date: Fri, 2 Mar 2018 16:59:20 -0800 Message-Id: <20180303005923.152761-8-ebiggers3@gmail.com> X-Mailer: git-send-email 2.16.2.395.g2e18187dfd-goog In-Reply-To: <20180303005923.152761-1-ebiggers3@gmail.com> References: <20180303005923.152761-1-ebiggers3@gmail.com> Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org From: Eric Biggers e2fsck_pass1_check_symlink() verifies that the symlink inode's i_size is less than the buffer length (60 for fast symlinks, fs->blocksize for slow symlinks). But it also verifies that len == i_size && len < buflen, which already implies i_size < buflen. Thus, remove the redundant checks of i_size. Signed-off-by: Eric Biggers --- e2fsck/pass1.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/e2fsck/pass1.c b/e2fsck/pass1.c index 6a6c5969..3a49e020 100644 --- a/e2fsck/pass1.c +++ b/e2fsck/pass1.c @@ -230,14 +230,10 @@ int e2fsck_pass1_check_symlink(ext2_filsys fs, ext2_ino_t ino, } if (ext2fs_is_fast_symlink(inode)) { - if (inode->i_size >= sizeof(inode->i_block)) - return 0; - buf = (char *)inode->i_block; buflen = sizeof(inode->i_block); } else { - if ((inode->i_size >= fs->blocksize) || - (inode->i_block[0] < fs->super->s_first_data_block) || + if ((inode->i_block[0] < fs->super->s_first_data_block) || (inode->i_block[0] >= ext2fs_blocks_count(fs->super))) return 0; From patchwork Sat Mar 3 00:59:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Biggers X-Patchwork-Id: 880972 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-ext4-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="ZnLPXoiB"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3ztSWL38Gyz9s9F for ; Sat, 3 Mar 2018 11:59:58 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S964850AbeCCA75 (ORCPT ); Fri, 2 Mar 2018 19:59:57 -0500 Received: from mail-io0-f195.google.com ([209.85.223.195]:46639 "EHLO mail-io0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S964828AbeCCA74 (ORCPT ); Fri, 2 Mar 2018 19:59:56 -0500 Received: by mail-io0-f195.google.com with SMTP id p78so12436570iod.13 for ; Fri, 02 Mar 2018 16:59:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=MT5R1e8gK0d10lA4G9f3iocGehoodrw+rhLgwd6YEj4=; b=ZnLPXoiBXwSQgqwAJ5RiXj5uL2As+ocrdahdPRwWTcgwp6yZxIP6Pmbli+uRJ+UTqL v9XEV3O9efOFAMCgy460tKlQ1n/lReJU7aewDuOOqV8kAVpHYxCnpQeuDD4DSqvV4JWZ LZX8ZAGxEd+UlA2SYI/a7chXFhB3q5jZxaGhvf4Yd9khpzbP64qth/9E42pC89I20Zmb aBG2xZNwjqIPZ6ht/gBbF+FMuAXoPkyiWFS8yjzgM6t8rfT09gs7pWgWAxIdld+XpZH6 UXDwkqycAk9WpzXhYg4H56n0EiqQErX5tsmZ0gAZwutuDLmcgVHpQW1rZlTJz5R9goMT hyMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=MT5R1e8gK0d10lA4G9f3iocGehoodrw+rhLgwd6YEj4=; b=Yx7FP/dxogFMq2myJ09gP1wYM4SYOVHcrnNyl89keloWzIUu2DqZ6s7z+zifL2THKO 4OwozeKKQPY5oHb2yuh4wfaOqcyXmsZrmzkep49NmRjpEaLKZthv1a+24aV8KwKo6p16 KF0fdA3IEzxZIgNJvaU8Pq3VWtLN5qCIvDa0KlxFpjc1k0+3YR2rzXBjr6zxGgALVa7M 19WB4GUphZSoJllc7jT1+eI2ihCXdh1fwMJZQ/KwtYDCXS0h18JueiILCTNq6wkxMxNG papmvkgCvlwZCjYdLOy6jKN6qrsvkfSAj/Bpg7CcoVpM1XK98oSwzfb23aT21vnAQWcM n7mg== X-Gm-Message-State: APf1xPDGKVfbZWSzvEQZXCAf9W4VII7WE4nMeYeEE8pYj1e9Uh9CDIV8 IsnskLau+PC4jQTtyRwAXYsrYdoQ X-Google-Smtp-Source: AG47ELsjJZaslGhTu8pEf1peYYxr9WsF+vZPdcnbZFWosyE8MTK1zIFUMRe11/xVUR7LkOeuReuaJg== X-Received: by 10.107.132.18 with SMTP id g18mr9016044iod.46.1520038795369; Fri, 02 Mar 2018 16:59:55 -0800 (PST) Received: from ebiggers-linuxstation.kir.corp.google.com ([2620:15c:17:3:dc28:5c82:b905:e8a8]) by smtp.gmail.com with ESMTPSA id p135sm1382972itg.44.2018.03.02.16.59.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 02 Mar 2018 16:59:54 -0800 (PST) From: Eric Biggers To: linux-ext4@vger.kernel.org Cc: Eric Biggers Subject: [PATCH 08/10] e2fsck: validate the targets of extent-based symlinks Date: Fri, 2 Mar 2018 16:59:21 -0800 Message-Id: <20180303005923.152761-9-ebiggers3@gmail.com> X-Mailer: git-send-email 2.16.2.395.g2e18187dfd-goog In-Reply-To: <20180303005923.152761-1-ebiggers3@gmail.com> References: <20180303005923.152761-1-ebiggers3@gmail.com> Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org From: Eric Biggers e2fsck is validating the target (requiring that it be NUL-terminated at i_size, or something a bit different for encrypted symlinks) of slow symlinks that use a traditional block list but not ones that use an extent tree. As far as I can tell this is simply a bug: there's no reason for the representation of the block list to affect how the symlink target is validated. And either way the kernel won't create symlinks with embedded NULs and will always add a terminating NUL. Thus, make e2fsck_pass1_check_symlink() start validating the targets of extent-based symlinks. Fixes: 7cadc57780f3 ("e2fsck: Support long symlinks which use extents") Signed-off-by: Eric Biggers --- e2fsck/pass1.c | 74 ++++++++++++++++++++++++++------------------------ 1 file changed, 39 insertions(+), 35 deletions(-) diff --git a/e2fsck/pass1.c b/e2fsck/pass1.c index 3a49e020..46d70d14 100644 --- a/e2fsck/pass1.c +++ b/e2fsck/pass1.c @@ -185,42 +185,16 @@ int e2fsck_pass1_check_symlink(ext2_filsys fs, ext2_ino_t ino, { unsigned int buflen; unsigned int len; - int i; - ext2_extent_handle_t handle; - struct ext2_extent_info info; - struct ext2fs_extent extent; if ((inode->i_size_high || inode->i_size == 0) || (inode->i_flags & EXT2_INDEX_FL)) return 0; - if (inode->i_flags & EXT4_EXTENTS_FL) { - if (inode->i_flags & EXT4_INLINE_DATA_FL) - return 0; - if (inode->i_size > fs->blocksize) - return 0; - if (ext2fs_extent_open2(fs, ino, inode, &handle)) - return 0; - i = 0; - if (ext2fs_extent_get_info(handle, &info) || - (info.num_entries != 1) || - (info.max_depth != 0)) - goto exit_extent; - if (ext2fs_extent_get(handle, EXT2_EXTENT_ROOT, &extent) || - (extent.e_lblk != 0) || - (extent.e_len != 1) || - (extent.e_pblk < fs->super->s_first_data_block) || - (extent.e_pblk >= ext2fs_blocks_count(fs->super))) - goto exit_extent; - i = 1; - exit_extent: - ext2fs_extent_free(handle); - return i; - } - if (inode->i_flags & EXT4_INLINE_DATA_FL) { size_t inline_size; + if (inode->i_flags & EXT4_EXTENTS_FL) + return 0; if (ext2fs_inline_data_size(fs, ino, &inline_size)) return 0; if (inode->i_size != inline_size) @@ -229,19 +203,49 @@ int e2fsck_pass1_check_symlink(ext2_filsys fs, ext2_ino_t ino, return 1; } - if (ext2fs_is_fast_symlink(inode)) { + if (ext2fs_is_fast_symlink(inode) && + !(inode->i_flags & EXT4_EXTENTS_FL)) { + buf = (char *)inode->i_block; buflen = sizeof(inode->i_block); } else { - if ((inode->i_block[0] < fs->super->s_first_data_block) || - (inode->i_block[0] >= ext2fs_blocks_count(fs->super))) - return 0; + ext2_extent_handle_t handle; + struct ext2_extent_info info; + struct ext2fs_extent extent; + blk64_t blk; + int i; - for (i = 1; i < EXT2_N_BLOCKS; i++) - if (inode->i_block[i]) + if (inode->i_flags & EXT4_EXTENTS_FL) { + if (ext2fs_extent_open2(fs, ino, inode, &handle)) + return 0; + if (ext2fs_extent_get_info(handle, &info) || + (info.num_entries != 1) || + (info.max_depth != 0)) { + ext2fs_extent_free(handle); + return 0; + } + if (ext2fs_extent_get(handle, EXT2_EXTENT_ROOT, + &extent) || + (extent.e_lblk != 0) || + (extent.e_len != 1)) { + ext2fs_extent_free(handle); return 0; + } + blk = extent.e_pblk; + ext2fs_extent_free(handle); + } else { + blk = inode->i_block[0]; + + for (i = 1; i < EXT2_N_BLOCKS; i++) + if (inode->i_block[i]) + return 0; + } + + if (blk < fs->super->s_first_data_block || + blk >= ext2fs_blocks_count(fs->super)) + return 0; - if (io_channel_read_blk64(fs->io, inode->i_block[0], 1, buf)) + if (io_channel_read_blk64(fs->io, blk, 1, buf)) return 0; buflen = fs->blocksize; From patchwork Sat Mar 3 00:59:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Biggers X-Patchwork-Id: 880974 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-ext4-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="FmcAM8hn"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3ztSWP387Pz9s92 for ; Sat, 3 Mar 2018 12:00:01 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S964857AbeCCBAA (ORCPT ); Fri, 2 Mar 2018 20:00:00 -0500 Received: from mail-io0-f196.google.com ([209.85.223.196]:35830 "EHLO mail-io0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S964848AbeCCA75 (ORCPT ); Fri, 2 Mar 2018 19:59:57 -0500 Received: by mail-io0-f196.google.com with SMTP id 30so12472516iog.2 for ; Fri, 02 Mar 2018 16:59:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=K6LHN3dY9N+wal+RpxtQ59ZKvHoIsHc0sHk9eNrNfVU=; b=FmcAM8hnj4wQMGQejJJSijFaI4iDHOA9Rw33N4H+E76hFevddzELDz3oHexn2fqrJ4 kTUzAsU2wuPcBYVTztCRyAKppOSYH1/IPGG5G/hGhJkZSvPCxyIII/e8nEBzt16ZRNee QTGdDO8drecNCXjbMOsneT4NDTGyK9YgOk1I9OVCoX4i/FZwVW698aPP8mCSSDLTKuwc Gqkdxqm4v36tCQb3XyDI5d851TgWpDBUEhWNlS8clDgww/uBhaZcfrMaFiR59aHyOSQK 8A7C71LGhtt9zvchoMK/5JOZX4ZHEVq/BL7iczQ6e6CAxQl1DDJIq5s11h9LhatvoDSd kvcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=K6LHN3dY9N+wal+RpxtQ59ZKvHoIsHc0sHk9eNrNfVU=; b=mjRRrxFhSi5JZmFJIxIjJLwLLo2SDavba1TSybmxzNns1ihZDjA7cNm4MAlDspbodV Z90bKKLNIKfynx0E7k6uuDR8ZgMu7GuLMuLCxgUD0obssgWZBp375FxKUuvpu/3nb9HW wbC+vrfXHb06o8oCXMhWEbl5Ay7aZ2qr5inFnAOVzy8f8v/DyCfbfkMa2exvnGjPOeHC S+KDlG9GKjQZ/u2nvPZLDLyC9eY11hYFQKY4kXofUqy07s8DG/KshapL+Dv8+XOZw7b8 dqnHsnmod+bC2SsLMzI6xt585fHw1jU+Kgn0pO8Qp5sulhxK27Q+WzlzH+raO+wz8fmL Qtlg== X-Gm-Message-State: APf1xPDG8wRz7WeT8oHbFVpKNmN9EhS2bPAOwfXJyYcBkCUai88Tu2UW 0qf6hqpTUvFZMBRoqAtCKNYuJRXe X-Google-Smtp-Source: AG47ELsuwL/TvI0Hs8DAnwNYNpQrcFQB/dFhESdw+fddEooJqMAAIy++fIDXyPIhW13CKUS1BHuoxQ== X-Received: by 10.107.155.71 with SMTP id d68mr9207132ioe.303.1520038796742; Fri, 02 Mar 2018 16:59:56 -0800 (PST) Received: from ebiggers-linuxstation.kir.corp.google.com ([2620:15c:17:3:dc28:5c82:b905:e8a8]) by smtp.gmail.com with ESMTPSA id p135sm1382972itg.44.2018.03.02.16.59.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 02 Mar 2018 16:59:56 -0800 (PST) From: Eric Biggers To: linux-ext4@vger.kernel.org Cc: Eric Biggers Subject: [PATCH 09/10] e2fsck: require that fast symlinks don't have EXT4_EXTENTS_FL Date: Fri, 2 Mar 2018 16:59:22 -0800 Message-Id: <20180303005923.152761-10-ebiggers3@gmail.com> X-Mailer: git-send-email 2.16.2.395.g2e18187dfd-goog In-Reply-To: <20180303005923.152761-1-ebiggers3@gmail.com> References: <20180303005923.152761-1-ebiggers3@gmail.com> Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org From: Eric Biggers It doesn't make sense for EXT4_EXTENTS_FL to be set on a fast symlink. The kernel doesn't set it, and it ignores it if set. Meanwhile, e2fsck is stricter: it will try to validate the extent tree, which will almost certainly fail (assuming the symlink is, in fact, a fast symlink). Make this behavior more explicit by rejecting EXT4_EXTENTS_FL for fast symlinks, rather than going ahead and trying to validate an extent tree. Signed-off-by: Eric Biggers --- e2fsck/pass1.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/e2fsck/pass1.c b/e2fsck/pass1.c index 46d70d14..fccd8816 100644 --- a/e2fsck/pass1.c +++ b/e2fsck/pass1.c @@ -203,9 +203,9 @@ int e2fsck_pass1_check_symlink(ext2_filsys fs, ext2_ino_t ino, return 1; } - if (ext2fs_is_fast_symlink(inode) && - !(inode->i_flags & EXT4_EXTENTS_FL)) { - + if (ext2fs_is_fast_symlink(inode)) { + if (inode->i_flags & EXT4_EXTENTS_FL) + return 0; buf = (char *)inode->i_block; buflen = sizeof(inode->i_block); } else { From patchwork Sat Mar 3 00:59:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Biggers X-Patchwork-Id: 880975 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-ext4-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="WMXSOGV8"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3ztSWY4K81z9s92 for ; Sat, 3 Mar 2018 12:00:09 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S964860AbeCCBAJ (ORCPT ); Fri, 2 Mar 2018 20:00:09 -0500 Received: from mail-it0-f66.google.com ([209.85.214.66]:55343 "EHLO mail-it0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S964843AbeCCA77 (ORCPT ); Fri, 2 Mar 2018 19:59:59 -0500 Received: by mail-it0-f66.google.com with SMTP id n7so3620422ita.5 for ; Fri, 02 Mar 2018 16:59:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=DXpJcUKzz/GmpveZDmaGPOD+oYZIJkVMsjm78C4COQY=; b=WMXSOGV8rqMtNhol/UCJd4MxYp2askL+Q0VdJPEKamIZbmX2U4FFaJinh0bx4F8w1q Zboq5G1xmVFVdP5hbGP/q8EDyh1vUWUIloUcbX1ogxn7pKUYsJaSuDncUx0f0b3T5WxW c5mtykhspSRzjgySNn3ltol03Sf/TbIxkobqytiALLDLKd2VG3bUnrLzMyfO29sWQprg mchh0yLd+Of2xq694qmPq2wJzyNK4Y7pix+7FNixYW8n+ab6B7JrZHZzqGZGquc6K142 IIhIXgggd7xBG4tbWsCuE/X6uYYVVc3hbxNih2Bffh6Ie3deq1OkpS+dy83FmFgwSPR9 r3Mg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=DXpJcUKzz/GmpveZDmaGPOD+oYZIJkVMsjm78C4COQY=; b=QN4o4ntuiMswHk2ewT3nLEEFYTo0zk1GS8FTKJ5I+3g8xFvWt5RE30v22YTYk3/CQ9 uahSjUAbgclCM1oQ/2z2ulWtM2AlviK7SGgZAA4jnMaK2Z9dNt/CYCoGRGVC/kFxND5+ PEj+BRO8IRQ7WMJMBvy3ZEvj3ZlFEbqt3UPh7KLzRR+RslkRQl0fryeUkso/1gLVgjXv vt1WEh4wrlKEDM0cBwy2cN6EzzDTn8fFbP2zASeB05yxMJqjnhs7G6U0CVqmximkjbfv buoCqi/FfWkUpujUVMNcwkgbfZOGEZd/QOispjEReJgnnfRZWs9PKeBztTCXVAjVk9vp KISQ== X-Gm-Message-State: AElRT7Gz5Ej6uL0nDRA2ABGNk44lvON8wbUZJBnR2x1Yi6oTxRADvRix +qFDp8vIiYQ1CFtcachFF+lO60/p X-Google-Smtp-Source: AG47ELtZU2u7+5ubmUoBqYrPE8pHzksL6lKLAyjO9vENSngIM3O1T5uN50K8vp8CyV3zA7CVRJHBoQ== X-Received: by 10.36.148.201 with SMTP id j192mr5077854ite.139.1520038798154; Fri, 02 Mar 2018 16:59:58 -0800 (PST) Received: from ebiggers-linuxstation.kir.corp.google.com ([2620:15c:17:3:dc28:5c82:b905:e8a8]) by smtp.gmail.com with ESMTPSA id p135sm1382972itg.44.2018.03.02.16.59.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 02 Mar 2018 16:59:57 -0800 (PST) From: Eric Biggers To: linux-ext4@vger.kernel.org Cc: Eric Biggers Subject: [PATCH 10/10] tests: test e2fsck of bad symlinks Date: Fri, 2 Mar 2018 16:59:23 -0800 Message-Id: <20180303005923.152761-11-ebiggers3@gmail.com> X-Mailer: git-send-email 2.16.2.395.g2e18187dfd-goog In-Reply-To: <20180303005923.152761-1-ebiggers3@gmail.com> References: <20180303005923.152761-1-ebiggers3@gmail.com> Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org From: Eric Biggers Add a test which verifies that e2fsck will detect a variety of bad symlinks, both fast and slow, and with several combinations of filesystem features including extents, encryption, and inline_data. There was already a similar test (f_badsymlinks), but it's an old test that doesn't use any of these newer filesystem features. Signed-off-by: Eric Biggers --- tests/f_badsymlinks2/expect.1 | 114 ++++++++++++++++++++++++++++ tests/f_badsymlinks2/expect.2 | 7 ++ tests/f_badsymlinks2/image.gz | Bin 0 -> 14302 bytes tests/f_badsymlinks2/mkimage.sh | 127 ++++++++++++++++++++++++++++++++ tests/f_badsymlinks2/name | 1 + 5 files changed, 249 insertions(+) create mode 100644 tests/f_badsymlinks2/expect.1 create mode 100644 tests/f_badsymlinks2/expect.2 create mode 100644 tests/f_badsymlinks2/image.gz create mode 100755 tests/f_badsymlinks2/mkimage.sh create mode 100644 tests/f_badsymlinks2/name diff --git a/tests/f_badsymlinks2/expect.1 b/tests/f_badsymlinks2/expect.1 new file mode 100644 index 00000000..939edce9 --- /dev/null +++ b/tests/f_badsymlinks2/expect.1 @@ -0,0 +1,114 @@ +Pass 1: Checking inodes, blocks, and sizes +Pass 2: Checking directory structure +Symlink /default/empty (inode #13) is invalid. +Clear? yes + +Symlink /default/fast_isize_too_small (inode #15) is invalid. +Clear? yes + +Symlink /default/fast_isize_too_large (inode #16) is invalid. +Clear? yes + +Symlink /default/slow_isize_too_small (inode #19) is invalid. +Clear? yes + +Symlink /default/slow_isize_too_large (inode #20) is invalid. +Clear? yes + +Symlink /default/one_too_long (inode #22) is invalid. +Clear? yes + +Symlink /default/too_long (inode #23) is invalid. +Clear? yes + +Symlink /encrypted/empty (inode #25) is invalid. +Clear? yes + +Symlink /encrypted/fast_isize_too_large (inode #28) is invalid. +Clear? yes + +Symlink /encrypted/fast_isize_too_small (inode #27) is invalid. +Clear? yes + +Symlink /encrypted/one_too_long (inode #34) is invalid. +Clear? yes + +Symlink /encrypted/slow_isize_too_large (inode #32) is invalid. +Clear? yes + +Symlink /encrypted/slow_isize_too_small (inode #31) is invalid. +Clear? yes + +Symlink /encrypted/too_long (inode #35) is invalid. +Clear? yes + +Symlink /extents/empty (inode #38) is invalid. +Clear? yes + +Symlink /extents/fast_isize_too_small (inode #40) is invalid. +Clear? yes + +Symlink /extents/fast_isize_too_large (inode #41) is invalid. +Clear? yes + +Symlink /extents/slow_isize_too_small (inode #44) is invalid. +Clear? yes + +Symlink /extents/slow_isize_too_large (inode #45) is invalid. +Clear? yes + +Symlink /extents/one_too_long (inode #47) is invalid. +Clear? yes + +Symlink /extents/too_long (inode #48) is invalid. +Clear? yes + +Symlink /extents_encrypted/empty (inode #50) is invalid. +Clear? yes + +Symlink /extents_encrypted/fast_isize_too_large (inode #53) is invalid. +Clear? yes + +Symlink /extents_encrypted/fast_isize_too_small (inode #52) is invalid. +Clear? yes + +Symlink /extents_encrypted/one_too_long (inode #59) is invalid. +Clear? yes + +Symlink /extents_encrypted/slow_isize_too_large (inode #57) is invalid. +Clear? yes + +Symlink /extents_encrypted/slow_isize_too_small (inode #56) is invalid. +Clear? yes + +Symlink /extents_encrypted/too_long (inode #60) is invalid. +Clear? yes + +Symlink /inline_data/empty (inode #63) is invalid. +Clear? yes + +Symlink /inline_data/fast_isize_too_small (inode #65) is invalid. +Clear? yes + +Symlink /inline_data/fast_isize_too_large (inode #66) is invalid. +Clear? yes + +Symlink /inline_data/slow_isize_too_small (inode #69) is invalid. +Clear? yes + +Symlink /inline_data/slow_isize_too_large (inode #70) is invalid. +Clear? yes + +Symlink /inline_data/one_too_long (inode #72) is invalid. +Clear? yes + +Symlink /inline_data/too_long (inode #73) is invalid. +Clear? yes + +Pass 3: Checking directory connectivity +Pass 4: Checking reference counts +Pass 5: Checking group summary information + +test_filesys: ***** FILE SYSTEM WAS MODIFIED ***** +test_filesys: 36/80 files (0.0% non-contiguous), 31/150 blocks +Exit status is 1 diff --git a/tests/f_badsymlinks2/expect.2 b/tests/f_badsymlinks2/expect.2 new file mode 100644 index 00000000..3da98a87 --- /dev/null +++ b/tests/f_badsymlinks2/expect.2 @@ -0,0 +1,7 @@ +Pass 1: Checking inodes, blocks, and sizes +Pass 2: Checking directory structure +Pass 3: Checking directory connectivity +Pass 4: Checking reference counts +Pass 5: Checking group summary information +test_filesys: 36/80 files (0.0% non-contiguous), 31/150 blocks +Exit status is 0 diff --git a/tests/f_badsymlinks2/image.gz b/tests/f_badsymlinks2/image.gz new file mode 100644 index 0000000000000000000000000000000000000000..d1f314ced5f639e635848b879b7dd248ec5ecade GIT binary patch literal 14302 zcmeIZ^+TIY(=d8hsZm1cwm& z+WWrW=XuZh1J3u$$q!d{XJ=<;W@l#in%#>w^1*|L2Wk4Z@7Ow;T3h~gkcB6f1gHHO zs~*!XXGx;Ml9!dY_~w-@3(w#%4LQyt`IT*H7_kCHVwinWS`DwHU=3@oO^YNJ;qFFp zwUen??B3FdLR}&+&a%6a$PUEjNtF9js;7T_!m%#sQuTeg_gIr%H`Ljh>S^Xx=-ZsW z1(F8xdo+T4bqyJ}`aX3$6=jql?RK%El}HUOEL?da#K;aIF*2);kaCBm)%)Rh2$&Io zLg03}!@(P;`Z1rM4q=6wy8}dS0);~msHIIgx^Rs7i}eoW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umhka*XS#;>6RfsEFnB%HHCTr7XR z(bE-fWDrtk8(Y6d$~OL>x^ekhWSiido{?~V&M|Crl@eX{nA$Q5hW>71IAPt`-xlEM zxS~J;U;wqKhGKO`9iA_+892E$ua!hOrCVy0^Rx~}!1k^iLcF^sF16^PwJZ|?1bfY_ zl(Us}kRcW-#QRH+D0tarZgyJ&AYqJ;xgKQWe-dES}awh*YNnYVw&9S_%Lh)9*)A1bq{)+{z7^b6SH zw+Bj>R6aHLRUZ;)f3j3w?rPRAI>JzGZyT}8r_ehBtxZx#ImWg;aoFXn@g{O@9qRuc z=8}mvyWK9CLKf_yUwuR_+WRDR=6Uk5MhK-}*^3leAUtZ0bki;SfOBNbFhW|%1hMJ0 z+WCcPJXfjpsDkT&V31^9k(6`Q-lVxX#!b1{FRgyJ{yn z!(neYIu{LVcu2nFHU{%Y;1iG(3|bHk)BJLBw}1T2$6Tv@=B1pY%$$7vTTF<-e1rwI zZ6|B$*y51;v{YsNOh704u7WslTxH(_A734#`xS90Q2}6!lg4KMq5{qbWlxEe7mIu~3bbi(>AX}YTlZO{5 z_O0!Zzr5DY+q!$#<-)QflQUi)8{Ck3=fIu-zn=rhs3=6zU2V-va||+ZXXRdWB)_CR zF{gI;Czt)#&nrn3;0Bb%g2AP;09%iw*-yY7SaXSeGOJtmkT+6e858ATlw=MV7mWPW znMnR=-FoM-EMk?&{eNVMStEGxPx+HG&CS1L|84y1lk;B!FaM|V|N8F;oco`9uy1h$ r|2E?McmMZ==ReR6_qptUTYq8!JOA@dnn@_+R`e^C@xMMk{OkV!t(3** literal 0 HcmV?d00001 diff --git a/tests/f_badsymlinks2/mkimage.sh b/tests/f_badsymlinks2/mkimage.sh new file mode 100755 index 00000000..6bbf020d --- /dev/null +++ b/tests/f_badsymlinks2/mkimage.sh @@ -0,0 +1,127 @@ +#!/bin/bash + +# This is the script that was used to create the image.gz in this directory. + +set -e -u + +BLOCKSIZE=4096 + +do_debugfs() { + umount mnt + debugfs -w "$@" image + mount image mnt +} + +do_tune2fs() { + umount mnt + tune2fs $@ image + mount image mnt +} + +symlink() { + local len=$1 + local src=$2 + local target=$(perl -e 'print "A" x '$len) + ln -s $target $src + stat -c %i $src +} + +# Overwrite the length in the header of the encrypted symlink target +set_encrypted_symlink_len() { + local ino=$1 + local len=$2 + + echo "zap_block -f <$ino> -p $((len%256)) -o 0 -l 1 0" + echo "zap_block -f <$ino> -p $((len/256)) -o 1 -l 1 0" +} + +create_symlinks() { + local dir=$1 + local encrypted=${2:-false} + local overhead=0 + local ino + + if $encrypted; then + overhead=2 + fi + + mkdir -p $dir + + { + ino=$(symlink 1 $dir/empty) + echo "set_inode_field <$ino> i_size 10" + echo "set_inode_field <$ino> block[0] 0" + + symlink 1 $dir/fast_min > /dev/null + + ino=$(symlink 10 $dir/fast_isize_too_small) + echo "set_inode_field <$ino> i_size 1" + + ino=$(symlink 10 $dir/fast_isize_too_large) + echo "set_inode_field <$ino> i_size 20" + + symlink $((59 - overhead)) $dir/fast_max > /dev/null + + symlink $((60 - overhead)) $dir/slow_min > /dev/null + + ino=$(symlink 100 $dir/slow_isize_too_small) + echo "set_inode_field <$ino> i_size 80" + + ino=$(symlink 100 $dir/slow_isize_too_large) + echo "set_inode_field <$ino> i_size 120" + + symlink $((BLOCKSIZE - 1 - overhead)) $dir/slow_max > /dev/null + + ino=$(symlink $((BLOCKSIZE - 1 - overhead)) $dir/one_too_long) + echo "set_inode_field <$ino> i_size $BLOCKSIZE" + echo "zap_block -f <$ino> -p 65 0" + if $encrypted; then + set_encrypted_symlink_len $ino $((BLOCKSIZE - overhead)) + fi + + ino=$(symlink $((BLOCKSIZE - 1 - overhead)) $dir/too_long) + echo "set_inode_field <$ino> i_size $((BLOCKSIZE + 1000))" + echo "zap_block -f <$ino> -p 65 0" + if $encrypted; then + set_encrypted_symlink_len $ino $((BLOCKSIZE + 1000 - overhead)) + fi + + } >> debugfs_commands + do_debugfs < debugfs_commands +} + +create_encrypted_symlinks() { + local dir=$1 link + + mkdir $dir + echo | e4crypt add_key $dir + create_symlinks $dir true + + # Move symlinks into an unencrypted directory (leaving their targets + # encrypted). This makes the fsck output consistent. + mv $dir ${dir}~encrypted + mkdir $dir + mv ${dir}~encrypted/* $dir +} + +mkdir -p mnt +umount mnt &> /dev/null || true +dd if=/dev/zero of=image bs=1024 count=600 + +mke2fs -O 'encrypt,^extents,^64bit' -b $BLOCKSIZE -I 256 image +mount image mnt + +create_symlinks mnt/default +create_encrypted_symlinks mnt/encrypted + +do_tune2fs -O extents +create_symlinks mnt/extents +create_encrypted_symlinks mnt/extents_encrypted + +do_debugfs -R 'feature inline_data' +create_symlinks mnt/inline_data + +rm -rf debugfs_commands mnt/*~encrypted +umount mnt +rmdir mnt +gzip -9 -f image diff --git a/tests/f_badsymlinks2/name b/tests/f_badsymlinks2/name new file mode 100644 index 00000000..81d32856 --- /dev/null +++ b/tests/f_badsymlinks2/name @@ -0,0 +1 @@ +more types of corrupted symlinks