From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 1A9FA279DB6 for ; Wed, 12 Aug 2026 01:55:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786499734; cv=none; b=UBm1oCTAv7shlP+f+ebmI6FzSs4iNhp0h1HjlBy4OHre0ntcg4BHJUODIiYHGqCsu1MorkaN6vSP4QiAcll7dOPeAOgEsu+RUTrg75pRddhW530QmB4T2r880LLG1AwZIA9cn0KKy+/mGYOKEb9dpkyp8aC+UJM8pXqTp5Hf28o= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786499734; c=relaxed/simple; bh=u1ZP1RQm5bWcnkSN8M5vqlbOUZ+lqlpN6DzSTXCEw64=; h=Date:From:To:Cc:Subject:Message-Id:In-Reply-To:References: Mime-Version:Content-Type; b=OYkaV773vV+l1xQ33FXH8VRaK+DQiHbXDkXI35BRJYezKGtK57ov3cdv1jsJq4GZatF2USAQ8X39eOpcikw+5ExNERkM1/2VkWc/78V4Ykf2rDlizEB6TM7h9EA+RcMBLQfniv/fYpYwp4PxZsOAXtXKUrm6+CgEiIlPmIFsm1Y= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b=1I4J573t; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b="1I4J573t" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0BF291F000E9; Wed, 12 Aug 2026 01:55:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=korg; t=1786499732; bh=D3J/mfvgn9SmovtymddZ07bkV2x12Gnah16+sxIHr8M=; h=Date:From:To:Cc:Subject:In-Reply-To:References; b=1I4J573tv8JASXk3UWDq6ARUNCxoHLr3ePLtFNJC94rmbe//f/8FRzX8NwlEYc2QV G7KRrTcxZJAPzmWpTfo56U8JS6iAgU7r0bZGtHpx87c9bDa1vUCC1OzlgcSgB3CaKC PdqmfnrD9F3eVyWWFbOFDCzhj4EYE6Av+bFlNLR8= Date: Tue, 11 Aug 2026 18:55:31 -0700 From: Andrew Morton To: Sourav Panda Cc: muchun.song@linux.dev, osalvador@suse.de, usama.arif@linux.dev, shakeel.butt@linux.dev, wangkefeng.wang@huawei.com, anshuman.khandual@arm.com, david@kernel.org, surenb@google.com, fvdl@google.com, gthelen@google.com, hannes@cmpxchg.org, riel@surriel.com, sj@kernel.org, vbabka@suse.cz, mhocko@suse.com, bjackman@google.com, zi.yan@sent.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v7] mm/hugetlb_cma: Fix null nodemask dereference in hugetlb_cma_alloc_frozen_folio Message-Id: <20260811185531.b8e3fb91c51713b2f29bc1f0@linux-foundation.org> In-Reply-To: <20260811052909.475635-1-souravpanda@google.com> References: <20260811052909.475635-1-souravpanda@google.com> X-Mailer: Sylpheed 3.8.0beta1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Tue, 11 Aug 2026 05:29:09 +0000 Sourav Panda wrote: > alloc_buddy_hugetlb_folio_with_mpol() can pass a NULL nodemask to > alloc_fresh_hugetlb_folio() as a fallback to allocate from all > nodes. If order is gigantic, alloc_fresh_hugetlb_folio() propagates > the NULL nodemask down to hugetlb_cma_alloc_frozen_folio() via > alloc_gigantic_frozen_folio(). > > Additionally, hugetlb_cma_alloc_frozen_folio() previously attempted > allocation on hugetlb_cma[nid] without verifying if nid is included in > the caller's nodemask. Adding a node_isset(nid, *nodemask) check ensures > the initial preferred node allocation honors the memory policy / nodemask. > > However, hugetlb_cma_alloc_frozen_folio() dereferences the nodemask in > node_isset(nid, *nodemask) and for_each_node_mask(node, *nodemask), > leading to a null pointer dereference kernel panic when nodemask is NULL. > > Fix this by checking if nodemask is NULL in > hugetlb_cma_alloc_frozen_folio() and defaulting it to > cpuset_current_mems_allowed. Enclose the allocation attempts within > the cpuset seqcount retry loop so that if the cpuset changes concurrently > during allocation, the attempts are retried using the updated nodemask. > This ensures that the initial node check and fallback loop safely honor > the task's cpuset without violating cpuset constraints or causing NULL > pointer dereferences or unexpected allocation failures. > > From a userspace perspective, this bug allows an unprivileged user to > crash the kernel (trigger a panic) by requesting a gigantic hugepage > allocation with MPOL_PREFERRED_MANY on a system where CMA is only > configured on a subset of NUMA nodes. Thanks. Sashio might have found another thing with MPOL_PREFERRED_MANY and CMA: https://sashiko.dev/#/patchset/20260811052909.475635-1-souravpanda@google.com We're days away from 7.2 and I do dislike sending hotfixes upstream at such a late stage. I expect I'll upstream this and a few other hotfixes after 7.2 is released. It'll all end up in the same place. I would still upstream hotfixes which address added-in-this-cycle bugs, but there aren't any of those at present.