From patchwork Mon Apr 15 01:30:32 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierre Bourdon X-Patchwork-Id: 1085426 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="sIrwCQN3"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 44j9th0Z4pz9s47 for ; Mon, 15 Apr 2019 11:30:51 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id B0DB7C21DFB; Mon, 15 Apr 2019 01:30:49 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=FREEMAIL_FROM, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id E4D4FC21D83; Mon, 15 Apr 2019 01:30:46 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 1CB68C21D83; Mon, 15 Apr 2019 01:30:46 +0000 (UTC) Received: from mail-ed1-f68.google.com (mail-ed1-f68.google.com [209.85.208.68]) by lists.denx.de (Postfix) with ESMTPS id B5C6DC21C4A for ; Mon, 15 Apr 2019 01:30:45 +0000 (UTC) Received: by mail-ed1-f68.google.com with SMTP id j20so2997190edq.10 for ; Sun, 14 Apr 2019 18:30:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=wMHB346367KPr4261LXermhpFyDinAauca7Dij9epDM=; b=sIrwCQN3JUN1sZFCJimSOpEtFE4lQ9Wb1/f33iYF6lN2Br5M8fdAlhuPIxbojCBQwm pmjqf1pH0I7Zfd00BNpWizsScz+gZaGK3goQ+Exgo2VM+9sJvxq8cO22IHSbWpJ57lGj 4or9DtDBilMhgYiGa6WMh/f4sSFmHZU9ZiQ10bMjVBP2smgxpHiYNUh7JqbKTzgpKJ7H 6K7+k5YL0sQeKi7ZGfLjBQy9bPn5Ad4P8rhaiC0jjf+7A9Bpmr01OaM+37phAbWcjlwN 2osdkSaMbSpQQHLOLjAkZ/AwPdl79qJxq1rEpqdIp3d/3MlP12QbCZtTnHW1G7Tj/E4b wkhA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=wMHB346367KPr4261LXermhpFyDinAauca7Dij9epDM=; b=jA3K6EZs/g2Ff18JIRNVB8wraX3ARx8w3Aah+fMqwQT3GANku+5H9a7Y+js6ok2sO/ yPzT6vWdmv7YHZUSoteTcbHeuLtTJJvQ1oHh+s8/l1LlhNw/F7t30Apf3BgqzODbE6rq AMDPWKhimGZovkH3qGXx4smw8sAAE+NDh176kCStCQCtLXRtqTNLquzZ6ND508T8Cunl ip8xyfBXl7jvLWpUPQ7XhivXq389harZNuBOSO2G0rPDqxZr1h+DeKIS003TWiK/QBn+ lIIt4GxkVP6yo1oCAU3SC0Cz/0yMPkCgKSbFUnwJyk022QJQ/grToKLKvWPE8rpoKBPq ub9A== X-Gm-Message-State: APjAAAVECZSK27LS3tPohnLsMj2Z70X6YOAYWdIDyYcWdxbxGoGQdzaO GjDMGTP8zBCzxKJvevj7mMlYxoCt80E= X-Google-Smtp-Source: APXvYqwCf0Qk3SkBzyyyAav3TjAnJEAh5BtRh2MCOoa3Ej5XIXJBwyo/VGC1mEvKIieNNdavPK5hcQ== X-Received: by 2002:aa7:d049:: with SMTP id n9mr19704858edo.177.1555291844968; Sun, 14 Apr 2019 18:30:44 -0700 (PDT) Received: from lowell.delroth.net ([2a02:168:6426::bb2]) by smtp.gmail.com with ESMTPSA id h13sm4049016ejs.3.2019.04.14.18.30.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 14 Apr 2019 18:30:44 -0700 (PDT) From: Pierre Bourdon To: u-boot@lists.denx.de Date: Mon, 15 Apr 2019 03:30:32 +0200 Message-Id: <20190415013032.17983-1-delroth@gmail.com> X-Mailer: git-send-email 2.19.2 MIME-Version: 1.0 Subject: [U-Boot] [PATCH] fs: btrfs: fix btrfs_search_tree invalid results X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" btrfs_search_tree should return the first item in the tree that is greater or equal to the searched item. The search algorithm did not properly handle the edge case where the searched item is higher than the last item of the node but lower than the first item of the next node. Instead of properly returning the first item of the next node, it was returning an invalid path pointer (pointing to a non-existent item after the last item of the node + 1). This fixes two issues in the btrfs driver: - Looking for a ROOT_ITEM could fail if it was the first item of its leaf node. - Iterating through DIR_INDEX entries (for readdir) could fail if the first DIR_INDEX entry was the first item of a leaf node. Signed-off-by: Pierre Bourdon Cc: Marek Behun --- fs/btrfs/ctree.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c index d248d79932..55246ea0fc 100644 --- a/fs/btrfs/ctree.c +++ b/fs/btrfs/ctree.c @@ -187,8 +187,13 @@ int btrfs_search_tree(const struct btrfs_root *root, struct btrfs_key *key, if (lvl) logical = buf->node.ptrs[slot].blockptr; - else + else { + /* cur leaf max < searched value < next leaf min */ + if (slot >= buf->header.nritems) + if (btrfs_next_slot(p) < 0) + goto err; break; + } } return 0;