From patchwork Tue Apr 6 13:55:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nikolay Borisov X-Patchwork-Id: 12185339 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 00BB1C433ED for ; Tue, 6 Apr 2021 13:55:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B79C861380 for ; Tue, 6 Apr 2021 13:55:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344778AbhDFNzO (ORCPT ); Tue, 6 Apr 2021 09:55:14 -0400 Received: from mx2.suse.de ([195.135.220.15]:57144 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244310AbhDFNzN (ORCPT ); Tue, 6 Apr 2021 09:55:13 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1617717304; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=VfZ5EUJ2C820A7VzEpQevLX6CSNWgc/P+MmuishEowc=; b=SpH71tvbFCNjWlt4IQMC/ja/78wZs/zD/5W7UULx8Na7kGqu/puWu1iUyGuvWSMjn977+q HU7VgUdwBa9c4cnoJyFoehnte5oU4AUZ99LRzJVHF7zBKrucC0ubWdlbp+Ve8cmYTu+Rd/ 9FfXRz2+VV/Ys9iPBDr9dWmEfWmxc/E= Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id AD724B1AE; Tue, 6 Apr 2021 13:55:04 +0000 (UTC) From: Nikolay Borisov To: linux-btrfs@vger.kernel.org Cc: Nikolay Borisov Subject: [PATCH] btrfs-progs: Fix null pointer deref in balance_level Date: Tue, 6 Apr 2021 16:55:03 +0300 Message-Id: <20210406135503.164590-1-nborisov@suse.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org In case the right buffer is emptied it's first set to null and subsequently it's dereferenced to get its size to pass to root_sub_used. This naturally leads to a null pointer dereference. The correct thing to do is to pass the stashed right->len in "blocksize". Fixes #296 Signed-off-by: Nikolay Borisov Reviewed-by: Josef Bacik --- kernel-shared/ctree.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel-shared/ctree.c b/kernel-shared/ctree.c index 4cc3aebc1412..3a82286cc914 100644 --- a/kernel-shared/ctree.c +++ b/kernel-shared/ctree.c @@ -927,7 +927,7 @@ static int balance_level(struct btrfs_trans_handle *trans, if (wret) ret = wret; - root_sub_used(root, right->len); + root_sub_used(root, blocksize); wret = btrfs_free_extent(trans, root, bytenr, blocksize, 0, root->root_key.objectid,