Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp2173427imm; Mon, 28 May 2018 03:12:30 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqPsxjXTsVjJjDdwThHqMNsU+K6x7GygpECfe+mumKtoZzygGvkqUjK0qjWiQwNXJjY/Z4v X-Received: by 2002:aa7:80c6:: with SMTP id a6-v6mr12801663pfn.120.1527502350513; Mon, 28 May 2018 03:12:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527502350; cv=none; d=google.com; s=arc-20160816; b=IcIMASxm7+3axU7r5v1p/F7gUsXpsAm0oSA7EXeG3mppQRpLr/Yt0Iw6RXDt+dreMB S4qi2RiYProO59kEtGyh7cUtki18c7Dm+ccSPrA4CZ3IEuU1EUQzPnw5vW57YCdcHFdR GIcJ34udWz9qMKUBT2cIosz+CnFWWbVNV7mtS/0pSWNoesX2OAFJuTU2RKMlU5a9Ax8S ADKpifIoNGxclXb6dgMG39A+zKDynxjk2kv7H2Dt4gbuAPl3u+gfeftmGRdL6IxA/KXP LFpRdGaFtPE6ccvxMSRZ2ja95U0xtUajlLn+5rZWHqPHzwWx1GZqK1mXJcwZoiAx3vpV 2tEA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=Wz6FMub6dv22ImswbZP/OM0duakHkXkr/IAvKkt7CpM=; b=naakCJxPGlxVUDvHPmbIZWNBesqy6A7owRzLHk90+Pug+RKjcNvZnlz4iLHKEvJynV ceAADnmvfomQGerlAHCvlntxiajnCN1DiUi6mh6RvLrBMTjzOnjT4ZaBk3cbvGv9Pn+S PR0DVHFn5FSrx/LMJBvT+UyQ1UKz6wyh2xtIe3kwf/dh0j5PSb8WBbbdrDCuKK+KB1D9 RRlZaztU6vWk3pkuAjdQNNLPQs0BhAf1N41f4stuJVX0XKvtfelZbWoACDs1gKy3J0/f /2s5O+38cqYyW1d5/55yCmuWvpmcTTI1SSB7QYQAXbWOvvybYFPeRJYxO5xXCZJCPNT9 aL2g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Il9ebeZ9; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l9-v6si1907507pgr.287.2018.05.28.03.12.15; Mon, 28 May 2018 03:12:30 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Il9ebeZ9; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S936543AbeE1KLA (ORCPT + 99 others); Mon, 28 May 2018 06:11:00 -0400 Received: from mail.kernel.org ([198.145.29.99]:59106 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S964948AbeE1KKy (ORCPT ); Mon, 28 May 2018 06:10:54 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 59A3E208AD; Mon, 28 May 2018 10:10:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1527502253; bh=i15udb9TZ0sg+gbfAqwiFJVlOhE/igpGZLX+YerZYFc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Il9ebeZ9US53NyJUa/o84kR9KbbCbDU2dILI8+gveuazgmMyTyuUMNx2a3wDfkF6E Obg7vUL04BwE3E6ywLlijy7OlfpNIenWbECNoR0zm6Lxfh2UVRkp477vM6QBdzQN4t JYsI0wP/dYX1bQ1WK93SzrkCEmR74hdAjC22gIlQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Nikolay Borisov , Liu Bo , David Sterba , Sasha Levin Subject: [PATCH 3.18 119/185] Btrfs: fix NULL pointer dereference in log_dir_items Date: Mon, 28 May 2018 12:02:40 +0200 Message-Id: <20180528100102.341672187@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180528100050.700971285@linuxfoundation.org> References: <20180528100050.700971285@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Liu Bo [ Upstream commit 80c0b4210a963e31529e15bf90519708ec947596 ] 0, 1 and <0 can be returned by btrfs_next_leaf(), and when <0 is returned, path->nodes[0] could be NULL, log_dir_items lacks such a check for <0 and we may run into a null pointer dereference panic. Fixes: e02119d5a7b4 ("Btrfs: Add a write ahead tree log to optimize synchronous operations") Reviewed-by: Nikolay Borisov Signed-off-by: Liu Bo Signed-off-by: David Sterba Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- fs/btrfs/tree-log.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) --- a/fs/btrfs/tree-log.c +++ b/fs/btrfs/tree-log.c @@ -3085,8 +3085,11 @@ static noinline int log_dir_items(struct * from this directory and from this transaction */ ret = btrfs_next_leaf(root, path); - if (ret == 1) { - last_offset = (u64)-1; + if (ret) { + if (ret == 1) + last_offset = (u64)-1; + else + err = ret; goto done; } btrfs_item_key_to_cpu(path->nodes[0], &tmp, path->slots[0]);