From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751989AbcFXOgs (ORCPT ); Fri, 24 Jun 2016 10:36:48 -0400 Received: from mail-pf0-f196.google.com ([209.85.192.196]:33904 "EHLO mail-pf0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751605AbcFXOge (ORCPT ); Fri, 24 Jun 2016 10:36:34 -0400 From: Ryusuke Konishi To: Andrew Morton Cc: linux-nilfs , LKML , Ryusuke Konishi , Torsten Hilbrich Subject: [PATCH 1/1] fs/nilfs2: Fix potential underflow in call to crc32_le Date: Fri, 24 Jun 2016 23:29:47 +0900 Message-Id: <1466778587-5184-2-git-send-email-konishi.ryusuke@lab.ntt.co.jp> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1466778587-5184-1-git-send-email-konishi.ryusuke@lab.ntt.co.jp> References: <1466778587-5184-1-git-send-email-konishi.ryusuke@lab.ntt.co.jp> X-Dispatcher: imput version 20110525(IM151) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Torsten Hilbrich The value bytes comes from the filesystem which is about to be mounted. We cannot trust that the value is always in the range we expect it to be. Check its value before using it to calculate the length for the crc32_le call. It value must be larger (or equal) sumoff + 4. This fixes a kernel bug when accidentially mounting an image file which had the nilfs2 magic value 0x3434 at the right offset 0x406 by chance. The bytes 0x01 0x00 were stored at 0x408 and were interpreted as a s_bytes value of 1. This caused an underflow when substracting sumoff + 4 (20) in the call to crc32_le. [201699.185465] BUG: unable to handle kernel paging request at ffff88021e600000 [201699.186111] IP: [] crc32_le+0x36/0x100 ... [201699.206202] Call Trace: [201699.206982] [] nilfs_valid_sb.part.5+0x52/0x60 [nilfs2] [201699.207773] [] nilfs_load_super_block+0x142/0x300 [nilfs2] [201699.208564] [] ? set_blocksize+0x9d/0xd0 [201699.209355] [] init_nilfs+0x60/0x390 [nilfs2] [201699.210160] [] nilfs_mount+0x302/0x520 [nilfs2] [201699.210930] [] ? pcpu_alloc+0x385/0x670 [201699.211685] [] mount_fs+0x38/0x160 [201699.212413] [] ? __alloc_percpu+0x15/0x20 [201699.213151] [] vfs_kern_mount+0x67/0x110 [201699.213898] [] do_mount+0x269/0xe00 [201699.214671] [] ? mntput+0x24/0x40 [201699.215432] [] ? __kmalloc_track_caller+0x1b4/0x250 [201699.216207] [] ? __fput+0x190/0x220 [201699.216987] [] ? memdup_user+0x42/0x70 [201699.217777] [] SyS_mount+0x9f/0x100 [201699.218595] [] entry_SYSCALL_64_fastpath+0x16/0x71 Signed-off-by: Torsten Hilbrich Tested-by: Torsten Hilbrich Signed-off-by: Ryusuke Konishi Cc: stable@vger.kernel.org --- fs/nilfs2/the_nilfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/nilfs2/the_nilfs.c b/fs/nilfs2/the_nilfs.c index 809bd2d..e9fd241 100644 --- a/fs/nilfs2/the_nilfs.c +++ b/fs/nilfs2/the_nilfs.c @@ -439,7 +439,7 @@ static int nilfs_valid_sb(struct nilfs_super_block *sbp) if (!sbp || le16_to_cpu(sbp->s_magic) != NILFS_SUPER_MAGIC) return 0; bytes = le16_to_cpu(sbp->s_bytes); - if (bytes > BLOCK_SIZE) + if (bytes < sumoff + 4 || bytes > BLOCK_SIZE) return 0; crc = crc32_le(le32_to_cpu(sbp->s_crc_seed), (unsigned char *)sbp, sumoff); -- 1.8.3.1