Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3420230pxf; Mon, 22 Mar 2021 06:09:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJydV4lWaQ4sCPUmM/3uBaGHCqJAdbeAik2yjX1PscwhbR06ROHVVm1sVl0rkPRivxFfUq+M X-Received: by 2002:a17:906:70d:: with SMTP id y13mr18830622ejb.170.1616418596717; Mon, 22 Mar 2021 06:09:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616418596; cv=none; d=google.com; s=arc-20160816; b=Q5kpdIu1aoWHStWku5vJs74y0SSQ343KoCjXGlscb8+tS42T3/W4aKOChx4n5Qcb9L /rPcQF9WYMvOH9k59oSyQB3BIDAb1uEffrlyIkY1d7m2m9rVFzII+PTmQUqUGCZAbY93 cONY7OfJl/biDlTeojjGtDW7CzAwlIShsMCeweAMKtWB8R4lnm0bL5NdZnZ8JOLd0cER 9nPHEl1dVN2ga+yRbOwfyB3CThELXX+/ngS8aKUf7m4uvWfD5eL/yu98XDEDj6GewgOy qZHmH9UM8J0CNOyCDs+8wBUgs7S2UR4MU12KAp1DbjyvzoPcUbERou0rRJZxwnWwO07w pbig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=KPxoa8ctVbHCEa5cYT+V2/iytV9rTEWhuWFEJRbtjDo=; b=J+GsB6/CTpSOYt9N6gFKSE+MHOBHLkxOAVOsm/wy16krVxglQeCPaOWrp/GK3pyzVe 4rnwHi1fNFZQoeiewcopiCfNRYkCWmJzJW/JZ3rqOSamaK2JN1A7H/Y5CC5aL5H7idqX VV1w3Yx8P42SZR8s48o9yqA8r+ib8gtpXdI/m19VK1qbotlksIu90ZDziY21RhbL762J 65a9iBACZGzkggdDFKo/5AUeZBHn/46nCXdswbWoyOtSy9cTks0zTJE2GiZfkqZs3FfW lkKv3XKMnQIaY4VtvQyLwsuwfGNuvhcis+uCIzRJeyY9/mCfAMIADPib1kZiXOYoAcfd /HvA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=xKxE5eNp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r15si11329973edq.306.2021.03.22.06.09.33; Mon, 22 Mar 2021 06:09:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=xKxE5eNp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232943AbhCVNGw (ORCPT + 99 others); Mon, 22 Mar 2021 09:06:52 -0400 Received: from mail.kernel.org ([198.145.29.99]:45654 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232858AbhCVMw4 (ORCPT ); Mon, 22 Mar 2021 08:52:56 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 2796D619E2; Mon, 22 Mar 2021 12:46:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1616417207; bh=/MmVq5Ogx833lFW8IvgYNzD3k9TDCJnlbClvnqfVyXA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xKxE5eNpZFOgwntZEWeAa9vK2ajhceYhAlOPgtQ87B7fZVtWM0XUQe7QEZyw3HD9P eXAnxUw1NTCp0PvwntI82iCC/UZiUP8fCZUPIeN2a2w763c/wPB3eOx2+MzHZK5bQH 1EcLO+hkUt6uk5bBqoqkQmiUWy9dm3Hc2j9f0Aq8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Lukas Czerner , Jan Kara , Theodore Tso Subject: [PATCH 4.9 02/25] ext4: dont allow overlapping system zones Date: Mon, 22 Mar 2021 13:28:52 +0100 Message-Id: <20210322121920.478208447@linuxfoundation.org> X-Mailer: git-send-email 2.31.0 In-Reply-To: <20210322121920.399826335@linuxfoundation.org> References: <20210322121920.399826335@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jan Kara commit bf9a379d0980e7413d94cb18dac73db2bfc5f470 upstream. 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 Link: https://lore.kernel.org/r/20200728130437.7804-3-jack@suse.cz Signed-off-by: Theodore Ts'o Signed-off-by: Greg Kroah-Hartman --- fs/ext4/block_validity.c | 34 ++++++++++++---------------------- 1 file changed, 12 insertions(+), 22 deletions(-) --- a/fs/ext4/block_validity.c +++ b/fs/ext4/block_validity.c @@ -57,7 +57,7 @@ static int add_system_zone(struct ext4_s 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 = &sbi->system_blks.rb_node, *node; struct rb_node *parent = NULL, *new_node = NULL; @@ -68,30 +68,20 @@ static int add_system_zone(struct ext4_s 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; + 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, &sbi->system_blks); - } + rb_link_node(new_node, parent, n); + rb_insert_color(new_node, &sbi->system_blks); /* Can we merge to the left? */ node = rb_prev(new_node);