Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'ext4_for_linus_stable' of git://git.kernel.org/pub/scm/linux/kernel/git/tytso/ext4

Pull ext4 fixes from Ted Ts'o:
"Ext4 bug fixes for v4.4, including fixes for post-2038 time encodings,
some endian conversion problems with ext4 encryption, potential memory
leaks after truncate in data=journal mode, and an ocfs2 regression
caused by a jbd2 performance improvement"

* tag 'ext4_for_linus_stable' of git://git.kernel.org/pub/scm/linux/kernel/git/tytso/ext4:
jbd2: fix null committed data return in undo_access
ext4: add "static" to ext4_seq_##name##_fops struct
ext4: fix an endianness bug in ext4_encrypted_follow_link()
ext4: fix an endianness bug in ext4_encrypted_zeroout()
jbd2: Fix unreclaimed pages after truncate in data=journal mode
ext4: Fix handling of extended tv_sec

+56 -13
+1 -1
fs/ext4/crypto.c
··· 389 389 struct ext4_crypto_ctx *ctx; 390 390 struct page *ciphertext_page = NULL; 391 391 struct bio *bio; 392 - ext4_lblk_t lblk = ex->ee_block; 392 + ext4_lblk_t lblk = le32_to_cpu(ex->ee_block); 393 393 ext4_fsblk_t pblk = ext4_ext_pblock(ex); 394 394 unsigned int len = ext4_ext_get_actual_len(ex); 395 395 int ret, err = 0;
+44 -7
fs/ext4/ext4.h
··· 26 26 #include <linux/seqlock.h> 27 27 #include <linux/mutex.h> 28 28 #include <linux/timer.h> 29 + #include <linux/version.h> 29 30 #include <linux/wait.h> 30 31 #include <linux/blockgroup_lock.h> 31 32 #include <linux/percpu_counter.h> ··· 728 727 <= (EXT4_GOOD_OLD_INODE_SIZE + \ 729 728 (einode)->i_extra_isize)) \ 730 729 730 + /* 731 + * We use an encoding that preserves the times for extra epoch "00": 732 + * 733 + * extra msb of adjust for signed 734 + * epoch 32-bit 32-bit tv_sec to 735 + * bits time decoded 64-bit tv_sec 64-bit tv_sec valid time range 736 + * 0 0 1 -0x80000000..-0x00000001 0x000000000 1901-12-13..1969-12-31 737 + * 0 0 0 0x000000000..0x07fffffff 0x000000000 1970-01-01..2038-01-19 738 + * 0 1 1 0x080000000..0x0ffffffff 0x100000000 2038-01-19..2106-02-07 739 + * 0 1 0 0x100000000..0x17fffffff 0x100000000 2106-02-07..2174-02-25 740 + * 1 0 1 0x180000000..0x1ffffffff 0x200000000 2174-02-25..2242-03-16 741 + * 1 0 0 0x200000000..0x27fffffff 0x200000000 2242-03-16..2310-04-04 742 + * 1 1 1 0x280000000..0x2ffffffff 0x300000000 2310-04-04..2378-04-22 743 + * 1 1 0 0x300000000..0x37fffffff 0x300000000 2378-04-22..2446-05-10 744 + * 745 + * Note that previous versions of the kernel on 64-bit systems would 746 + * incorrectly use extra epoch bits 1,1 for dates between 1901 and 747 + * 1970. e2fsck will correct this, assuming that it is run on the 748 + * affected filesystem before 2242. 749 + */ 750 + 731 751 static inline __le32 ext4_encode_extra_time(struct timespec *time) 732 752 { 733 - return cpu_to_le32((sizeof(time->tv_sec) > 4 ? 734 - (time->tv_sec >> 32) & EXT4_EPOCH_MASK : 0) | 735 - ((time->tv_nsec << EXT4_EPOCH_BITS) & EXT4_NSEC_MASK)); 753 + u32 extra = sizeof(time->tv_sec) > 4 ? 754 + ((time->tv_sec - (s32)time->tv_sec) >> 32) & EXT4_EPOCH_MASK : 0; 755 + return cpu_to_le32(extra | (time->tv_nsec << EXT4_EPOCH_BITS)); 736 756 } 737 757 738 758 static inline void ext4_decode_extra_time(struct timespec *time, __le32 extra) 739 759 { 740 - if (sizeof(time->tv_sec) > 4) 741 - time->tv_sec |= (__u64)(le32_to_cpu(extra) & EXT4_EPOCH_MASK) 742 - << 32; 743 - time->tv_nsec = (le32_to_cpu(extra) & EXT4_NSEC_MASK) >> EXT4_EPOCH_BITS; 760 + if (unlikely(sizeof(time->tv_sec) > 4 && 761 + (extra & cpu_to_le32(EXT4_EPOCH_MASK)))) { 762 + #if LINUX_VERSION_CODE < KERNEL_VERSION(4,20,0) 763 + /* Handle legacy encoding of pre-1970 dates with epoch 764 + * bits 1,1. We assume that by kernel version 4.20, 765 + * everyone will have run fsck over the affected 766 + * filesystems to correct the problem. (This 767 + * backwards compatibility may be removed before this 768 + * time, at the discretion of the ext4 developers.) 769 + */ 770 + u64 extra_bits = le32_to_cpu(extra) & EXT4_EPOCH_MASK; 771 + if (extra_bits == 3 && ((time->tv_sec) & 0x80000000) != 0) 772 + extra_bits = 0; 773 + time->tv_sec += extra_bits << 32; 774 + #else 775 + time->tv_sec += (u64)(le32_to_cpu(extra) & EXT4_EPOCH_MASK) << 32; 776 + #endif 777 + } 778 + time->tv_nsec = (le32_to_cpu(extra) & EXT4_NSEC_MASK) >> EXT4_EPOCH_BITS; 744 779 } 745 780 746 781 #define EXT4_INODE_SET_XTIME(xtime, inode, raw_inode) \
+1 -1
fs/ext4/symlink.c
··· 52 52 /* Symlink is encrypted */ 53 53 sd = (struct ext4_encrypted_symlink_data *)caddr; 54 54 cstr.name = sd->encrypted_path; 55 - cstr.len = le32_to_cpu(sd->len); 55 + cstr.len = le16_to_cpu(sd->len); 56 56 if ((cstr.len + 57 57 sizeof(struct ext4_encrypted_symlink_data) - 1) > 58 58 max_size) {
+1 -1
fs/ext4/sysfs.c
··· 358 358 return single_open(file, ext4_seq_##name##_show, PDE_DATA(inode)); \ 359 359 } \ 360 360 \ 361 - const struct file_operations ext4_seq_##name##_fops = { \ 361 + static const struct file_operations ext4_seq_##name##_fops = { \ 362 362 .owner = THIS_MODULE, \ 363 363 .open = name##_open, \ 364 364 .read = seq_read, \
+9 -3
fs/jbd2/transaction.c
··· 1009 1009 } 1010 1010 1011 1011 /* Fast check whether buffer is already attached to the required transaction */ 1012 - static bool jbd2_write_access_granted(handle_t *handle, struct buffer_head *bh) 1012 + static bool jbd2_write_access_granted(handle_t *handle, struct buffer_head *bh, 1013 + bool undo) 1013 1014 { 1014 1015 struct journal_head *jh; 1015 1016 bool ret = false; ··· 1036 1035 /* This should be bh2jh() but that doesn't work with inline functions */ 1037 1036 jh = READ_ONCE(bh->b_private); 1038 1037 if (!jh) 1038 + goto out; 1039 + /* For undo access buffer must have data copied */ 1040 + if (undo && !jh->b_committed_data) 1039 1041 goto out; 1040 1042 if (jh->b_transaction != handle->h_transaction && 1041 1043 jh->b_next_transaction != handle->h_transaction) ··· 1077 1073 struct journal_head *jh; 1078 1074 int rc; 1079 1075 1080 - if (jbd2_write_access_granted(handle, bh)) 1076 + if (jbd2_write_access_granted(handle, bh, false)) 1081 1077 return 0; 1082 1078 1083 1079 jh = jbd2_journal_add_journal_head(bh); ··· 1214 1210 char *committed_data = NULL; 1215 1211 1216 1212 JBUFFER_TRACE(jh, "entry"); 1217 - if (jbd2_write_access_granted(handle, bh)) 1213 + if (jbd2_write_access_granted(handle, bh, true)) 1218 1214 return 0; 1219 1215 1220 1216 jh = jbd2_journal_add_journal_head(bh); ··· 2156 2152 2157 2153 if (!buffer_dirty(bh)) { 2158 2154 /* bdflush has written it. We can drop it now */ 2155 + __jbd2_journal_remove_checkpoint(jh); 2159 2156 goto zap_buffer; 2160 2157 } 2161 2158 ··· 2186 2181 /* The orphan record's transaction has 2187 2182 * committed. We can cleanse this buffer */ 2188 2183 clear_buffer_jbddirty(bh); 2184 + __jbd2_journal_remove_checkpoint(jh); 2189 2185 goto zap_buffer; 2190 2186 } 2191 2187 }