From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9E25D311968 for ; Thu, 20 Nov 2025 09:25:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763630709; cv=none; b=jU2s8WSw9LItTbgsjYt1MqTPy0ry2wBGtjtWZv/f7e7EL9jf6ImkWgPz4tZBkj9BUg4kjG0Mc/10ztWvoUc0gu0bzwV8J72JVxL6QhrZs5YBzXxXWqSy8rb1LRfKgC5WtiFsnFMKHlzZ6NVc6fGZy2YPs0NJrpLvVY/4Vby4eIY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763630709; c=relaxed/simple; bh=Zxcj9YrpAEfvPY91o1U5hwiHCXNZdysrcM08YutqhjA=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=QF+32dGC+6p4w4FzuILHK95sWwQwljywFqLHQ5D8dJE+ZryspkyaTOEg/CEBAQP+BM6Y9NDazK6FAMOiPXPEbo265RcVYeGG+puLC3ymGXeKNglBRRLYQ00zNEdsyYfkvNLw0Wvsk3MSLY72qjwP8WpqvamtOUuFHHfM4oIsrsg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=uwLOIVrC; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="uwLOIVrC" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0C8E6C4CEF1; Thu, 20 Nov 2025 09:25:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1763630707; bh=Zxcj9YrpAEfvPY91o1U5hwiHCXNZdysrcM08YutqhjA=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=uwLOIVrCHyj293/4WH4HOG2zu281VSxljjgOmaymHYjlguERPfAvjpub/HQXMaBV3 MndUSzl+xdJ8n6JaBOtzKpWB1DbPDCNe/+bZKBLtAV6C8SJAgHO9iQQ6phudPOCvEt yzp5BKvBVMliCmTQjTZBAfV0UB4leb7yzJ5V5vhTjJRDnseA2Bh0fx6+sV8qEy6VgS tB29W2mj6vEzz8sO8gakgTCpvxTjCXTuQim5ckt/P4nF/5rXOVHSiqdq9zEukpNm3Q 2cFd6XYCoDx8kmoueTfcrs8w8yvqO0o9js8bETMGbuvRdVUN6AK8MX4foCpnH0OJkr mQGfW84PZULcQ== Message-ID: <875584d7-5a68-4f7a-8549-2a9cd6c7f9d8@kernel.org> Date: Thu, 20 Nov 2025 10:25:01 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [RFC PATCH 1/3] mm/huge_memory: prevent NULL pointer dereference in try_folio_split_to_order() To: Zi Yan , Lorenzo Stoakes Cc: Andrew Morton , Baolin Wang , "Liam R. Howlett" , Nico Pache , Ryan Roberts , Dev Jain , Barry Song , Lance Yang , Miaohe Lin , Naoya Horiguchi , linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <20251120035953.1115736-1-ziy@nvidia.com> <20251120035953.1115736-2-ziy@nvidia.com> From: "David Hildenbrand (Red Hat)" Content-Language: en-US In-Reply-To: <20251120035953.1115736-2-ziy@nvidia.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 11/20/25 04:59, Zi Yan wrote: > folio_split_supported() used in try_folio_split_to_order() requires > folio->mapping to be non NULL, but current try_folio_split_to_order() does > not check it. Add the check to prevent NULL pointer dereference. > > There is no issue in the current code, since try_folio_split_to_order() is > only used in truncate_inode_partial_folio(), where folio->mapping is not > NULL. > > Signed-off-by: Zi Yan > --- > include/linux/huge_mm.h | 7 +++++++ > 1 file changed, 7 insertions(+) > > diff --git a/include/linux/huge_mm.h b/include/linux/huge_mm.h > index 1d439de1ca2c..0d55354e3a34 100644 > --- a/include/linux/huge_mm.h > +++ b/include/linux/huge_mm.h > @@ -407,6 +407,13 @@ static inline int split_huge_page_to_order(struct page *page, unsigned int new_o > static inline int try_folio_split_to_order(struct folio *folio, > struct page *page, unsigned int new_order) > { > + /* > + * Folios that just got truncated cannot get split. Signal to the > + * caller that there was a race. > + */ > + if (!folio_test_anon(folio) && !folio->mapping) > + return -EBUSY; > + > if (!folio_split_supported(folio, new_order, SPLIT_TYPE_NON_UNIFORM, /* warns= */ false)) > return split_huge_page_to_order(&folio->page, new_order); > return folio_split(folio, new_order, page, NULL); I guess we'll take the one from Wei https://lkml.kernel.org/r/20251119235302.24773-1-richard.weiyang@gmail.com right? -- Cheers David