From patchwork Tue Mar 22 21:38:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Morton X-Patchwork-Id: 12789045 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id B9CFCC433F5 for ; Tue, 22 Mar 2022 21:38:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3E4426B007D; Tue, 22 Mar 2022 17:38:42 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 38F866B007B; Tue, 22 Mar 2022 17:38:42 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 230D06B007D; Tue, 22 Mar 2022 17:38:42 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.25]) by kanga.kvack.org (Postfix) with ESMTP id 1429E6B0078 for ; Tue, 22 Mar 2022 17:38:42 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id D3ED522CE7 for ; Tue, 22 Mar 2022 21:38:41 +0000 (UTC) X-FDA: 79273336842.01.806016D Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf05.hostedemail.com (Postfix) with ESMTP id 5CA88100033 for ; Tue, 22 Mar 2022 21:38:41 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 6E6616166F; Tue, 22 Mar 2022 21:38:40 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3117DC340F4; Tue, 22 Mar 2022 21:38:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1647985120; bh=eZCt7nWQhmPEj1yw/elTFm+QXFc4QMWTtFkhJv31Mw8=; h=Date:To:From:In-Reply-To:Subject:From; b=T28KDiF5HERRVcy3OYX1F7iiNFkNwV8fUQsTTGIgawGjKBka5cm4AkPeAhTDSrf5k jdNiwGfWXrhzmNeLqzSKBP01uGhnmaUeWin+fajHJS+RM6WnvAkuKN0vUjd8wsEl0J OsMnWp89gMxzD7cUU7dLTkF6yS/m5WFuFvKB6XGg= Date: Tue, 22 Mar 2022 14:38:39 -0700 To: anton@tuxera.com,mudongliangabcd@gmail.com,akpm@linux-foundation.org,patches@lists.linux.dev,linux-mm@kvack.org,mm-commits@vger.kernel.org,torvalds@linux-foundation.org,akpm@linux-foundation.org From: Andrew Morton In-Reply-To: <20220322143803.04a5e59a07e48284f196a2f9@linux-foundation.org> Subject: [patch 003/227] ntfs: add sanity check on allocation size Message-Id: <20220322213840.3117DC340F4@smtp.kernel.org> X-Stat-Signature: 33a5tiir6ruyq8ee37r8t9e54j8ztuyw X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 5CA88100033 Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b=T28KDiF5; dmarc=none; spf=pass (imf05.hostedemail.com: domain of akpm@linux-foundation.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org X-Rspam-User: X-HE-Tag: 1647985121-366230 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Dongliang Mu Subject: ntfs: add sanity check on allocation size ntfs_read_inode_mount invokes ntfs_malloc_nofs with zero allocation size. It triggers one BUG in the __ntfs_malloc function. Fix this by adding sanity check on ni->attr_list_size. Link: https://lkml.kernel.org/r/20220120094914.47736-1-dzm91@hust.edu.cn Reported-by: syzbot+3c765c5248797356edaa@syzkaller.appspotmail.com Signed-off-by: Dongliang Mu Acked-by: Anton Altaparmakov Signed-off-by: Andrew Morton --- fs/ntfs/inode.c | 4 ++++ 1 file changed, 4 insertions(+) --- a/fs/ntfs/inode.c~ntfs-add-sanity-check-on-allocation-size +++ a/fs/ntfs/inode.c @@ -1881,6 +1881,10 @@ int ntfs_read_inode_mount(struct inode * } /* Now allocate memory for the attribute list. */ ni->attr_list_size = (u32)ntfs_attr_size(a); + if (!ni->attr_list_size) { + ntfs_error(sb, "Attr_list_size is zero"); + goto put_err_out; + } ni->attr_list = ntfs_malloc_nofs(ni->attr_list_size); if (!ni->attr_list) { ntfs_error(sb, "Not enough memory to allocate buffer "