Commit Graph

5225 Commits (2df733facd99261a4c462f76f72e143e803487d0)

Author SHA1 Message Date
Darrick J. Wong 79614b2709 libext2fs/e2fsck: provide routines to read-ahead metadata
This patch adds to e2fsck the ability to pre-fetch metadata into the
page cache in the hopes of speeding up fsck runs.  There are two new
functions -- the first allows a caller to readahead a list of blocks,
and the second is a helper function that uses that first mechanism to
load group data (bitmaps, inode tables).

These new e2fsck routines require the addition of a dblist API to
allow us to iterate a subset of a dblist.  This will enable
incremental directory block readahead in e2fsck pass 2.

There's also a function to estimate the readahead given a FS.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2015-04-21 10:40:15 -04:00
Darrick J. Wong 76761ca221 e2fsck: turn inline data symlink into a fast symlink when possible
When there's a problem accessing the EA part of an inline data symlink
and we want to truncate the symlink back to 60 characters (hoping the
user can re-establish the link later on, apparently) be sure to turn
off the inline data flag to convert the symlink back to a regular fast
symlink.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2015-04-20 21:48:02 -04:00
Darrick J. Wong e0d5dd3602 e2fuzz: fuzz harder
Once we've "fixed" the filesystem, try mounting and modifying it to see
if we can break the kernel.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2015-04-20 21:47:18 -04:00
Theodore Ts'o a6721909c2 Revert "libext2fs: encrypted symlinks are never fast"
This reverts commit ae73e88e82.

The latest kernel patches will now create fast encrypted symlinks

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2015-04-12 18:05:07 -04:00
Theodore Ts'o fc898cb99b Reserve superblock fields s_lpf_ino and s_encryption_level
The s_lpf_ino field is intended to store the location of the lost and
found directory if the root directory becomes encrypted (which is not
yet supported).  The s_encryption_level field is designed to allow
support for future changes in the on-disk ext4 encryption format while
this feature under development, without having to burn a large number
of bits in the incompat feature flag.

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2015-04-12 08:51:53 -04:00
Theodore Ts'o 4a05268cf8 Remove compression support
The compression patches were an out-of-kernel patch set that was (a)
only available for ext2, (b) something that was never could be
stablized due to file system corruption, and (c) the most recent
patches were for 3.1, last updated in 2011.

The history of the compression patches has been a bit checkered.
There is a long history here at http://e2compr.sourceforge.net which
lists the perspective of the people working on it from the e2compr
side.

