stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: David Turner <novalis@novalis.org>
To: Ben Hutchings <ben@decadent.org.uk>,
	linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: akpm@linux-foundation.org, Theodore Ts'o <tytso@mit.edu>,
	Mark Harris <mh8928@yahoo.com>
Subject: Re: [PATCH 3.2 33/77] ext4: Fix handling of extended tv_sec
Date: Thu, 24 Dec 2015 16:21:25 -0500	[thread overview]
Message-ID: <1450992085.8557.31.camel@novalis.org> (raw)
In-Reply-To: <lsq.1450971462.919604920@decadent.org.uk>

LGTM.

On Thu, 2015-12-24 at 15:37 +0000, Ben Hutchings wrote:
> 3.2.75-rc1 review patch.  If anyone has any objections, please let me
> know.
> 
> ------------------
> 
> From: David Turner <novalis@novalis.org>
> 
> commit a4dad1ae24f850410c4e60f22823cba1289b8d52 upstream.
> 
> In ext4, the bottom two bits of {a,c,m}time_extra are used to extend
> the {a,c,m}time fields, deferring the year 2038 problem to the year
> 2446.
> 
> When decoding these extended fields, for times whose bottom 32 bits
> would represent a negative number, sign extension causes the 64-bit
> extended timestamp to be negative as well, which is not what's
> intended.  This patch corrects that issue, so that the only negative
> {a,c,m}times are those between 1901 and 1970 (as per 32-bit signed
> timestamps).
> 
> Some older kernels might have written pre-1970 dates with 1,1 in the
> extra bits.  This patch treats those incorrectly-encoded dates as
> pre-1970, instead of post-2311, until kernel 4.20 is released.
> Hopefully by then e2fsck will have fixed up the bad data.
> 
> Also add a comment explaining the encoding of ext4's extra
> {a,c,m}time
> bits.
> 
> Signed-off-by: David Turner <novalis@novalis.org>
> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
> Reported-by: Mark Harris <mh8928@yahoo.com>
> Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=23732
> Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
> ---
>  fs/ext4/ext4.h | 51 ++++++++++++++++++++++++++++++++++++++++++++----
> ---
>  1 file changed, 44 insertions(+), 7 deletions(-)
> 
> --- a/fs/ext4/ext4.h
> +++ b/fs/ext4/ext4.h
> @@ -26,6 +26,7 @@
>  #include <linux/seqlock.h>
>  #include <linux/mutex.h>
>  #include <linux/timer.h>
> +#include <linux/version.h>
>  #include <linux/wait.h>
>  #include <linux/blockgroup_lock.h>
>  #include <linux/percpu_counter.h>
> @@ -698,19 +699,55 @@ struct move_extent {
>  	<= (EXT4_GOOD_OLD_INODE_SIZE +			\
>  	    (einode)->i_extra_isize))			\
>  
> +/*
> + * We use an encoding that preserves the times for extra epoch "00":
> + *
> + * extra  msb of                         adjust for signed
> + * epoch  32-bit                         32-bit tv_sec to
> + * bits   time    decoded 64-bit tv_sec  64-bit tv_sec      valid
> time range
> + * 0 0    1    -0x80000000..-0x00000001  0x000000000 1901-12
> -13..1969-12-31
> + * 0 0    0    0x000000000..0x07fffffff  0x000000000 1970-01
> -01..2038-01-19
> + * 0 1    1    0x080000000..0x0ffffffff  0x100000000 2038-01
> -19..2106-02-07
> + * 0 1    0    0x100000000..0x17fffffff  0x100000000 2106-02
> -07..2174-02-25
> + * 1 0    1    0x180000000..0x1ffffffff  0x200000000 2174-02
> -25..2242-03-16
> + * 1 0    0    0x200000000..0x27fffffff  0x200000000 2242-03
> -16..2310-04-04
> + * 1 1    1    0x280000000..0x2ffffffff  0x300000000 2310-04
> -04..2378-04-22
> + * 1 1    0    0x300000000..0x37fffffff  0x300000000 2378-04
> -22..2446-05-10
> + *
> + * Note that previous versions of the kernel on 64-bit systems would
> + * incorrectly use extra epoch bits 1,1 for dates between 1901 and
> + * 1970.  e2fsck will correct this, assuming that it is run on the
> + * affected filesystem before 2242.
> + */
> +
>  static inline __le32 ext4_encode_extra_time(struct timespec *time)
>  {
> -       return cpu_to_le32((sizeof(time->tv_sec) > 4 ?
> -			   (time->tv_sec >> 32) & EXT4_EPOCH_MASK :
> 0) |
> -                          ((time->tv_nsec << EXT4_EPOCH_BITS) &
> EXT4_NSEC_MASK));
> +	u32 extra = sizeof(time->tv_sec) > 4 ?
> +		((time->tv_sec - (s32)time->tv_sec) >> 32) &
> EXT4_EPOCH_MASK : 0;
> +	return cpu_to_le32(extra | (time->tv_nsec <<
> EXT4_EPOCH_BITS));
>  }
>  
>  static inline void ext4_decode_extra_time(struct timespec *time,
> __le32 extra)
>  {
> -       if (sizeof(time->tv_sec) > 4)
> -	       time->tv_sec |= (__u64)(le32_to_cpu(extra) &
> EXT4_EPOCH_MASK)
> -			       << 32;
> -       time->tv_nsec = (le32_to_cpu(extra) & EXT4_NSEC_MASK) >>
> EXT4_EPOCH_BITS;
> +	if (unlikely(sizeof(time->tv_sec) > 4 &&
> +			(extra & cpu_to_le32(EXT4_EPOCH_MASK)))) {
> +#if LINUX_VERSION_CODE < KERNEL_VERSION(4,20,0)
> +		/* Handle legacy encoding of pre-1970 dates with
> epoch
> +		 * bits 1,1.  We assume that by kernel version 4.20,
> +		 * everyone will have run fsck over the affected
> +		 * filesystems to correct the problem.  (This
> +		 * backwards compatibility may be removed before
> this
> +		 * time, at the discretion of the ext4 developers.)
> +		 */
> +		u64 extra_bits = le32_to_cpu(extra) &
> EXT4_EPOCH_MASK;
> +		if (extra_bits == 3 && ((time->tv_sec) & 0x80000000)
> != 0)
> +			extra_bits = 0;
> +		time->tv_sec += extra_bits << 32;
> +#else
> +		time->tv_sec += (u64)(le32_to_cpu(extra) &
> EXT4_EPOCH_MASK) << 32;
> +#endif
> +	}
> +	time->tv_nsec = (le32_to_cpu(extra) & EXT4_NSEC_MASK) >>
> EXT4_EPOCH_BITS;
>  }
>  
>  #define EXT4_INODE_SET_XTIME(xtime, inode, raw_inode)		
> 	       \
> 

  reply	other threads:[~2015-12-24 21:21 UTC|newest]

