Commit Graph

45 Commits (master)

Author SHA1 Message Date
Theodore Ts'o 8d7a63921f Avoid crashing on unaligned pointers from corrupted file systems
On platforms that don't permit unaligned pointer dereferences,
corrupted file systems will as used by the regression test suite can
cause e2fsck and debugfs to crash.  Avoid those crashes caused by
corrupted file systems.  With this commit the full set of regression
test suites will pass on the sparc64 platform.

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2016-09-04 15:06:32 -04:00
Theodore Ts'o 478360f50b Fix Android build warnings
Also fix some additional gcc -Wall build warnings in a traditional
Linux environment.

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2016-05-29 23:51:08 -04:00
Theodore Ts'o b4f02c9f32 e2fsck: use specific CRC and corruption errors in journal recovery
Sync up with kernel commit 6a797d27: "ext4: call out CRC and
corruption errors with specific error codes".

This allows us to distinguish between CRC errors and I/O errors.

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2016-04-15 19:35:02 -04:00
Darrick J. Wong 86f3b6cf98 e2fsck: clean up feature test macros with predicate functions
Create separate predicate functions to test/set/clear feature flags,
thereby replacing the wordy old macros.  Furthermore, clean out the
places where we open-coded feature tests.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2015-10-24 00:44:40 -04:00
Darrick J. Wong 04c66cb25f e2fsck: fix buffer overrun in revoke block scanning
Check the value of r_count to ensure that we never try to read revoke
records past the end of the revoke block.  It turns out that the
journal writing code in debugfs was also playing fast and loose with
the r_count, so fix that as well.

