From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4CBEA3B42E9 for ; Thu, 2 Jul 2026 21:57:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.73 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783029437; cv=none; b=gwb6a1/59WsENqR7XHb+umZdSX6Mbi4O++VqeLSEgCbKiE9mt60cnPMKc+8Q9Ph6Qy9xkT/KCuYu1Hp/4buFeF6hXW+4gQb3TDflHgwW3yfuvUz98ZLYLun/3oosIdNbdxCMChggApessI71OPvNuodo9D8u5WgClWn3QEMViig= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783029437; c=relaxed/simple; bh=Zpptfimxsq5mvqlCgfYLQyueILi3+TSkrNtaLLv5FSo=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=LIx/jFyES78HvNmKqs+0N8SHofAP/eYB/3NFEv9J37poCO6nAdgGbPUgqFj+XL1TUEvlN+T8jozDhYRtqjDXN9xAFn9nKt18/e4yLJ571WLgfHmFHzD2BWVJ/pQomQB5uYSv5rAKldIonlXlsLMw3XANnItQqFA+mau5zdbOK9w= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--souravpanda.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=U7NcBFnz; arc=none smtp.client-ip=209.85.216.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--souravpanda.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="U7NcBFnz" Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-3810960140eso1027173a91.2 for ; Thu, 02 Jul 2026 14:57:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1783029435; x=1783634235; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=WZ/TPtvTNC+q9FGe3x84bP2kV6oDVoOCT17hGTL+ZZU=; b=U7NcBFnzCQ+ossm39UlR088Fnd+Gf2Aao8uJ0aEX3r2As5g4FV6n0bL37LXwJ1wKj1 YIaAsnxyrddBPFjLcweOovG+yc5n55upnM7S/kWYNIyWIkkzmWCnWIHEbxa2kX2vSKgP 2a2g1QbhCvJOYTaU+Cv/yGABnwlpZJpe/fDlweOvzqikz+eIRYLLOzMpGk9u45ZeQq/j F+EU/9sDK0t2TbMWe+mSxytQXJoJ9ZS36Vty4cmsMjJIVFVZYs2NX4S49zY3I2QOpCNF WXhkAvPmf1g5/ePmbesJAnHbC8eU51r+PemKf2wtuzY2sA7pL/gqBTxovgeK8/VOSEmD vW2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783029435; x=1783634235; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=WZ/TPtvTNC+q9FGe3x84bP2kV6oDVoOCT17hGTL+ZZU=; b=jCQRQrwd2xqSWR/ZbdKZMcUTmd+jvr2GLSge8BvFb32R8ZoWYaSx67Hlo+tk9Q/gIM XxNPY+M4FTpmkrTcGQW3EEVu2WTIMrQKh3QD/P9j8ycnnazEf5L9fmr40qzfhnNE621f Ah8NsibiuaB0yOZUnAFP1eszko65TZfo8o6pyr7TKl50mGONSMdXDBu6/Ic/2otJB3FR dkCL1Q4hS2D5I8/Laspz4WYYMatKUIEdLIQOB3Ov6TfMUjRk67IAQOiQy2eMAUf/StaU rFG0ofoDG7QmO6Sc5gkUW4I0rdt6OtuF2ZM2bOs4v7qzzdOuMGqOzBs8eIsMPRNc/LPo vilA== X-Forwarded-Encrypted: i=1; AHgh+RrRC51UNRE5lEbJO11s7AAi3mvBmYXIdDNX8JdPZshz5eDzLLeRM6M0LKuRk03QOBICCaZdREGcvcejSZU=@vger.kernel.org X-Gm-Message-State: AOJu0YwOJG0I2OeLB+4v1MLlzLWBMnyDy+0UhbpA0BFzP6vQUJbDPqoU 1sbP2WWHo1jeRZxvw+ZEFgjmnHT4VXwYlPIL0aOPgBMNQmOjOCrS1X3tgNAXJZ63d+jN+/chrki /sJ3GL4xzMvy4WftFx3kMT+l93Q== X-Received: from pltm9.prod.google.com ([2002:a17:902:6bc9:b0:2ca:c162:e758]) (user=souravpanda job=prod-delivery.src-stubby-dispatcher) by 2002:a17:903:8d0:b0:2c0:b5c1:8e22 with SMTP id d9443c01a7336-2ca7e6847d9mr90430995ad.12.1783029435098; Thu, 02 Jul 2026 14:57:15 -0700 (PDT) Date: Thu, 2 Jul 2026 21:57:13 +0000 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Mailer: git-send-email 2.55.0.rc0.799.gd6f94ed593-goog Message-ID: <20260702215713.627941-1-souravpanda@google.com> Subject: [PATCH] mm/hugetlb: Fix null pointer dereference of nodemask in hugetlb_cma_alloc_frozen_folio From: Sourav Panda To: muchun.song@linux.dev, osalvador@suse.de, akpm@linux-foundation.org Cc: david@kernel.org, surenb@google.com, fvdl@google.com, gthelen@google.com, souravpanda@google.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" alloc_buddy_hugetlb_folio_with_mpol() can pass a NULL nodemask to hugetlb_cma_alloc_frozen_folio() as a fallback to allocate from all nodes. In this case, hugetlb_cma_alloc_frozen_folio() blindly dereferences it in for_each_node_mask(), leading to a null pointer dereference. Fix this by checking if nodemask is NULL and defaulting to node_states[N_MEMORY] if it is. Signed-off-by: Sourav Panda --- mm/hugetlb_cma.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mm/hugetlb_cma.c b/mm/hugetlb_cma.c index 39344d6c78d8..563e11e607e5 100644 --- a/mm/hugetlb_cma.c +++ b/mm/hugetlb_cma.c @@ -34,6 +34,9 @@ struct folio *hugetlb_cma_alloc_frozen_folio(int order, gfp_t gfp_mask, if (!hugetlb_cma_size) return NULL; + if (!nodemask) + nodemask = &node_states[N_MEMORY]; + if (hugetlb_cma[nid]) page = cma_alloc_frozen_compound(hugetlb_cma[nid], order); -- 2.55.0.rc0.799.gd6f94ed593-goog