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=-3.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=no 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 72625C4338F for ; Mon, 23 Aug 2021 01:06:44 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id B9D1E61262 for ; Mon, 23 Aug 2021 01:06:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org B9D1E61262 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id E1BB96B006C; Sun, 22 Aug 2021 21:06:42 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DA4596B0072; Sun, 22 Aug 2021 21:06:42 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C6C4F8D0001; Sun, 22 Aug 2021 21:06:42 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0144.hostedemail.com [216.40.44.144]) by kanga.kvack.org (Postfix) with ESMTP id A855E6B006C for ; Sun, 22 Aug 2021 21:06:42 -0400 (EDT) Received: from smtpin11.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 546F4180EE3E6 for ; Mon, 23 Aug 2021 01:06:42 +0000 (UTC) X-FDA: 78504555444.11.AE118BD Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf01.hostedemail.com (Postfix) with ESMTP id C5FC9501EE3E for ; Mon, 23 Aug 2021 01:06:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=aspPZtQVW2NXlfWYzMvyvdVJsYawidsXh00ZJfiDIgk=; b=jL04ykE3uh+j5Lc5Hh8LKs7iYO PCr18G7o0uas5a+kZ4dfug8ngc+wrVXJtnqozxE5fZ+i+jVreVre66iq475ebwIQkBfVebvW0n8Wp xdQglzke+8XqfZnaK1Ci8vLMc8YdkyI/YHgzxV7ZGTW5YhUiEyB4WC5D5iZiSPzqDTq+/4jzVvFhw N5WCqNiT2tuWD3RHuECjffZCmhGszhOlW8WjBST6GFuidpcPfOlF31FPRB1nUd96z+S2yDFKxoIhE NnqsXM1QS7Tfeq8speOwfrQfYN8X3aC8gIFiFzqRcqWdkpl6wo7SNyzTt+arRHYOPXQVopInewnEw jy2+6SmQ==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1mHyOp-0096T6-1r; Mon, 23 Aug 2021 01:05:29 +0000 Date: Mon, 23 Aug 2021 02:05:15 +0100 From: Matthew Wilcox To: Yi Wang Cc: akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, xue.zhihong@zte.com.cn, jiang.xuexin@zte.com.cn, zealci@zte.com.cn, Changcheng Deng Subject: Re: [PATCH linux-next] mm/folio-compat.c: folio should not be NULL when it is referenced Message-ID: References: <20210823004735.32013-1-wang.yi59@zte.com.cn> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210823004735.32013-1-wang.yi59@zte.com.cn> Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=jL04ykE3; spf=none (imf01.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: C5FC9501EE3E X-Stat-Signature: zdfwsycpykuo4zn4pyejbwcrjtfiopi4 X-HE-Tag: 1629680801-415824 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000001, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Mon, Aug 23, 2021 at 08:47:35AM +0800, Yi Wang wrote: > From: Changcheng Deng > > A bug was found by coccinelle: > folio is NULL but dereferenced > Therefore,added a check to make sure 'folio' is not NULL. > > Reported-by: Zeal Robot Your robot is overzealous. This does not dereference folio; rather it takes the address of the page element of the folio structure. By a strict reading of the C spec, it is not allowed. However, GCC (and I assume Clang) does the right thing. > folio = __filemap_get_folio(mapping, index, fgp_flags, gfp); > - if ((fgp_flags & FGP_HEAD) || !folio || xa_is_value(folio)) > - return &folio->page; > + if ((fgp_flags & FGP_HEAD) || xa_is_value(folio)) > + if (folio != NULL) > + return &folio->page; > return folio_file_page(folio, index); This is definitely wrong. Did you test it? I bet you get a NULL pointer dereference if you try it. You could potentially make the case for: if (!folio) return NULL; if ((fgp_flags & FGP_HEAD) || xa_is_value(folio)) return &folio->page; but you actually have the same problem with the C spec, that unless folio is actually a pointer to a folio, then &folio->page is _technically_ undefined. So it would have to be something even more complex to be pedantically correct. It's just not worth it. Fix your tool.