The Coverity bug was 1297508.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2015-05-16 20:50:21 -04:00
Darrick J. Wong c10700f974 e2fsck: free bh when descriptor block checksum fails
Free the buffer head if the journal descriptor block fails checksum
verification.  This has been patched before (see "e2fsck: free bh on
csum verify error in do_one_pass") but apparently the patch was never
committed to jbd2 in the kernel, so when we resync'd the recovery code
with 3.16, the bug came back.  Sigh.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Cc: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
2014-09-18 21:46:22 -04:00
Darrick J. Wong 38d5adf339 e2fsck/debugfs: fix descriptor block size handling errors with journal_csum
It turns out that there are some serious problems with the on-disk
format of journal checksum v2.  The foremost is that the function to
calculate descriptor tag size returns sizes that are too big.  This
causes alignment issues on some architectures and is compounded by the
fact that some parts of jbd2 use the structure size (incorrectly) to
determine the presence of a 64bit journal instead of checking the
feature flags.  These errors regrettably lead to the journal
corruption reported by Mr. Reardon.

Therefore, introduce journal checksum v3, which enlarges the
descriptor block tag format to allow for full 32-bit checksums of
journal blocks, fix the journal tag function to return the correct
sizes, and fix the jbd2 recovery code to use feature flags to
determine 64bitness.

Add a few function helpers so we don't have to open-code quite so
many pieces.

Switching to a 16-byte block size was found to increase journal size
overhead by a maximum of 0.1%, to convert a 32-bit journal with no
checksumming to a 32-bit journal with checksum v3 enabled.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reported-by: TR Reardon <thomas_reardon@hotmail.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2014-09-11 12:40:54 -04:00
Darrick J. Wong bf93a9685e e2fsck: fix infinite loop when recovering corrupt journal blocks
When recovering the journal, don't fall into an infinite loop if we
encounter a corrupt journal block.  Instead, just skip the block and
proceed with the full filesystem fsck.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2014-08-26 23:45:11 -04:00
Darrick J. Wong 97f168b67e e2fsck: resync jbd2 revoke code from Linux 3.16
Synchronize e2fsck's copy of revoke.c with the kernel's copy in
fs/jbd2.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2014-08-26 23:43:20 -04:00
Darrick J. Wong 13af4b93fb e2fsck: resync jbd2 recovery code from Linux 3.16
Synchronize e2fsck's copy of recovery.c with the kernel's copy in
fs/jbd2.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2014-08-26 23:32:14 -04:00
Eric Sandeen 26dacce72c e2fsck: free bh on csum verify error in do_one_pass
Coverity (re-)spotted this; it was triaged as a false positive,
but it seems pretty clear that the bh (which was just checked)
isn't currently freed before the function exits.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2014-07-22 12:40:30 -04:00
Darrick J. Wong bd78b1dae9 e2fsck: fix journal block tag checksum verification
Al Viro complained of a ton of bogosity with regards to the jbd2 block tag
header checksum.  This one checksum is 16 bits, so cut off the upper 16 bits
and treat it as a 16-bit value and don't mess around with be32* conversions.
Fortunately metadata checksumming is still "experimental" and not in a shipping
e2fsprogs, so there should be few users affected by this.

This is the e2fsprogs version of the kernel patch.

Reported-by: Al Viro <viro@ZenIV.linux.org.uk>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2013-06-08 17:03:04 -04:00
Theodore Ts'o fd9ca82599 e2fsck: fix gcc -Wall nits
[For 1.43 branch]

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2013-05-20 09:17:02 -04:00
Theodore Ts'o 581ecb6d88 Merge branch 'maint' into next
Conflicts:
	e2fsck/pass1b.c
	e2fsck/rehash.c
	lib/ext2fs/crc32c.c
	lib/ext2fs/gen_bitmap64.c
	misc/tune2fs.c
2013-05-19 21:45:16 -04:00
Theodore Ts'o 68477355a9 e2fsck: fix gcc -Wall nits
Perhaps the most serious fix up is a type-punning warning which could
result in miscompilation with overly enthusiastic compilers.

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2013-05-19 21:36:31 -04:00
Theodore Ts'o 8c236c62c9 Merge branch 'maint' into next 2013-03-13 16:17:34 -04:00
Theodore Ts'o d3f58ef166 e2fsck: fix build failure with --enable-jbd-debug
Commit e3507739e4 introduced a build failure if e2fsprogs is
configured with --enable-jbd-debug.  Fix this.

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2013-03-13 14:02:53 -04:00
Andreas Dilger 1b8c4c1b45 build: quiet build warnings for "gcc -Wall"
Signed-off-by: Andreas Dilger <adilger@dilger.ca>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2013-01-27 22:31:03 -05:00
Theodore Ts'o b9b5e43ea8 Merge branch 'maint' into next
Conflicts:
	RELEASE-NOTES
	debian/changelog
	lib/ext2fs/crc32c.c
	lib/ext2fs/rw_bitmaps.c
	resize/resize2fs.c
	version.h
2013-01-01 18:50:26 -05:00
Theodore Ts'o e3507739e4 Fix gcc -Wall nits
This fixes the last set of gcc -Wall complaints.

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2013-01-01 13:28:27 -05:00
Andreas Dilger 00eb0eee0a build: quiet some "gcc -Wall" compiler warnings
Quiet a number of simple compiler warnings:
- pointers not initialized by ext2fs_get_mem()
- return without value in non-void function
- dereferencing type-punned pointers
- unused variables

Signed-off-by: Andreas Dilger <adilger@dilger.ca>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2012-12-29 17:39:45 -05:00
Darrick J. Wong a8ed37054f e2fsck: refactor crc32_be code
Remove crc32_be in favor of the implementation in libext2fs.

Signed-off-by: Darrick J. Wong <djwong@us.ibm.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2012-08-02 20:47:46 -04:00
Darrick J. Wong d920038068 e2fsck: verify data block checksums when recovering journal
Check the data block checksums when recovering the journal.

Signed-off-by: Darrick J. Wong <djwong@us.ibm.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2012-08-02 20:47:46 -04:00
Darrick J. Wong 721e065c62 e2fsck: check commit block checksum during recovery
When recovering a journal with checksum v2, verify the commit block
checksum.

Signed-off-by: Darrick J. Wong <djwong@us.ibm.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2012-08-02 20:47:46 -04:00
Darrick J. Wong 5c8428513d e2fsck: check descriptor block checksum when recovering journal
Verify the descriptor block checksum when recovering a journal.

Signed-off-by: Darrick J. Wong <djwong@us.ibm.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2012-08-02 20:47:46 -04:00
Darrick J. Wong d35ed158cf e2fsck: check revoke block checksum during recovery
Verify the revoke block checksum when recovering the journal.

Signed-off-by: Darrick J. Wong <djwong@us.ibm.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2012-08-02 20:47:45 -04:00
Darrick J. Wong 2556373a33 libext2fs: change on-disk journal layout to support metadata checksumming
Define flags and change journal structure definitions to support v2 journal
checksumming.

Signed-off-by: Darrick J. Wong <djwong@us.ibm.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2012-08-02 20:47:45 -04:00
Theodore Ts'o 3b693d0b03 e2fsck: fix 64-bit journal support
64-bit journal support was broken; we weren't using the high bits from
the journal descriptor blocks!  We were also using "unsigned long" for
the journal block numbers, which would be a problem on 32-bit systems.

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2012-05-21 21:30:45 -04:00
Darrick J. Wong 79a4dddbf7 e2fsck: recover revoke blocks on 64bit filesystems correctly
Since the advent of 64bit filesystems, revoke blocks store 64-bit
block numbers instead of 32-bit block numbers.  Therefore we need to
be able to handle that case.

Signed-off-by: Darrick J. Wong <djwong@us.ibm.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2011-10-08 13:37:08 -04:00
Theodore Ts'o d1154eb460 Shorten compile commands run by the build system
The DEFS line in MCONFIG had gotten so long that it exceeded 4k, and
this was starting to cause some tools heartburn.  It also made "make
V=1" almost useless, since trying to following the individual commands
run by make was lost in the noise of all of the defines.

So fix this by putting the configure-generated defines in lib/config.h
and the directory pathnames to lib/dirpaths.h.

In addition, clean up some vestigal defines in configure.in and in the
Makefiles to further shorten the cc command lines.

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2011-09-18 17:34:37 -04:00
Eric Sandeen c816ecb204 e2fsprogs: fix type-punning warnings
Flags used during RHEL/Fedora builds lead to a couple type-punning
warnings:

  recovery.c: In function 'do_one_pass':
  recovery.c:539: warning: dereferencing type-punned pointer will break strict-aliasing rules
  ./csum.c: In function 'print_csum':
  ./csum.c:170: warning: dereferencing type-punned pointer will break strict-aliasing rules

The two changes below fix this up.

Note that the csum test binary output changes slightly, but this does
not break any tests.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2010-12-16 17:15:30 -05:00
Theodore Ts'o 2acad6b489 Fix gcc -Wall warnings in e2fsck
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2008-06-07 11:04:10 -04:00
Theodore Ts'o 185c4aeaf2 e2fsck: Add support to check journal checksums
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2008-06-06 23:38:38 -04:00
Theodore Ts'o e5ea6b14eb e2fsck: Fix potential data corruptor bug in journal recovery
While synchronizing e2fsck's recovery.c with the latest 2.6 kernel
sources, I discovered a serious bug that apparently had been fixed in
the kernel sometime between Deceber 2003 and April 2005, but which had
not been carried over to e2fsprogs.  Specifically, when blocks whose
first 4 bytes are JFS_MAGIC_NUMBER (0xc03b3998) are written into the
journal, the first 4 bytes zero'ed out.  A one character typo meant
that when the blocks were replayed by e2fsck, the JFS_MAGIC_NUMBER
would not be restored.

Oops.

Fortunately, it is *highly* unlikely that ext4 metadata blocks will
contain that magic number in the first four bytes, and data=journalled
is a relatively rarely used.

This commit fixes this bug, as well as updating e2fsck's recovery.c to
be in sync with 2.6.25.

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2008-05-20 14:51:14 -04:00
Matthias Andree f6567a889f Fix printf types (FreeBSD has u_long for ntohl).
Signed-off-by: Matthias Andree <matthias.andree@gmx.de>
2006-05-30 16:26:29 +02:00
Theodore Ts'o 2aa362f54a Fix memory leak in e2fsck's error paths
Add missing brelse() calls to avoid memory leaks in error paths.  (Thanks
to Michael C. Thompson for pointing these out; they were originally 
found using Coverity.)

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2006-05-14 17:16:29 -04:00
Takashi Sato 8deb80a5d1 Fix format statements to make e2fsprogs programs 32-bit clean
Change the format string(%d, %ld) for a block number and inode number
to %u or %lu.

Signed-off-by: Takashi Sato <sho@tnes.nec.co.jp>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2006-03-18 21:43:46 -05:00
Theodore Ts'o 3de085dd41 recovery.c, jfs_user.h: Sync recovery.c with latest 2.5 kernel
version.
2003-12-07 01:00:02 -05:00
Theodore Ts'o 8cf93332d1 Fix e2fsck's handling of external journals,and update journal
recovery files from 2.4.17-pre8.
2001-12-16 02:23:36 -05:00
Theodore Ts'o 725c474ffc ChangeLog, jfs.h:
jfs.h: Synchronize with ext3 0.7a
ChangeLog, recovery.c, revoke.c:
  recover.c, revoke.c: Synchronize with ext3 0.7a
2001-06-08 11:55:44 +00:00
Theodore Ts'o a479fe6049 ChangeLog, recovery.c:
recovery.c (scan_revoke_records): Fix bug in recovery code; missing
  	byte order conversion.
2001-06-02 04:50:14 +00:00
Theodore Ts'o 1f73503816 ChangeLog, recovery.c, revoke.c:
recovery.c, revoke.c: Synchronize with 0.6b ext3 files.
2001-03-29 19:00:50 +00:00
Theodore Ts'o 53ef44c40a Many files:
journal.c, pass1.c, pass1b.c, pass3.c, recovery.c, revoke.c, super.c,
  	unix.c, util.c: Fix random gcc -Wall complaints.
  jfs_user.h: Use more sophisticated inline handling to allow building
  	with --enable-gcc-wall
2001-01-06 05:55:58 +00:00
Theodore Ts'o 0e8a9560d8 Many files:
jfs_e2fsck.h, jfs_user.h: Replaces jfs_compat.h.  The jfs.h file has
  	been moved to the include/linux directory.
  journal.c, revoke.c, recovery.c: Updated files from Stephen to support
  	the V2 superblock and revoke processing.  The journal.c and revoke.c
  	files are copies from the ext3 kernel source.
  Makefile.in: Added revoke.c to the list of source/object files.
Makefile.in:
  Fix up some mistakes in the source file list, and regenerate the
  dependencies.
  Update Makefile dependencies.
ChangeLog, jfs.h:
  jfs.h: Remove excess #include of JFS_DEBUG.  Not needed for e2fsprogs,
  	since we optioanlly define it in the configuration file system.
2000-12-09 06:41:25 +00:00
Theodore Ts'o 3b5386dca8 Many files:
journal.c: implement loading of ext3 journal for recovery code
  problem.c (fix_problem): return answer from PR_AFTER_CODE to caller.
  	Add journal problems.
  recovery.c (journal_recover): user-space ext3 journal recovery code
  unix.c (main) : check journal and do recovery in separate steps
  jfs.h, recovery.c: Files ext3 kernel code.
  jfs_compat.h: Compatibility header file to allow kernel code to be
  	linked to e2fsck.
2000-08-14 14:25:19 +00:00