From patchwork Tue Sep 20 00:38:09 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: hawken X-Patchwork-Id: 9340835 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 8D2F2601C2 for ; Tue, 20 Sep 2016 00:47:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 71C2328E84 for ; Tue, 20 Sep 2016 00:47:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 64EF128E9B; Tue, 20 Sep 2016 00:47:05 +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=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID 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 7986328E84 for ; Tue, 20 Sep 2016 00:47:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752611AbcITAqx (ORCPT ); Mon, 19 Sep 2016 20:46:53 -0400 Received: from 204.37-191-141.fiber.lynet.no ([37.191.141.204]:42630 "EHLO mail.thehawken.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751579AbcITAqw (ORCPT ); Mon, 19 Sep 2016 20:46:52 -0400 X-Greylist: delayed 515 seconds by postgrey-1.27 at vger.kernel.org; Mon, 19 Sep 2016 20:46:51 EDT Received: from [IPv6:2a00:c440:10:1c62:12::80] (unknown [IPv6:2a00:c440:10:1c62:12::80]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.thehawken.org (Postfix) with ESMTPSA id DBFFDA40175 for ; Tue, 20 Sep 2016 02:37:57 +0200 (CEST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.99.2 at hermes Authentication-Results: mail.thehawken.org; dmarc=fail header.from=thehawken.org DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=thehawken.org; s=mail; t=1474331877; bh=s4eZD2z5lE5+faYsJTSu25WJyWCF0+uM3OpYOCwIas4=; h=To:From:Subject:Date:From; b=bf7p8//kKwGpNHPf6+nJunA8be8x9o5eJqBPSiUWGvM/gfoypvvP94iJIWUI+uHqu d9LUYpBOR1zlYSXU9bjWORy1p4rNblRKEMzO7aCRlqijiD+HnBiWGXbbAx0jwdkP99 Sw00K/GrVzxSv5tWid7i//wLstIYd5S2jzkmRZz6LOsxqTQcXc8kNECFW5dJ+fHtO1 eXl0g7/g/pBBpZCjhGurdOptfoyptK+rSCq/SkQ0r6JQdAw+qdKZqKbICTJwGEh9co hAPeEizDoKyeGRpfM4TnN0FigUQkjr1lxGjJKCuPJ3YGo13/H8Som3HbuTkXoAOPiG YmuW7/5r2kMzA== To: linux-btrfs@vger.kernel.org From: hawken Subject: super-recover crashing because it found a bad superblock Message-ID: Date: Tue, 20 Sep 2016 02:38:09 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Icedove/45.2.0 MIME-Version: 1.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 Hi! In super-recover.c, around line 96, check_super calls btrfs_super_csum_size, which then dies because the size was too big. I have solved this by reimplementing that stub inside super-recover.c with error handling rather than crashing: (Sorry for bad formatting) This allowed me to recover my superblocks I found this bug kind of ironic because a routine made to discover bad data, crashed because it encountered bad data :D - hawken --- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/super-recover.c b/super-recover.c index adb2c44..2508e06 100644 --- a/super-recover.c +++ b/super-recover.c @@ -93,7 +93,11 @@ void free_recover_superblock(struct btrfs_recover_superblock *recover) static int check_super(u64 bytenr, struct btrfs_super_block *sb) { - int csum_size = btrfs_super_csum_size(sb); + int t = btrfs_super_csum_type(sb); + if(t >= ARRAY_SIZE(btrfs_csum_sizes)) + return 0; + int csum_size = btrfs_csum_sizes[t]; + char result[csum_size]; u32 crc = ~(u32)0;