From patchwork Tue Jun 24 07:30:21 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Satoru Takeuchi X-Patchwork-Id: 4406611 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id BE339BEEAA for ; Tue, 24 Jun 2014 07:32:40 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id D5113202F8 for ; Tue, 24 Jun 2014 07:32:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D19DD2020A for ; Tue, 24 Jun 2014 07:32:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751859AbaFXHce (ORCPT ); Tue, 24 Jun 2014 03:32:34 -0400 Received: from fgwmail2.fujitsu.co.jp ([164.71.1.135]:55706 "EHLO fgwmail2.fujitsu.co.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751676AbaFXHcd (ORCPT ); Tue, 24 Jun 2014 03:32:33 -0400 Received: from kw-mxoi2.gw.nic.fujitsu.com (unknown [10.0.237.143]) by fgwmail2.fujitsu.co.jp (Postfix) with ESMTP id E85D93EE0C8 for ; Tue, 24 Jun 2014 16:32:31 +0900 (JST) Received: from s1.gw.fujitsu.co.jp (s1.gw.nic.fujitsu.com [10.0.50.91]) by kw-mxoi2.gw.nic.fujitsu.com (Postfix) with ESMTP id 076C1AC015A for ; Tue, 24 Jun 2014 16:32:31 +0900 (JST) Received: from g01jpfmpwkw01.exch.g01.fujitsu.local (g01jpfmpwkw01.exch.g01.fujitsu.local [10.0.193.38]) by s1.gw.fujitsu.co.jp (Postfix) with ESMTP id B4EB91DB8048 for ; Tue, 24 Jun 2014 16:32:30 +0900 (JST) Received: from g01jpexchkw33.g01.fujitsu.local (unknown [10.0.193.4]) by g01jpfmpwkw01.exch.g01.fujitsu.local (Postfix) with ESMTP id 439F3692690; Tue, 24 Jun 2014 16:32:29 +0900 (JST) X-SecurityPolicyCheck: OK by SHieldMailChecker v2.0.1 X-SHieldMailCheckerPolicyVersion: FJ-ISEC-20120718-4 Message-ID: <53A9290D.6090202@jp.fujitsu.com> Date: Tue, 24 Jun 2014 16:30:21 +0900 From: Satoru Takeuchi User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:24.0) Gecko/20100101 Thunderbird/24.3.0 MIME-Version: 1.0 To: CC: Adam Buchbinder , Subject: [PATCH] Avoid double-free of fs_devices->list. References: <1402703036-2447-1-git-send-email-abuchbinder@google.com> <53A11E62.6070308@jp.fujitsu.com> In-Reply-To: <53A11E62.6070308@jp.fujitsu.com> X-SecurityPolicyCheck-GC: OK by FENCE-Mail Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP I found the following patch is insufficient. =============================================================================== commit 6e6b32ddf58db54f714d0f263c2589f4859e8b5e Author: Adam Buchbinder Date: Fri Jun 13 16:43:56 2014 -0700 btrfs-progs: Fix a use-after-free in the volumes code. =============================================================================== "btrfs filesystem show " with this patch causes segmentation fault if "" is a not-mounted Btrfs filesystem. =============================================================================== # ./btrfs filesystem show /dev/sdd1 Label: none uuid: Total devices 1 FS bytes used 112.00KiB devid 1 size 59.12GiB used 2.04GiB path /dev/sdd1 Segmentation fault (core dumped) =============================================================================== It's due to double-free of fs_devices->list as follows. =============================================================================== cmd_show -> list_del(&fs_devices->list) # 1st one. -> btrfs_close_devices(fs_devices) -> list_del(&fs_devices->list) # <- 2nd one introduced at 6e6b32dd. Double-free happens here. =============================================================================== First list_del() can safely be removed because fs_devices->list will be deleted by second one, soon. Signed-off-by: Satoru Takeuchi Cc: Adam Buchbinder --- cmds-filesystem.c | 1 - 1 file changed, 1 deletion(-) diff --git a/cmds-filesystem.c b/cmds-filesystem.c index b1ba508..14cb6e0 100644 --- a/cmds-filesystem.c +++ b/cmds-filesystem.c @@ -716,7 +716,6 @@ devs_only: while (!list_empty(all_uuids)) { fs_devices = list_entry(all_uuids->next, struct btrfs_fs_devices, list); - list_del(&fs_devices->list); btrfs_close_devices(fs_devices); } out: