Received: by 2002:a25:ca44:0:0:0:0:0 with SMTP id a65csp973788ybg; Mon, 27 Jul 2020 04:47:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyOp/zFlZSJbMde5na7XriUNASN0jKwsABHtVgOZpkiV4fxOmFOFddBzUgYzNfkxwhn9rSo X-Received: by 2002:a50:eac5:: with SMTP id u5mr21422638edp.6.1595850468366; Mon, 27 Jul 2020 04:47:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595850468; cv=none; d=google.com; s=arc-20160816; b=rxlgs7skbQlfcwHtm9fuQnI/lORfksOhR0TduAY/x+QaKT+sKivxKLEm3Eg3ZiI5s7 AoQFmnaLZ5ZhLIR9YOco+hyMhgf1e6V6gk9z3K8Rhx8mM2JODXvZONYMc+Jis3L4TwOk 8u2SUvT/K+yyrwrNldJgZZCUXHxb444dneq7976843j7l5xjHDEKRX1/+mTFASHzwZYH QKfGEGKpGpJkx0Rz0kR8M7pIKTPJkV5WA3VClHDivGv/2tuuk0qvuZptvGrMg2rmrI0R a7jkXly5737ExbANR14iz0PzGsIut55gsHrBrUmkgxDjZB1oeoZ3+HQN+3WtrC7UxFdt y7pw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=il7VTSCnbssHCtO5DQ1WhlwAeqTlfSGJ6OjkWLkwlM0=; b=woi3SsppnT+AKeYeodES2yBh9CGpHb9jb4UebVG/dvMDgIqS+UB0DDYro2bn0KGnZM 82Vvv2PxlnFR0W9TBfaD3ZjScaa5BrhXr34TZaukoRyXD8PAc1xAsPROVprUv+roEkNE okMGvpeF57hCKzehNssJGRaXlPzqBgJiXJASYszuCoTMInYD1u0McUK6nnbCfgLQAhXx PjEY/lr5JwTFxgZ3tEG8BtrV+XvSsjW+KHU5VX4qdC5rrLoMs62e6G2Je2MVnktTCOq5 uJkCOw5yE+Zja+YEo9yd9RU9ps/+Y5rH6e7Kynba6K7e5/J5bhBI13EqQdZhjDKgO3Kx 9dQg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h11si5298322eji.666.2020.07.27.04.47.24; Mon, 27 Jul 2020 04:47:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728057AbgG0Loc (ORCPT + 99 others); Mon, 27 Jul 2020 07:44:32 -0400 Received: from mx2.suse.de ([195.135.220.15]:45912 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728000AbgG0Loc (ORCPT ); Mon, 27 Jul 2020 07:44:32 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id C1D88B690; Mon, 27 Jul 2020 11:44:40 +0000 (UTC) Received: by quack2.suse.cz (Postfix, from userid 1000) id 5142E1E12C7; Mon, 27 Jul 2020 13:44:30 +0200 (CEST) From: Jan Kara To: Ted Tso Cc: , Lukas Czerner , Jan Kara Subject: [PATCH 2/6] ext4: Don't allow overlapping system zones Date: Mon, 27 Jul 2020 13:44:25 +0200 Message-Id: <20200727114429.1478-3-jack@suse.cz> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20200727114429.1478-1-jack@suse.cz> References: <20200727114429.1478-1-jack@suse.cz> Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org Currently, add_system_zone() just silently merges two added system zones that overlap. However the overlap should not happen and it generally suggests that some unrelated metadata overlap which indicates the fs is corrupted. We should have caught such problems earlier (e.g. in ext4_check_descriptors()) but add this check as another line of defense. In later patch we also use this for stricter checking of journal inode extent tree. Reviewed-by: Lukas Czerner Signed-off-by: Jan Kara --- fs/ext4/block_validity.c | 36 +++++++++++++----------------------- 1 file changed, 13 insertions(+), 23 deletions(-) diff --git a/fs/ext4/block_validity.c b/fs/ext4/block_validity.c index 16e9b2fda03a..b394a50ebbe3 100644 --- a/fs/ext4/block_validity.c +++ b/fs/ext4/block_validity.c @@ -68,7 +68,7 @@ static int add_system_zone(struct ext4_system_blocks *system_blks, ext4_fsblk_t start_blk, unsigned int count) { - struct ext4_system_zone *new_entry = NULL, *entry; + struct ext4_system_zone *new_entry, *entry; struct rb_node **n = &system_blks->root.rb_node, *node; struct rb_node *parent = NULL, *new_node = NULL; @@ -79,30 +79,20 @@ static int add_system_zone(struct ext4_system_blocks *system_blks, n = &(*n)->rb_left; else if (start_blk >= (entry->start_blk + entry->count)) n = &(*n)->rb_right; - else { - if (start_blk + count > (entry->start_blk + - entry->count)) - entry->count = (start_blk + count - - entry->start_blk); - new_node = *n; - new_entry = rb_entry(new_node, struct ext4_system_zone, - node); - break; - } + else /* Unexpected overlap of system zones. */ + return -EFSCORRUPTED; } - if (!new_entry) { - new_entry = kmem_cache_alloc(ext4_system_zone_cachep, - GFP_KERNEL); - if (!new_entry) - return -ENOMEM; - new_entry->start_blk = start_blk; - new_entry->count = count; - new_node = &new_entry->node; - - rb_link_node(new_node, parent, n); - rb_insert_color(new_node, &system_blks->root); - } + new_entry = kmem_cache_alloc(ext4_system_zone_cachep, + GFP_KERNEL); + if (!new_entry) + return -ENOMEM; + new_entry->start_blk = start_blk; + new_entry->count = count; + new_node = &new_entry->node; + + rb_link_node(new_node, parent, n); + rb_insert_color(new_node, &system_blks->root); /* Can we merge to the left? */ node = rb_prev(new_node); -- 2.16.4