From the ext2/3/4 mainline developers' perspective, initial
compression support was added to e2fsprogs in 2000 (in the Linux 2.2
era), but due to stability concerns the kernel patches were never
merged into the mainline kernel.  While there were some sporadic
efforts to try to get the ext2 compression patches working in the 2.4
and 2.6 era, by that time mainline work had moved on to ext4, and the
e2compr approach could only work with 32-bit block numbers and
indirect mapped files.

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2015-04-12 08:42:40 -04:00
Theodore Ts'o 8dbcedd702 Merge branch 'maint' into next 2015-04-05 20:44:39 -04:00
Theodore Ts'o a0556bd8e1 e4crypt: add the get_policy command
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2015-04-05 20:43:24 -04:00
Theodore Ts'o 654531df2a tune2fs: add ability to enable the encrypt feature
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2015-04-05 20:42:58 -04:00
Theodore Ts'o f7257a93f9 Change filename encryption to use CTS mode
Previously we were using a weird hybrid CBC/CTS.  Switch things so we
are using straight CTS; this corresponds to changes made in the latest
ext4 encryption patches.

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2015-04-05 20:39:57 -04:00
Theodore Ts'o 8afaf3be33 libext2fs: fix bug in ext2fs_digest_encode()
The ext2fs_digest_encode() function was broken for any input which was
a multiple of 3.  Previously we never hit that case, so we never
noticed it was busted.  Also fix up the unit test so future problems
like this get noticed quickly.

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2015-04-05 20:35:50 -04:00
Theodore Ts'o 4fb758aa4b Clean up and fix Android build files
Add missing new lib/ext2fs source files that were added for encryption
support.  Also move configuration #define's from individual Android.mk
to the android_config.h file, since we've moved away from specifying
configuration #define's on the command-line upstream.

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2015-03-30 14:50:55 -04:00
Theodore Ts'o 8b5c6c78d5 Update version.h
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2015-03-30 02:13:09 -04:00
Theodore Ts'o 1e734e72e1 e4crypt: change the UI to use a subcommand style
Also add a new subcommand "new_session", which works much like keyctl
new_session does.

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2015-03-30 02:13:09 -04:00
Darrick J. Wong ce93d0ea3d libext2fs: zero hash in ibody extended attributes
The kernel never updates the extended attribute hash value for
attributes stored in the inode.  However, fsck has always checked this
value (if it's nonzero) and will complain if the hash doesn't match
the xattr.  Therefore, always zero the hash value when writing to
in-ibody xattrs to avoid creating "corrupt" attribute errors
downstream.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2015-03-29 00:12:53 -04:00
Darrick J. Wong dbb328576d e2fsck: actually fix inline_data flags problems when user says to do so
fix_problem() returning 1 means to fix the fs error, so do that.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2015-03-29 00:04:46 -04:00
Darrick J. Wong fae2467fb6 libext2fs: ext2fs_new_block2() should call alloc_block hook
If ext2fs_new_block2() is called without a specific block map, we
should call the alloc_block hook before checking fs->block_map.  This
helps us to avoid a bug in e2fsck where we need to allocate a block
but instead of consulting block_found_map, we use the FS bitmaps,
which (prior to pass 5) could be wrong.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2015-03-28 23:58:20 -04:00
Darrick J. Wong 3d28f54589 libext2fs: zero blocks via FALLOC_FL_ZERO_RANGE in ext2fs_zero_blocks
Plumb a new call into the IO manager to support translating
ext2fs_zero_blocks calls into the equivalent FALLOC_FL_ZERO_RANGE
fallocate flag primitive when possible.  This patch provides _only_
support for file-based images.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2015-03-28 23:08:25 -04:00
Theodore Ts'o f096708126 e2fsck: use PROMPT_NONE for FUTURE_SB_LAST_*_FUDGED problems
This allows us to print a message warning the user that there is
something funny going on with their hardware clock (probably time zone
issues caused by trying to be compatible with legacy OS's such as
Windows), without triggering a full file system check.

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2015-03-28 21:39:54 -04:00
Theodore Ts'o 41f2210131 Add support for a password salt stored in the superblock
Previously, e4crypt required the user to manually specify the salt
used for their passphrase.  This was user unfriendly to say the least.
The e4crypt program can now request the salt using an ioctl, which
will automatically generate the salt if necessary, and keep it in the
ext4 superblock.

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2015-03-28 20:15:02 -04:00
Ildar Muslukhov bfa4b350b1 misc: add e4crypt tool
This patch adds new e4crypt tool for encryption management in the ext4
filesystem.

Signed-off-by: Ildar Muslukhov <muslukhovi@gmail.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2015-03-26 09:30:03 -04:00
Theodore Ts'o c4241cf50a libext2fs: fix blocksize for SHA512
The blocksize of SHA512 is 128 bytes, not 512.

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2015-03-26 00:17:48 -04:00
Ildar Muslukhov bbb859496a misc: teach mke2fs to create encrypted file systems
Also enable support for encryption in e2fsprogs.

Signed-off-by: Ildar Muslukhov <muslukhovi@gmail.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2015-03-08 23:29:04 -04:00
Theodore Ts'o 62ad24802c e2fsck: handle encrypted directories which are indexed using htree
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2015-03-08 19:09:52 -04:00
Theodore Ts'o 6a5bdaf73d libext2fs: fix up ext2fs_sha256() and ext2fs_sha512()
Add const annotation to the input pointers; also run the tst_sha256
and tst_sha512 unit tests on a "make check".

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2015-03-08 18:19:05 -04:00
Theodore Ts'o bf34b4af70 libext2fs: add ext2fs_digest_encode()
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2015-03-08 18:15:47 -04:00
Theodore Ts'o 68a1de3df3 debugfs: pretty print encrypted filenames in the ls command
Added the -r (raw) option to print the actual encrypted entry.

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2015-03-08 18:04:04 -04:00
Theodore Ts'o baa14bd17f e2fsck: fix spurious duplicate directory entries with encrypted filenames
Use memcmp() instead of strncmp() since encrypted directory names can
contain NUL characters.  For non-encrypted directories, we've already
checked for the case of NUL characters in file names, so it's safe to
use memcmp() here in all cases.

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2015-03-02 11:40:18 -05:00
Theodore Ts'o ae73e88e82 libext2fs: encrypted symlinks are never fast
Teach ext2fs_inodes_has_valid_blocks2() that encrypted symlinks always
use an external block (i.e., we never try to store the symlink in the
i_blocks[] array if it is encrypted).

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2015-03-01 16:58:46 -05:00
Theodore Ts'o 321f3446f3 Add files to build on Android
The Android.mk files were taken from the Android AOSP sources, and
updated for the 1.43 next branch.  The intention is that this will
allow the repository which is currently located in external/e2fsprogs
with one which is based off of the upstream e2fsprogs.  Right now
external/e2fsprogs was not created using "git clone", so it means that
git merges don't work.  After the external/e2fsprogs Android
repository is replaced, with one based off the upstream repository,
Android will be able to synchronize with the upstream repository by
pulling and merging from upstream, and then running the script
"./util/gen-android-files" to update any generated files.  (This is
necessary because in the Android build system, the Android.mk files
are rather stylized and don't make it easy to run arbitrary shell
scripts during the build phase.)

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2015-03-01 15:45:11 -05:00
Theodore Ts'o c379cdc334 e2fsck: clean up assertions in dict.c
The C preprocessing symbol NDEBUG is also defined (differently) by
Android's build files, and this was causing compilation failures.  So
change assert() to dict_assert() and manually define it instead of
relying on the NDEBUG and <assert.h> semantics.

Also make sure the necessary debugging functions are available is
DICT_NODEBUG is not defined, so that dict.c will correctly build with
and without DICT_NODEBUG.

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2015-03-01 15:44:55 -05:00
Theodore Ts'o 52a06740ef libext2fs: make sure dirent functions have prototypes if inline is disabled
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2015-02-23 23:00:17 -05:00
Theodore Ts'o 569ee9020d libext2fs: add functions for sha256 and sha512
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2015-02-23 22:38:46 -05:00
Theodore Ts'o b59014c994 libe2p: add support for printing and parsing the encryption mode
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2015-02-23 18:05:21 -05:00
Theodore Ts'o dbff534ec6 e2fsck: suppress bad name checks for encrypted directories
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2015-02-23 17:44:23 -05:00
Theodore Ts'o 8b39e4cf77 Add support for the read-only feature
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2015-02-23 13:04:47 -05:00
Darrick J. Wong aeb933b3f2 e2fsck: add a 'yes to all' response in interactive mode
Provide a mechanism for a user to switch fsck into '-y' mode if they
start an interactive session and then get tired of pressing 'y' in
response to numerous prompts.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2015-02-16 10:41:20 -05:00
Theodore Ts'o ad5d05d645 Merge branch 'maint' into next 2015-02-16 10:17:21 -05:00
Theodore Ts'o 49d0fe2a14 libext2fs: fix potential buffer overflow in closefs()
The bug fix in f66e6ce4446: "libext2fs: avoid buffer overflow if
s_first_meta_bg is too big" had a typo in the fix for
ext2fs_closefs().  In practice most of the security exposure was from
the openfs path, since this meant if there was a carefully crafted
file system, buffer overrun would be triggered when the file system was
opened.

However, if corrupted file system didn't trip over some corruption
check, and then the file system was modified via tune2fs or debugfs,
such that the superblock was marked dirty and then written out via the
closefs() path, it's possible that the buffer overrun could be
triggered when the file system is closed.

Also clear up a signed vs unsigned warning while we're at it.

Thanks to Nick Kralevich <nnk@google.com> for asking me to look at
compiler warning in the code in question, which led me to notice the
bug in f66e6ce444.

Addresses: CVE-2015-1572

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2015-02-11 15:06:18 -05:00
Darrick J. Wong 4a3dc1f0b6 e2fsck: salvage under-sized dirents by removing them
If the directory processing code ends up pointing to a directory entry
that's so close to the end of the block that there's not even space
for a rec_len/name_len, just substitute dummy values that will force
e2fsck to extend the previous entry to cover the remaining space.  We
can't use the helper methods to extract rec_len because that's reading
off the end of the buffer.

This isn't an issue with non-inline directories because the directory
check buffer is zero-extended so that fsck won't blow up.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2015-01-29 11:09:07 -05:00
Darrick J. Wong e274cc39b9 e2fsck: improve the inline directory detector
Strengthen the checks that guess if the inode we're looking at is an
inline directory.  The current check sweeps up any inline inode if
its length is a multiple of four; now we'll at least try to see if
there's the beginning of a valid directory entry.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2015-01-28 11:37:44 -05:00
Darrick J. Wong 0ac4b3973f e2fsck: inspect inline dir data as two directory blocks
The design of inline directories (apparently) calls for the i_block[]
region and the EA regions to be treated as if they were two separate
blocks of dirents.  Effectively this means that it is impossible for a
directory entry to straddle both areas.  e2fsck doesn't enforce this,
so teach it to do so.  e2fslib already knows to do this....

Cc: Zheng Liu <gnehzuil.liu@gmail.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2015-01-28 09:00:13 -05:00
Darrick J. Wong 09282b8a0b e2fsck: decrement bad count _after_ remapping a duplicate block
Decrement the bad count *after* we've shown that (a) we can allocate a
replacement block and (b) remap the file block.  Unfortunately,
the only way to tell if the remapping succeeded is to wait until the
next clone_file_block() call or block_iterate3() returns.

Otherwise, there's a corruption error: we decrease the badcount once in
preparation to remap, then the remap fails (either we can't find a
replacement block or we have to split the extent tree and can't find a
new extent block), so we delete the file, which decreases the badcount
on the block a second time.  Later on e2fsck will think that it's
straightened out all the duplicate blocks, which isn't true.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2015-01-28 08:53:54 -05:00
Darrick J. Wong 5e61441a40 e2fsck: handle multiple *ind block collisions with critical metadata
An earlier patch tried to detect indirect blocks that conflicted with
critical FS metadata for the purpose of preventing corrections being
made to those indirect blocks.  Unfortunately, that patch cannot
handle more than one conflicting *ind block per file; therefore, use
the ref_block parameter to test the metadata block map to decide if
we need to avoid fixing the *ind block when we're iterating the
block's entries.  (We have to iterate the block to capture any blocks
that the block points to, as they could be in use.)

