From patchwork Mon Jul 30 06:17:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 10548463 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AF32F139A for ; Mon, 30 Jul 2018 06:17:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A14A929762 for ; Mon, 30 Jul 2018 06:17:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 95B3229772; Mon, 30 Jul 2018 06:17:31 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3C3C029762 for ; Mon, 30 Jul 2018 06:17:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726550AbeG3Hux (ORCPT ); Mon, 30 Jul 2018 03:50:53 -0400 Received: from mx2.suse.de ([195.135.220.15]:32896 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726395AbeG3Hux (ORCPT ); Mon, 30 Jul 2018 03:50:53 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id B7768AE1F for ; Mon, 30 Jul 2018 06:17:27 +0000 (UTC) From: Qu Wenruo To: linux-btrfs@vger.kernel.org Subject: [PATCH 0/1] btrfs: Tree lock return value enhancement to avoid deadlock on crafted image Date: Mon, 30 Jul 2018 14:17:22 +0800 Message-Id: <20180730061723.13290-1-wqu@suse.com> X-Mailer: git-send-email 2.18.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The patch along with all submitted patches for fuzzed image can be found at the following repo: https://github.com/adam900710/linux/tree/tree_checker_enhance Although fuzzed images are not really possible to happen in real world, it's still a pretty possible Deny of Service to attack the kernel, so we still need to address such problems. Instead of previous failed attempt to use cached eb to determine if we're allocating new tree blocks on already used tree block, this time we allow btrfs_tree_lock() to return error number to inform callers there is something wrong so we can exit a little more gracefully. This branch should address the 2nd wave of fuzzed images reported by Xu Wen. Please note, since extent tree corruption is the worst scenario, we still keep kernel to WARN() on such problem. But at least for that fuzzed image we can switched to RO other than deadlock the kernel. Qu Wenruo (1): btrfs: locking: Allow btrfs_tree_lock() to return error to avoid deadlock fs/btrfs/ctree.c | 57 +++++++++++++++++++++++++++++++------- fs/btrfs/extent-tree.c | 28 +++++++++++++++---- fs/btrfs/extent_io.c | 8 ++++-- fs/btrfs/free-space-tree.c | 4 ++- fs/btrfs/locking.c | 12 ++++++-- fs/btrfs/locking.h | 2 +- fs/btrfs/qgroup.c | 4 ++- fs/btrfs/relocation.c | 13 +++++++-- fs/btrfs/tree-log.c | 14 ++++++++-- 9 files changed, 114 insertions(+), 28 deletions(-)