From patchwork Thu Oct 17 09:27:53 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eryu Guan X-Patchwork-Id: 284144 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 99D372C0092 for ; Thu, 17 Oct 2013 20:29:05 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753453Ab3JQJ3E (ORCPT ); Thu, 17 Oct 2013 05:29:04 -0400 Received: from mail-pb0-f54.google.com ([209.85.160.54]:49221 "EHLO mail-pb0-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753118Ab3JQJ3D (ORCPT ); Thu, 17 Oct 2013 05:29:03 -0400 Received: by mail-pb0-f54.google.com with SMTP id ro12so2057142pbb.13 for ; Thu, 17 Oct 2013 02:28:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=7Uzdh4pH2Pyudm27QcHjZNpnNVi+NMzg+cGoVKB9Z1Q=; b=LC4dGHHYmDuoK3dRigw3VZnfggeTqWZwXCyDLC3IkjxwezyWA8tz3eVT4nvqZT+5Oo jEz3ZUVlWBsVZmv7wRtdZSwGXX5ktQwcC8aJkI3PqBc+bluLWGJR+8y/UR+jLUpcU9VS htEb1bshDRIK+ja5usDw5tbvUd/tGM9OJxU9lCwtyiEjtsMMdcVLeryI1fldTF/db/je Ymvlpx5u1F7vK4f6N+Fi7dghfpyf6m/jM53jGm5mCepVN/wWQkAXpUjRmksw93a51RdD jS+9u2CddPeIaMaQ4Ex8EHAS1GowDE7cc/by3YJxswth+gICCzlY9QQtpS48y9NBZsGP qHZw== X-Received: by 10.67.14.67 with SMTP id fe3mr8214755pad.134.1382002139829; Thu, 17 Oct 2013 02:28:59 -0700 (PDT) Received: from dhcp-13-216.nay.redhat.com ([203.114.244.88]) by mx.google.com with ESMTPSA id xs1sm113019322pac.7.1969.12.31.16.00.00 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Thu, 17 Oct 2013 02:28:59 -0700 (PDT) From: Eryu Guan To: linux-ext4@vger.kernel.org Cc: Eryu Guan , "Theodore Ts'o" Subject: [PATCH] ext4: don't cache out of order extents Date: Thu, 17 Oct 2013 17:27:53 +0800 Message-Id: <1382002073-27862-1-git-send-email-guaneryu@gmail.com> X-Mailer: git-send-email 1.8.3.1 Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org A corrupted ext4 may have out of order leaf extents, i.e. extent: lblk 0--1023, len 1024, pblk 9217, flags: LEAF UNINIT extent: lblk 1000--2047, len 1024, pblk 10241, flags: LEAF UNINIT ^^^^ overlap with previous extent Reading such extent could hit BUG_ON() in ext4_es_cache_extent(). BUG_ON(end < lblk); The problem is that __read_extent_tree_block() tries to cache holes as well but assumes 'lblk' is greater than 'prev' and passes underflowed length to ext4_es_cache_extent(). I hit this when fuzz testing ext4, and am able to reproduce it by modifying the on-disk extent by hand. Ran xfstests on patched ext4 and no regression. Cc: "Theodore Ts'o" Signed-off-by: Eryu Guan --- fs/ext4/extents.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c index 54d52af..c9ebcb9 100644 --- a/fs/ext4/extents.c +++ b/fs/ext4/extents.c @@ -503,7 +503,7 @@ __read_extent_tree_block(const char *function, unsigned int line, ext4_lblk_t lblk = le32_to_cpu(ex->ee_block); int len = ext4_ext_get_actual_len(ex); - if (prev && (prev != lblk)) + if (prev && (prev < lblk)) ext4_es_cache_extent(inode, prev, lblk - prev, ~0, EXTENT_STATUS_HOLE);