As a side note, in 1B we'll reallocate all those conflicting *ind
blocks and restart fsck, so the contents will be checked eventually.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2015-01-27 13:12:59 -05:00
Darrick J. Wong b151d346d4 e2fsck: fix message when the journal is deleted and regenerated
When we recreate the journal, don't say that the FS "is now ext3
again", since we could be fixing a damaged ext4 FS journal, which does
not magically convert the FS back to ext3.

[ Use "journaled" instead of "journalled", and also fix the message we
  print when deleting the journal --Ted ]

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2015-01-27 13:12:52 -05:00
Darrick J. Wong fac0c8ead8 e2fsck: on read error, don't rewrite blocks past the end of the fs
If e2fsck encounters a read error on a block past the end of the
filesystem, don't bother trying to "rewrite" the block.  We might
still want to re-try the read to capture FS data marooned past the end
of the filesystem, but in that case e2fsck ought to move the block
back inside the filesystem.

This enables e2fuzz to detect writes past the end of the FS due to
software bugs.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2015-01-27 13:12:37 -05:00
Darrick J. Wong 3ee2946581 e2fsck: clear i_block[] when there are too many bad mappings on a special inode
If we decide to clear a special inode because of bad mappings, we need
to zero the i_block array.  The clearing routine depends on setting
i_links_count to zero to keep us from re-checking the block maps,
but that field isn't checked for special inodes.  Therefore, if we
haven't erased the mappings, check_blocks will restart fsck and fsck
will try to check the blocks again, leading to an infinite loop.

(This seems easy to trigger if the bootloader inode extent map is
corrupted.)

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2015-01-27 13:12:31 -05:00
Darrick J. Wong e263765505 tune2fs: direct user to resize2fs for 64bit conversion
If the user tries to enable or disable the 64bit feature via tune2fs,
tell them how to use resize2fs to effect the conversion.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2015-01-27 13:12:07 -05:00
Darrick J. Wong f2a96b6eb9 tune2fs: abort when trying to enable/disable metadata_csum on mounted fs
Earlier, I tried to make tune2fs abort if the user tried to enable or
disable metadata_csum on a mounted FS, but forgot the exit() call.
Supply it now.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2015-01-27 13:11:41 -05:00
Darrick J. Wong dd3ffbc918 tune2fs: disable csum verification before resizing inode
When we're turning on metadata checksumming /and/ resizing the inode
at the same time, disable checksum verification during the
resize_inode() call because the subroutines it calls will try to
verify the checksums (which have not yet been set), causing the
operation to fail unnecessarily.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2015-01-27 13:11:18 -05:00