From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) (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 D0ADE30E82D for ; Fri, 24 Apr 2026 02:56:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.175 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776999373; cv=none; b=MDBlgV6TvsRu6SI4Ws5/Oq8gBzygQmzb4J54JXYBBC1GaWOgklN7rH6672q3Jo+xWmvMblJQL7NJ21lZSvGcE3vzGtyVzXCBLC/WNM0+l3fADnppnO11vongstI8DO03dfi4lbisYGT6ZqfniIXsT4XGzYD4/knb/npfL8Vjv8A= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776999373; c=relaxed/simple; bh=9/CO8vx+V21oREl0OLJTEhDPgpJAF4/FGvx8E6oUzqk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=FI+PxQG57ynor2k5J/vOKZLTlqSbqFXA8qCK1KLypnAJ2PeXLjQ4eTnMtwElIr/7ql6xsYmzs3LlAYEugJqqIjmHF6s4oqQ2eTvKS/LXMgqECpLCVF3zXG27soqdFY2nSWTLxBv00cHhEXY3AXUi9IZu3+1QvQQSSveONk4jwsQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com; spf=pass smtp.mailfrom=bytedance.com; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b=YajlZVeG; arc=none smtp.client-ip=209.85.214.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bytedance.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b="YajlZVeG" Received: by mail-pl1-f175.google.com with SMTP id d9443c01a7336-2aaf59c4f7cso34587045ad.1 for ; Thu, 23 Apr 2026 19:56:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1776999367; x=1777604167; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=A4lJZQuHOoBwkCuOEzBR659IeprHDGyqMQmHH4+zCQA=; b=YajlZVeGPbLCqOu7hK93QpTyZSoew7cPPZGJfWl7a64Xb574NRIPwRSnStqUaju0Dd 0jsz7wlhHYY5NP4kO9SjHW0TcXJgNZ+UVzKLwI/eGC5C+MECd5CaBXZHkZwDR7R4tqt0 0ybRCavX/4k7Nu3NKGzy2YjqU0GfB2Hd7r5YG3gRGaCvO826MHyTa4NtmphhQaQZFiJU ElfcDRNsoPVt3bIERTF8CEzqNEFMxUIEWfr/Fh/syNz3nJpTNBNwDInFv/yP2x72l5+a XZe2eiEuk2M6wa22c8boqtumYs0pJPyeJXjcjx660PPNvXulAREtHQsC1DRdh5M1/aIU L4oQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776999367; x=1777604167; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=A4lJZQuHOoBwkCuOEzBR659IeprHDGyqMQmHH4+zCQA=; b=eYPBik26lC72LowViCi5skHkSCweKmNJXpdZRPP6C4BLQhdYQrrNy3YqgPOn21+517 3fPqA1COLYto79xV3xvDVQjOcyRGJMtok8tTjBnxfoos+8iAZFGq16v7hUb9U1OclVcJ Tcb664UqzaVE8y3oMxkUZZ+ZhPpMJQXz95OJYgpPa7tQR384OyelmcNMKrjNLzASaFxK /cHqSfCDkbqeDC+thwzyRFj5KxxhYBaAfFc4aE8oZjwoH8PnOIbLHaurwdli3gottOXx ADHavpUuI4JmQVS/oxRHNSQ552RtZ6xIJACz0OGNplYADjPpmqfWPGx4O8u/udK+QF6G CMFw== X-Forwarded-Encrypted: i=1; AFNElJ+1NTSZOjZe0LTQRYPqMEgP4kLzjVug6H4BFzlD7bOcFLcohy/mJ3Yd0nFwT7+/4NNWIJxWNHdXf7tR5OQ=@vger.kernel.org X-Gm-Message-State: AOJu0Yw5KlfTULJBMx4YUfQRkud1dw9ARfnKk/X27mUP+8xNVNI+sLxh WXfp6wK+TNkuOKG4rQYBHbxnbiGBEh5QmLqatdfaFjUwD2lD9BXWjyw40PyqMlg/y0Q= X-Gm-Gg: AeBDiesL3o2Rda2iC+ZmqBX2/Ve2FX04haP0Wz0n3a3/WN7f6ziC0hOGe8XOmwSEIo5 QsBgf/MOeCJkIbQE4F9vQH9yhHRcLoIzuy6W4y3AafRa+kP0Y5y7JszqfSZShRVSYBigmVEFGvm 9p5SbR9J22woHmDgo2O8SdiitQtcmq/qoMMNNUEYSIJQZfDFLvH2zTsnsvyZnbDBpxxWQKRy7rG iE90uSU5GkSoiWfNKfox5cRMedz6zMA2jeCOhrAMJovTrUxIV08pqbiqW4N8cWbPHjh6n2lkvR6 LPYWCkXtuyqjJF1/LS0hIF8ijN3pcle8TQugn3vZwwjQDOCWGXbF7sIsm3ChD4G7M9hMlXl0CnF mX7aowz7gaABaiuOuEEGDf/Q/VzIv45ADrF5/Zs7PukvBDFRhIl2gLEIkl9VHW5hYOp7H0zeCOx ZXfuOb5rXWeQLrzQ9qVNJJ2jqd8jf4jSk+7GRYzxyrrSx1LDq0WtOUknA= X-Received: by 2002:a17:903:2412:b0:2b2:42f8:1a4b with SMTP id d9443c01a7336-2b5f9f3a987mr327922445ad.27.1776999366531; Thu, 23 Apr 2026 19:56:06 -0700 (PDT) Received: from n232-176-004.byted.org ([36.110.163.102]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2b5fab20d33sm221668325ad.63.2026.04.23.19.56.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Apr 2026 19:56:06 -0700 (PDT) From: Muchun Song To: Andrew Morton , David Hildenbrand , Muchun Song , Oscar Salvador , Michael Ellerman , Madhavan Srinivasan Cc: Lorenzo Stoakes , "Liam R . Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , Nicholas Piggin , Christophe Leroy , aneesh.kumar@linux.ibm.com, joao.m.martins@oracle.com, linux-mm@kvack.org, linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, Muchun Song , stable@vger.kernel.org Subject: [PATCH v6 2/7] mm/memory_hotplug: Fix incorrect altmap passing in error path Date: Fri, 24 Apr 2026 10:55:42 +0800 Message-Id: <20260424025547.3806072-3-songmuchun@bytedance.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20260424025547.3806072-1-songmuchun@bytedance.com> References: <20260424025547.3806072-1-songmuchun@bytedance.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit In create_altmaps_and_memory_blocks(), when arch_add_memory() succeeds with memmap_on_memory enabled, the vmemmap pages are allocated from params.altmap. If create_memory_block_devices() subsequently fails, the error path calls arch_remove_memory() with a NULL altmap instead of params.altmap. This is a bug that could lead to memory corruption. Since altmap is NULL, vmemmap_free() falls back to freeing the vmemmap pages into the system buddy allocator via free_pages() instead of the altmap. arch_remove_memory() then immediately destroys the physical linear mapping for this memory. This injects unowned pages into the buddy allocator, causing machine checks or memory corruption if the system later attempts to allocate and use those freed pages. Fix this by passing params.altmap to arch_remove_memory() in the error path. Fixes: 6b8f0798b85a ("mm/memory_hotplug: split memmap_on_memory requests across memblocks") Cc: stable@vger.kernel.org Signed-off-by: Muchun Song Acked-by: David Hildenbrand (Arm) --- mm/memory_hotplug.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index 2a943ec57c85..0bad2aed2bde 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -1468,7 +1468,7 @@ static int create_altmaps_and_memory_blocks(int nid, struct memory_group *group, ret = create_memory_block_devices(cur_start, memblock_size, nid, params.altmap, group); if (ret) { - arch_remove_memory(cur_start, memblock_size, NULL); + arch_remove_memory(cur_start, memblock_size, params.altmap); kfree(params.altmap); goto out; } -- 2.20.1