Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753110AbbKZIaI (ORCPT ); Thu, 26 Nov 2015 03:30:08 -0500 Received: from mail.parknet.co.jp ([210.171.160.6]:54258 "EHLO mail.parknet.co.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752819AbbKZIaE (ORCPT ); Thu, 26 Nov 2015 03:30:04 -0500 From: OGAWA Hirofumi To: Andrew Morton Cc: Vegard Nossum , Richard Weinberger , LKML Subject: Re: WARNING: CPU: 0 PID: 913 at fs/inode.c:275 drop_nlink+0x4b/0x50() References: <5652C676.8040207@oracle.com> <5653916C.7060601@nod.at> <56541AE8.2070704@oracle.com> <87lh9l2190.fsf@mail.parknet.co.jp> <5656BEE8.4030001@oracle.com> Date: Thu, 26 Nov 2015 17:30:01 +0900 In-Reply-To: <5656BEE8.4030001@oracle.com> (Vegard Nossum's message of "Thu, 26 Nov 2015 09:12:24 +0100") Message-ID: <87egfd6u46.fsf@mail.parknet.co.jp> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2577 Lines: 88 Vegard Nossum writes: > On 11/25/2015 10:54 PM, OGAWA Hirofumi wrote: >> Vegard Nossum writes: >> >>> On 11/23/2015 11:21 PM, Richard Weinberger wrote: >>>> Am 23.11.2015 um 08:55 schrieb Vegard Nossum: >>>>> With the attached vfat disk image (fuzzed), I get the following WARNING: >>>>> >>>>> WARNING: CPU: 0 PID: 913 at fs/inode.c:275 drop_nlink+0x4b/0x50() > > [...] > >> >> Can you try this one? >> > > That seems to fix the problem here, thanks! Andrew, please queue this up for next chance. Thanks. -- OGAWA Hirofumi [PATCH] fat: Add simple validation for directory inode This detects simple corruption cases of directory, and try to avoid further damage to user data. And performance impact of this validation should be very low, or not measurable. Reported-by: Vegard Nossum Tested-by: Vegard Nossum Signed-off-by: OGAWA Hirofumi --- fs/fat/inode.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff -puN fs/fat/inode.c~fat-validate-dir fs/fat/inode.c --- linux/fs/fat/inode.c~fat-validate-dir 2015-11-26 06:31:39.666959958 +0900 +++ linux-hirofumi/fs/fat/inode.c 2015-11-26 06:31:39.670959945 +0900 @@ -449,6 +449,24 @@ static int fat_calc_dir_size(struct inod return 0; } +static int fat_validate_dir(struct inode *dir) +{ + struct super_block *sb = dir->i_sb; + + if (dir->i_nlink < 2) { + /* Directory should have "."/".." entries at least. */ + fat_fs_error(sb, "corrupted directory (invalid entries)"); + return -EIO; + } + if (MSDOS_I(dir)->i_start == 0 || + MSDOS_I(dir)->i_start == MSDOS_SB(sb)->root_cluster) { + /* Directory should point valid cluster. */ + fat_fs_error(sb, "corrupted directory (invalid i_start)"); + return -EIO; + } + return 0; +} + /* doesn't deal with root inode */ int fat_fill_inode(struct inode *inode, struct msdos_dir_entry *de) { @@ -475,6 +493,10 @@ int fat_fill_inode(struct inode *inode, MSDOS_I(inode)->mmu_private = inode->i_size; set_nlink(inode, fat_subdirs(inode)); + + error = fat_validate_dir(inode); + if (error < 0) + return error; } else { /* not a directory */ inode->i_generation |= 1; inode->i_mode = fat_make_mode(sbi, de->attr, _ -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/