From patchwork Fri Oct 2 15:49:05 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Sterba X-Patchwork-Id: 7317371 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 39DBA9F1B9 for ; Fri, 2 Oct 2015 15:50:18 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 7145420862 for ; Fri, 2 Oct 2015 15:50:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 44DC22085F for ; Fri, 2 Oct 2015 15:50:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753012AbbJBPuJ (ORCPT ); Fri, 2 Oct 2015 11:50:09 -0400 Received: from mx2.suse.de ([195.135.220.15]:52590 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752827AbbJBPuI (ORCPT ); Fri, 2 Oct 2015 11:50:08 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 9A635ACB8 for ; Fri, 2 Oct 2015 15:50:06 +0000 (UTC) Received: by ds.suse.cz (Postfix, from userid 10065) id 9191BDAB51; Fri, 2 Oct 2015 17:49:06 +0200 (CEST) From: David Sterba To: linux-btrfs@vger.kernel.org Cc: David Sterba Subject: [PATCH] btrfs-progs: fix double free during scanning Date: Fri, 2 Oct 2015 17:49:05 +0200 Message-Id: <1443800945-27882-1-git-send-email-dsterba@suse.com> X-Mailer: git-send-email 2.1.3 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=unavailable 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 If there are different devices mounted to the same directory we can run into double free issue in the scanning code and this can lead to a crash. The dev_info_arg buffer allocation get_fs_info might be skipped, eg. if the FS_INFO ioctl fails due to EPERM in older kernels. Reset the pointer before each loop starts. Signed-off-by: David Sterba --- cmds-filesystem.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cmds-filesystem.c b/cmds-filesystem.c index b4576ed30360..366373473c56 100644 --- a/cmds-filesystem.c +++ b/cmds-filesystem.c @@ -485,6 +485,7 @@ static int btrfs_scan_kernel(void *search, unsigned unit_mode) if (search && !match_search_item_kernel(fs_info_arg.fsid, mnt->mnt_dir, label, search)) { kfree(dev_info_arg); + dev_info_arg = NULL; continue; } @@ -500,6 +501,7 @@ static int btrfs_scan_kernel(void *search, unsigned unit_mode) if (fd != -1) close(fd); kfree(dev_info_arg); + dev_info_arg = NULL; } out: