From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from www262.sakura.ne.jp ([202.181.97.72]:21231 "EHLO www262.sakura.ne.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754913AbeFNN20 (ORCPT ); Thu, 14 Jun 2018 09:28:26 -0400 Subject: Re: [PATCH] bfs: add sanity check at bfs_fill_super(). To: Tigran Aivazian , Dmitry Vyukov Cc: Andrew Morton , linux-fsdevel , syzbot , syzkaller-bugs References: <1525862104-3407-1-git-send-email-penguin-kernel@I-love.SAKURA.ne.jp> <20180509160658.c37bef542a8ee5245a13917b@linux-foundation.org> <201805092346.w49NkINl045657@www262.sakura.ne.jp> <20180509165321.3b2b1313fde0f007c1a5a015@linux-foundation.org> <9ef86114-02d6-b243-203d-fbbdab95a6fa@I-love.SAKURA.ne.jp> From: Tetsuo Handa Message-ID: Date: Thu, 14 Jun 2018 22:28:11 +0900 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-fsdevel-owner@vger.kernel.org List-ID: On 2018/06/14 22:05, Tigran Aivazian wrote: > On 14 June 2018 at 13:38, Dmitry Vyukov wrote: >> Consider, currently we can have a bfs image that works fine on one >> kernel, but fails to mount on another just because it happens so that >> one could allocate 4MB with kmalloc, but another can't (different >> allocator/different settings/different kernel revision). > > Yes, but this would only happen _without_ the validation proposed by > Tetsuo Handa. If we check s_start then the invalid enormous allocation > request will not be made and what you describe won't not happen. > What is possible largest value for imap_len ? info->si_lasti = (le32_to_cpu(bfs_sb->s_start) - BFS_BSIZE) / sizeof(struct bfs_inode) + BFS_ROOT_INO - 1; imap_len = (info->si_lasti / 8) + 1; info->si_imap = kzalloc(imap_len, GFP_KERNEL); Since sizeof(struct bfs_inode) is 64 and bfs_sb->s_start is unsigned 32bits integer (where constraints is BFS_BSIZE <= bfs_sb->s_start <= bfs_sb->s_end), theoretically it is possible to assign bfs_sb->s_start > 2GB (apart from whether such value makes sense). Then, isn't it possible that imap_len > 4M and still hit KMALLOC_MAX_SIZE limit?