Thread overview: 84+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-12-24 15:37 [PATCH 3.2 00/77] 3.2.75-rc1 review Ben Hutchings
2015-12-24 15:37 ` [PATCH 3.2 75/77] af_unix: fix a fatal race with bit fields Ben Hutchings
2015-12-24 15:37 ` [PATCH 3.2 52/77] ipmi: move timer init to before irq is setup Ben Hutchings
2015-12-24 15:37 ` [PATCH 3.2 60/77] tcp: initialize tp->copied_seq in case of cross SYN connection Ben Hutchings
2015-12-24 15:37 ` [PATCH 3.2 12/77] net: fix __netdev_update_features return on ndo_set_features failure Ben Hutchings
2015-12-24 15:37 ` [PATCH 3.2 22/77] net: ip6mr: fix static mfc/dev leaks on table destruction Ben Hutchings
2015-12-24 15:37 ` [PATCH 3.2 57/77] mm: hugetlb: call huge_pte_alloc() only if ptep is null Ben Hutchings
2015-12-24 15:37 ` [PATCH 3.2 38/77] AHCI: Fix softreset failed issue of Port Multiplier Ben Hutchings
2015-12-24 15:37 ` [PATCH 3.2 15/77] macvlan: fix leak in macvlan_handle_frame Ben Hutchings
2015-12-24 15:37 ` [PATCH 3.2 19/77] usblp: do not set TASK_INTERRUPTIBLE before lock Ben Hutchings
2015-12-24 15:37 ` [PATCH 3.2 10/77] usb: musb: core: fix order of arguments to ulpi write callback Ben Hutchings
2015-12-24 15:37 ` [PATCH 3.2 66/77] ipv6: sctp: implement sctp_v6_destroy_sock() Ben Hutchings
2015-12-24 15:37 ` [PATCH 3.2 31/77] broadcom: fix PHY_ID_BCM5481 entry in the id table Ben Hutchings
2015-12-24 15:37 ` [PATCH 3.2 59/77] snmp: Remove duplicate OUTMCAST stat increment Ben Hutchings
2015-12-24 15:37 ` [PATCH 3.2 24/77] USB: cp210x: Remove CP2110 ID from compatibility list Ben Hutchings
2015-12-24 15:37 ` [PATCH 3.2 06/77] USB: serial: option: add support for Novatel MiFi USB620L Ben Hutchings
2015-12-24 15:37 ` [PATCH 3.2 33/77] ext4: Fix handling of extended tv_sec Ben Hutchings
2015-12-24 21:21   ` David Turner [this message]
2015-12-24 15:37 ` [PATCH 3.2 72/77] pptp: verify sockaddr_len in pptp_bind() and pptp_connect() Ben Hutchings
2015-12-24 15:37 ` [PATCH 3.2 77/77] ppp, slip: Validate VJ compression slot parameters completely Ben Hutchings
2015-12-24 15:37 ` [PATCH 3.2 32/77] ring-buffer: Update read stamp with first real commit on page Ben Hutchings
2015-12-24 15:37 ` [PATCH 3.2 13/77] FS-Cache: Add missing initialization of ret in cachefiles_write_page() Ben Hutchings
2015-12-24 15:37 ` [PATCH 3.2 36/77] nfs: if we have no valid attrs, then don't declare the attribute cache valid Ben Hutchings
2015-12-24 15:37 ` [PATCH 3.2 26/77] USB: cdc_acm: Ignore Infineon Flash Loader utility Ben Hutchings
2015-12-24 15:37 ` [PATCH 3.2 03/77] ALSA: usb-audio: add packet size quirk for the Medeli DD305 Ben Hutchings
2015-12-24 15:37 ` [PATCH 3.2 25/77] USB: cdc-acm - Add IGNORE_DEVICE quirk Ben Hutchings
2015-12-24 15:37 ` [PATCH 3.2 17/77] xhci: Workaround to get Intel xHCI reset working more reliably Ben Hutchings
2015-12-24 15:37 ` [PATCH 3.2 40/77] wan/x25: Fix use-after-free in x25_asy_open_tty() Ben Hutchings
2015-12-24 15:37 ` [PATCH 3.2 02/77] sctp: translate host order to network order when setting a hmacid Ben Hutchings
2015-12-24 15:37 ` [PATCH 3.2 07/77] USB: serial: ti_usb_3410_5052: add Abbott strip port ID to combined table as well Ben Hutchings
2015-12-24 15:37 ` [PATCH 3.2 23/77] can: sja1000: clear interrupts on start Ben Hutchings
2015-12-24 15:37 ` [PATCH 3.2 42/77] usb: Use the USB_SS_MULT() macro to decode burst multiplier for log message Ben Hutchings
2015-12-24 15:37 ` [PATCH 3.2 50/77] ALSA: rme96: Fix unexpected volume reset after rate changes Ben Hutchings
2015-12-24 15:37 ` [PATCH 3.2 27/77] unix: avoid use-after-free in ep_remove_wait_queue Ben Hutchings
2015-12-24 15:37 ` [PATCH 3.2 71/77] sh_eth: fix kernel oops in skb_put() Ben Hutchings
2015-12-24 15:37 ` [PATCH 3.2 43/77] dm btree: fix leak of bufio-backed block in btree_split_sibling error path Ben Hutchings
2015-12-24 15:37 ` [PATCH 3.2 56/77] mm, vmstat: allow WQ concurrency to discover memory reclaim doesn't make any progress Ben Hutchings
2015-12-24 15:37 ` [PATCH 3.2 47/77] sched/core: Remove false-positive warning from wake_up_process() Ben Hutchings
2015-12-24 15:37 ` [PATCH 3.2 51/77] 9p: ->evict_inode() should kick out ->i_data, not ->i_mapping Ben Hutchings
2015-12-24 15:37 ` [PATCH 3.2 45/77] locking: Add WARN_ON_ONCE lock assertion Ben Hutchings
2015-12-24 15:37 ` [PATCH 3.2 61/77] net, scm: fix PaX detected msg_controllen overflow in scm_detach_fds Ben Hutchings
2015-12-24 15:37 ` [PATCH 3.2 68/77] sctp: update the netstamp_needed counter when copying sockets Ben Hutchings
2015-12-24 15:37 ` [PATCH 3.2 01/77] fuse: break infinite loop in fuse_fill_write_pages() Ben Hutchings
2015-12-24 15:37 ` [PATCH 3.2 48/77] sched/core: Clear the root_domain cpumasks in init_rootdomain() Ben Hutchings
2015-12-24 15:37 ` [PATCH 3.2 76/77] isdn_ppp: Add checks for allocation failure in isdn_ppp_open() Ben Hutchings
2015-12-24 15:37 ` [PATCH 3.2 08/77] USB: ti_usb_3410_502: Fix ID table size Ben Hutchings
2015-12-24 15:37 ` [PATCH 3.2 11/77] ASoC: wm8962: correct addresses for HPF_C_0/1 Ben Hutchings
2015-12-24 15:37 ` [PATCH 3.2 37/77] drm/ttm: Fixed a read/write lock imbalance Ben Hutchings
2015-12-24 15:37 ` [PATCH 3.2 62/77] net: ipmr: fix static mfc/dev leaks on table destruction Ben Hutchings
2015-12-24 15:37 ` [PATCH 3.2 18/77] USB: option: add XS Stick W100-2 from 4G Systems Ben Hutchings
2015-12-24 15:37 ` [PATCH 3.2 16/77] xhci: Add XHCI_INTEL_HOST quirk Ben Hutchings
2015-12-24 15:37 ` [PATCH 3.2 28/77] fix sysvfs symlinks Ben Hutchings
2015-12-24 15:37 ` [PATCH 3.2 09/77] USB: ti_usb_3410_5052: Add Honeywell HGI80 ID Ben Hutchings
2015-12-24 15:37 ` [PATCH 3.2 69/77] ipv6: sctp: clone options to avoid use after free Ben Hutchings
2015-12-24 15:37 ` [PATCH 3.2 74/77] af_unix: Revert 'lock_interruptible' in stream receive code Ben Hutchings
2015-12-24 15:37 ` [PATCH 3.2 73/77] bluetooth: Validate socket address length in sco_sock_bind() Ben Hutchings
2015-12-24 15:37 ` [PATCH 3.2 34/77] jbd2: Fix unreclaimed pages after truncate in data=journal mode Ben Hutchings
2015-12-24 15:37 ` [PATCH 3.2 49/77] usb: xhci: fix config fail of FS hub behind a HS hub with MTT Ben Hutchings
2015-12-24 15:37 ` [PATCH 3.2 14/77] mac80211: mesh: fix call_rcu() usage Ben Hutchings
2015-12-24 15:37 ` [PATCH 3.2 35/77] RDS: fix race condition when sending a message on unbound socket Ben Hutchings
2015-12-24 15:37 ` [PATCH 3.2 30/77] vfs: Avoid softlockups with sendfile(2) Ben Hutchings
2015-12-24 15:37 ` [PATCH 3.2 53/77] dm btree: fix bufio buffer leaks in dm_btree_del() error path Ben Hutchings
2015-12-24 15:37 ` [PATCH 3.2 63/77] ipv6: distinguish frag queues by device for multicast and link-local packets Ben Hutchings
2015-12-24 15:37 ` [PATCH 3.2 64/77] dccp: remove unnecessary codes in ipv6.c Ben Hutchings
2015-12-24 15:37 ` [PATCH 3.2 54/77] vgaarb: fix signal handling in vga_get() Ben Hutchings
2015-12-24 15:37 ` [PATCH 3.2 46/77] drm: Fix an unwanted master inheritance v2 Ben Hutchings
2015-12-25 14:13   ` Thomas Hellstrom
2015-12-26  4:31     ` Ben Hutchings
2015-12-24 15:37 ` [PATCH 3.2 41/77] USB: whci-hcd: add check for dma mapping error Ben Hutchings
2015-12-24 15:37 ` [PATCH 3.2 21/77] ip6mr: call del_timer_sync() in ip6mr_free_table() Ben Hutchings
2015-12-24 15:37 ` [PATCH 3.2 39/77] sata_sil: disable trim Ben Hutchings
2015-12-24 15:37 ` [PATCH 3.2 65/77] ipv6: add complete rcu protection around np->opt Ben Hutchings
2015-12-24 15:37 ` [PATCH 3.2 70/77] net: add validation for the socket syscall protocol argument Ben Hutchings
2015-12-24 15:37 ` [PATCH 3.2 67/77] atl1c: Improve driver not to do order 4 GFP_ATOMIC allocation Ben Hutchings
2015-12-24 15:37 ` [PATCH 3.2 44/77] ipv4: igmp: Allow removing groups from a removed interface Ben Hutchings
2015-12-24 15:37 ` [PATCH 3.2 29/77] vfs: Make sendfile(2) killable even better Ben Hutchings
2015-12-24 15:37 ` [PATCH 3.2 55/77] parisc iommu: fix panic due to trying to allocate too large region Ben Hutchings
2015-12-24 15:37 ` [PATCH 3.2 20/77] mac: validate mac_partition is within sector Ben Hutchings
2015-12-24 15:37 ` [PATCH 3.2 58/77] sh64: fix __NR_fgetxattr Ben Hutchings
2015-12-24 15:37 ` [PATCH 3.2 05/77] ALSA: usb-audio: work around CH345 input SysEx corruption Ben Hutchings
2015-12-24 15:37 ` [PATCH 3.2 04/77] ALSA: usb-audio: prevent CH345 multiport output " Ben Hutchings
2015-12-24 16:40 ` [PATCH 3.2 00/77] 3.2.75-rc1 review Ben Hutchings
2015-12-24 22:20 ` Guenter Roeck
2015-12-24 22:31   ` Ben Hutchings

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1450992085.8557.31.camel@novalis.org \
    --to=novalis@novalis.org \
    --cc=akpm@linux-foundation.org \
    --cc=ben@decadent.org.uk \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mh8928@yahoo.com \
    --cc=stable@vger.kernel.org \
    --cc=tytso@mit.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).