From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.4 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B51D9C433E0 for ; Mon, 18 Jan 2021 08:48:46 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id D7FD1221E3 for ; Mon, 18 Jan 2021 08:48:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D7FD1221E3 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=huawei.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id BD5CB6B0095; Mon, 18 Jan 2021 03:48:44 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B85036B009C; Mon, 18 Jan 2021 03:48:44 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A9BAF6B00C8; Mon, 18 Jan 2021 03:48:44 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0211.hostedemail.com [216.40.44.211]) by kanga.kvack.org (Postfix) with ESMTP id 9419C6B0095 for ; Mon, 18 Jan 2021 03:48:44 -0500 (EST) Received: from smtpin04.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 47804181AF5D0 for ; Mon, 18 Jan 2021 08:48:44 +0000 (UTC) X-FDA: 77718270168.04.patch75_0a184d927547 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin04.hostedemail.com (Postfix) with ESMTP id 249B9800BE85 for ; Mon, 18 Jan 2021 08:48:44 +0000 (UTC) X-HE-Tag: patch75_0a184d927547 X-Filterd-Recvd-Size: 3448 Received: from szxga05-in.huawei.com (szxga05-in.huawei.com [45.249.212.191]) by imf43.hostedemail.com (Postfix) with ESMTP for ; Mon, 18 Jan 2021 08:48:43 +0000 (UTC) Received: from DGGEMS414-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4DK5506fwFzMLfg; Mon, 18 Jan 2021 16:47:16 +0800 (CST) Received: from [10.174.177.2] (10.174.177.2) by DGGEMS414-HUB.china.huawei.com (10.3.19.214) with Microsoft SMTP Server id 14.3.498.0; Mon, 18 Jan 2021 16:48:38 +0800 Subject: Re: [PATCH] hugetlbfs: make BUG_ON(!inode) takes effect in hugetlbfs_setattr To: Muchun Song CC: , , linux-kernel References: <20210116090910.5671-1-linmiaohe@huawei.com> From: Miaohe Lin Message-ID: <88d19bf2-f176-500e-9e73-0d863754466d@huawei.com> Date: Mon, 18 Jan 2021 16:48:37 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.6.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.174.177.2] X-CFilter-Loop: Reflected 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: Hi: On 2021/1/18 15:59, Muchun Song wrote: > On Sat, Jan 16, 2021 at 5:11 PM Miaohe Lin wrote: >> >> When we reach here with inode = NULL, we should have crashed as inode has >> already been dereferenced via hstate_inode. In order to make BUG_ON(!inode) >> takes effect, we should defer initializing hstate until we really need it. >> Also do this for hugetlbfs_inode_info as it's only used when ia_valid is >> verified with ATTR_SIZE. >> >> Signed-off-by: Miaohe Lin >> --- >> fs/hugetlbfs/inode.c | 4 ++-- >> 1 file changed, 2 insertions(+), 2 deletions(-) >> >> diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c >> index 740693d7f255..9b221b87fbea 100644 >> --- a/fs/hugetlbfs/inode.c >> +++ b/fs/hugetlbfs/inode.c >> @@ -755,10 +755,8 @@ static long hugetlbfs_fallocate(struct file *file, int mode, loff_t offset, >> static int hugetlbfs_setattr(struct dentry *dentry, struct iattr *attr) >> { >> struct inode *inode = d_inode(dentry); >> - struct hstate *h = hstate_inode(inode); > > If inode == NULL, it will panic here when we access inode->i_sb. > I have seen many other file system implementations about setattr, > they all think that d_inode() will return a non-NULL pointer. So > I prefer to just remove the BUG_ON(). > Sounds reasonable. Will do it in v2. Many thanks. > Thanks. > > >> int error; >> unsigned int ia_valid = attr->ia_valid; >> - struct hugetlbfs_inode_info *info = HUGETLBFS_I(inode); >> >> BUG_ON(!inode); >> >> @@ -767,6 +765,8 @@ static int hugetlbfs_setattr(struct dentry *dentry, struct iattr *attr) >> return error; >> >> if (ia_valid & ATTR_SIZE) { >> + struct hstate *h = hstate_inode(inode); >> + struct hugetlbfs_inode_info *info = HUGETLBFS_I(inode); >> loff_t oldsize = inode->i_size; >> loff_t newsize = attr->ia_size; >> >> -- >> 2.19.1 >> > . >