Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp1596915imm; Sat, 2 Jun 2018 04:44:35 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKBHeRQVziMGQrHYSto2BJOUsNPgkGrFAsRjJpLafRpNoQAwkRBFMXU+JCEu/jm4ecd6hXv X-Received: by 2002:a62:ac14:: with SMTP id v20-v6mr5253820pfe.126.1527939875335; Sat, 02 Jun 2018 04:44:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527939875; cv=none; d=google.com; s=arc-20160816; b=ptXmvzs72Jc/2izeOT3d/EtcnbHR+naz88HlAUe6u8sfECFfZJ9kA4p8AvP5wwLfDH 2+i3MwbGu8vZbm7MeoUrlZBauesIPU6ChEyH5LcIgcDmeBccJuYBf0Urq11jwxIb62W3 xK5ke8lwNgXVl6L1dWhXqDNcwQqSDLZpVfm8s9dFCLvnTUeG3RZjH6BKM+DsL86irrqb tc7HQ/ek6ViuxgsFNeMtGaJk5CC9thwy+nFtJqCggmTZ8mZFr6Y8t9T6OM23mbF156Xr +C0OHVSZCG3WZmlEGIWUOdAkB91azmBgV0YQ7a41A+7Vca3uESgHcdZmtnJntPMP1FuL /Lww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:message-id :in-reply-to:date:references:subject:cc:to:from :arc-authentication-results; bh=WqGKQYU29QqMQdRBxwn+9Gp107Cd4G08HHED7c1rMSM=; b=r21Q3oKKfluUouh1goMJ6ueoUYvl38EHWpgZXlXXbY8pLDVfeYtmkkhaKEESUGqqm+ +VODUmG34/DI98p9MiYwmSYpzp3YrEDoOeW520pEYPdBRumAM0I9MUzm3OAzgVGQXhuX e+2WC7A9MVgE3M+ODFbbyjiQSvHfTB/k7MTv3hdtNmM3R8a/ndPhyGJfxXqh2qPebE9S kYtlT6dpH1U1LN28FR/Qo6c34B0C5kQLV//vW01KfAAuchX0MJynBg/ZimiXcTPO9xrW t9zT5Iw6Uf1x4sJDALsU2mzvMuQ7DVMG3XB629LBfcaWQufa8WELwnai559kGGfMlv5T GD+A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z23-v6si43214744plo.492.2018.06.02.04.43.46; Sat, 02 Jun 2018 04:44:35 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751393AbeFBLk7 (ORCPT + 99 others); Sat, 2 Jun 2018 07:40:59 -0400 Received: from mail.parknet.co.jp ([210.171.160.6]:46939 "EHLO mail.parknet.co.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750892AbeFBLk5 (ORCPT ); Sat, 2 Jun 2018 07:40:57 -0400 X-Greylist: delayed 1271 seconds by postgrey-1.27 at vger.kernel.org; Sat, 02 Jun 2018 07:40:56 EDT Received: from ibmpc.myhome.or.jp (server.parknet.ne.jp [210.171.168.39]) by mail.parknet.co.jp (Postfix) with ESMTP id BA59C1E004A; Sat, 2 Jun 2018 20:19:29 +0900 (JST) Received: from devron.myhome.or.jp (foobar@devron.myhome.or.jp [192.168.0.3]) by ibmpc.myhome.or.jp (8.15.2/8.15.2/Debian-11) with ESMTPS id w52BJSTe001162 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sat, 2 Jun 2018 20:19:29 +0900 Received: from devron.myhome.or.jp (foobar@localhost [127.0.0.1]) by devron.myhome.or.jp (8.15.2/8.15.2/Debian-11) with ESMTPS id w52BJSng015020 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sat, 2 Jun 2018 20:19:28 +0900 Received: (from hirofumi@localhost) by devron.myhome.or.jp (8.15.2/8.15.2/Submit) id w52BJSjE015019; Sat, 2 Jun 2018 20:19:28 +0900 From: OGAWA Hirofumi To: Anatoly Trosinenko Cc: Andrew Morton , linux-kernel@vger.kernel.org Subject: Re: PROBLEM: [kernel BUG at fs/fat/inode.c:162] when writing to a broken VFAT References: Date: Sat, 02 Jun 2018 20:19:28 +0900 In-Reply-To: (Anatoly Trosinenko's message of "Fri, 1 Jun 2018 12:45:14 +0300") Message-ID: <874lilcu67.fsf@mail.parknet.co.jp> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Anatoly Trosinenko writes: > Description: > > Writing to some file on a broken VFAT partition causes kernel bug Thanks. This patch should fix this issue. -- OGAWA Hirofumi [PATCH] fat: Use fat_fs_error() instead of BUG_ON() in __fat_get_block() If file size and FAT cluster chain is not matched (corrupted image), we can hit BUG_ON(!phys) in __fat_get_block(). So, use fat_fs_error() instead. Signed-off-by: OGAWA Hirofumi --- fs/fat/inode.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff -puN fs/fat/inode.c~vfat-dont-bugon fs/fat/inode.c --- linux/fs/fat/inode.c~vfat-dont-bugon 2018-06-02 20:15:04.441920069 +0900 +++ linux-hirofumi/fs/fat/inode.c 2018-06-02 20:15:04.442920067 +0900 @@ -158,8 +158,13 @@ static inline int __fat_get_block(struct err = fat_bmap(inode, iblock, &phys, &mapped_blocks, create, false); if (err) return err; + if (!phys) { + fat_fs_error(sb, + "invalid FAT chain (i_pos %lld, last_block %ld)", + MSDOS_I(inode)->i_pos, last_block); + return -EIO; + } - BUG_ON(!phys); BUG_ON(*max_blocks != mapped_blocks); set_buffer_new(bh_result); map_bh(bh_result, sb, phys); _