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 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D903AC433F5 for ; Sat, 9 Oct 2021 19:36:16 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 2BB4D60E94 for ; Sat, 9 Oct 2021 19:36:16 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 2BB4D60E94 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 7F5BC900002; Sat, 9 Oct 2021 15:36:15 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7A59F6B0072; Sat, 9 Oct 2021 15:36:15 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6BB57900002; Sat, 9 Oct 2021 15:36:15 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0252.hostedemail.com [216.40.44.252]) by kanga.kvack.org (Postfix) with ESMTP id 5B87D6B006C for ; Sat, 9 Oct 2021 15:36:15 -0400 (EDT) Received: from smtpin32.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 26E8D180AD83E for ; Sat, 9 Oct 2021 19:36:15 +0000 (UTC) X-FDA: 78677905110.32.5F30104 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf13.hostedemail.com (Postfix) with ESMTP id 7F56E103DA2D for ; Sat, 9 Oct 2021 19:36:14 +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=lM0zRIXeoiENBbttmaqjYixN1trfHDq/iU88uhQzWPg=; b=VY2NW6qMmyw2Zkw+xexPwo8Prw /WK/nTozEFsts2fE2oQwjR8JYO5XGnTnp8ZqA5028GAuy4kZoCId0eI1ZcwwWQ93fNP8CXNC26jyV giOSPWOvL2BiK6yryNiqs7Am/iZOBj9UPPwyEAGabD1RPrTnCvIkC/RqwCHkyUpf67YDYEFssADCQ 5A7I4k1FECQGimdJVW6rN7VbAkcYlmD3zq4jwBdaFQh6eOKVHnJ+fiaEIgaQIf0Q0qvlLSO1QDsT1 DQXSpROEPGcENJcxbT5NBcI7CWmjbVPqFf2RugbsjthtBd42RptaiT2RJnpnpstu5p1VTiBiA7tfA AFTJ5fsw==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1mZI8J-004Mbb-4R; Sat, 09 Oct 2021 19:35:53 +0000 Date: Sat, 9 Oct 2021 20:35:47 +0100 From: Matthew Wilcox To: cgel.zte@gmail.com Cc: akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, xu xin , Zeal Robot Subject: Re: [PATCH linux-next] mm/folio-compat: fix potential NULL pointer access Message-ID: References: <20210913081113.79975-1-xu.xin16@zte.com.cn> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210913081113.79975-1-xu.xin16@zte.com.cn> X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 7F56E103DA2D X-Stat-Signature: pcbu6hnd3x9jgaqqqm4sk4rk7ywo8qjg Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=VY2NW6qM; dmarc=none; spf=none (imf13.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org X-HE-Tag: 1633808174-58934 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: On Mon, Sep 13, 2021 at 08:11:13AM +0000, cgel.zte@gmail.com wrote: > From: xu xin > > The pointer 'folio' might be NULL, but the structure it points to is accessed. > Accordingly, we add a check of NULL pointer by 'if (!folio)'. > Secondly, there is no need to check if folio is pointer or value with 'xa_is_value(folio)' > because folio is alwayse pointer. > > Reported-by: Zeal Robot Your robot is garbage. > folio = __filemap_get_folio(mapping, index, fgp_flags, gfp); > - if ((fgp_flags & FGP_HEAD) || !folio || xa_is_value(folio)) > + if (!folio) > + return NULL; > + if ((fgp_flags & FGP_HEAD)) > return &folio->page; &folio->page *does not access folio*. It does pointer arithmetic on folio. Specifically, it adds zero to folio, because page is the first element of folio. Secondly, __filemap_get_folio() absolutely can return an xa_is_value() result if FGP_ENTRY entry is set. It's right there in the first few lines: folio = mapping_get_entry(mapping, index); if (xa_is_value(folio)) { if (fgp_flags & FGP_ENTRY) return folio;