From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.199 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796349399; b=uUGax4jCy+SJVfm0HlwY+md/FKnA3Zxu76EMXlQX2YFMlaOsTrZHvsyt4ZBOmUM/TTZg TIj8TVZJXBSE8IZ25JLxmQzQqoWcG27syfkazQVzgB5DvAj6MrhgE5qKjhDyO3AEvoBPK Zwi58ZrU24nIe92BohaDZNrWMqAqonM0isOqF35B5obaIIgZIl+HjdUDVqB00Auf9vPIV 2DD5e6GKRUmw+cGPg4kTxT8Aq1Q6Z+jS14o7a/+5aY9UPvE4uhsQ4u7Z1HLAtxODYUlH2 TdX80XJq109Q/tVMDgz97JtdWiie+9WIDTc6CZh7O7PwvIPQiKUe+5bXVfNT7FXbWPA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796349399; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Received:Date:In-Reply-To: Mime-Version:References:X-Mailer:Message-ID:Subject:From:To:Cc: Content-Type; bh=UEzxysLHUlnOk1XtNOc0ZHENXG047py1CawwP+iOaEU=; b=UDxEeqPSl9HCHKSP9EYDqDSmyUxIyQmNplASXi1VcxtUMUxDlMWgc3ZnTGc/EgG28R9G t/4AUWH0kxFQzDaka7m+ltWuAK8tiqg1XqMQTtUJqCV2yz851o4K3WP/RYCPikrIkce+E 9QifxgLqlUv/oWFpkzp90vDOBlLFGdhBmRpJbobmI2Wkx6kciVnCKzqlNZtLRE8Kv3ez+ ewHnxSbpM6/CZr3rkYYm5jWzmWcECAiFcRo/6vU5Iq1N0Z++rmjWpgfEq8LXCb8QAbwuf 9f9CknaU1GmzoN86s51iU2wYJfoD8OBa100FhdEAiZpOaLqhsY6UlnSy6DDT9/sSF4g== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=google.com; spf=pass smtp.mailfrom=flex--surenb.bounces.google.com; dkim=pass header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=B+T6cyRR; arc=none smtp.remote-ip=74.125.82.199 Received: from mail-dy1-f199.google.com (mail-dy1-f199.google.com [74.125.82.199]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 37CF7606A322 for ; Fri, 4 Dec 2026 01:56:39 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 37CF7606A322 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--surenb.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=B+T6cyRR Received: by mail-dy1-f199.google.com with SMTP id 5a478bee46e88-386a65fca25so821691eec.0 for ; Thu, 03 Dec 2026 17:56:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1796349398; x=1796954198; darn=lists.linux.dev; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=UEzxysLHUlnOk1XtNOc0ZHENXG047py1CawwP+iOaEU=; b=B+T6cyRR5jyUIgHk41XcWBQQC1v4ZTXhv2uq0J856s6fhIT8QYu2eiYuO5WsuoZqQP m1GubPV1/TUIBBOm9gOsQNvFiTqMK5rE0uySxaZMvZsaqAnVLCZZ+U9mvE2Cx+pLvLve QKyF0/zod/tzMN4H/GvNFtt3tX41GOMpqmTQ82Tf3vNCHvBs4GfacyXpkK9yau71q5Dy e6ICZ8Vk0ovna2xQrjRQBaEgTR2fuiJgnovNsVwar8pLRcg0UEZIELBwnCWXFw7BsmNw lqFu89xADGtoLO9u38uD07GudqhqLbef+DliwB5mbWqehP/LfofCE7AHjVBwpemxBiow 4uhQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796349398; x=1796954198; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=UEzxysLHUlnOk1XtNOc0ZHENXG047py1CawwP+iOaEU=; b=KdsiByIe+LNBrQ4w2LuqDn4aPvpd1ohtZJEMJMvC5K7MkrqLXC7NBxqhoVsudDQQ/i bjMTKHppkeQi94FsflbTmKXPjYivh8V+htCGQV8iPWiM88MVfhJprY3PxqDR1kCGetdc 2Nn1gH8YHiGn4FbCMxcVuG27Gn70s9tZ5xKvHdRuMbEJTgWjWB5xv4PGLwInuqOPS720 WYEI7K3L92SgmOFnk2YYovHYaoI7Ocs0YL4nVwARNWAAFfZOwe+adOFs6zRbfsOzURKb G1prnsXZwJdJFCTrikyx66uIz0acUii7vCvM03jvlNuUTxGm85NYr7/k5/HPAvvm+zGa kRNw== X-Forwarded-Encrypted: i=1; AL+hErFnDYdT4EOvAG60HncpIakUGHFOz47k9PYyCEIzq55GkEDEmON5CxiqQC4MU3pYsz6oqdLQOjWUHzxsrTCjYw==@lists.linux.dev X-Gm-Message-State: APuU4Z8OmBPj1gY/p3BeAMRULxVTwsNSG8aTIJN5DEFGwJKT/yb0Atct QAOgHl0NenvPP2ssvxDs5g/CsHr+VyqDaBe+jml0WEl/eF8vAs6iAfNqNoH7OB/oNSFm+nIGDs/ 5f0/KPA== X-Received: from dycne3.prod.google.com ([2002:a05:7301:c83:b0:383:9b3f:7909]) (user=surenb job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7301:d196:b0:386:b526:251e with SMTP id 5a478bee46e88-387520ee565mr593822eec.10.1796349397901; Thu, 03 Dec 2026 17:56:37 -0800 (PST) Date: Thu, 3 Dec 2026 17:56:29 -0800 In-Reply-To: <20261204015630.4095988-1-surenb@google.com> X-Mailing-List: linux-rt-devel@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Mime-Version: 1.0 References: <20261204015630.4095988-1-surenb@google.com> X-Mailer: git-send-email 2.56.1.987.g2ec0ab4260-goog Message-ID: <20261204015630.4095988-3-surenb@google.com> Subject: [PATCH 2/3] alloc_tag: do not leak module tag areas when removing them fails From: Suren Baghdasaryan To: akpm@linux-foundation.org Cc: david@kernel.org, hao.ge@linux.dev, liam@infradead.org, vbabka@kernel.org, hannes@cmpxchg.org, brendan.jackman@linux.dev, ziy@nvidia.com, bigeasy@linutronix.de, clrkwllms@kernel.org, rostedt@goodmis.org, pasha.tatashin@soleen.com, pyyjason@gmail.com, usamaarif642@gmail.com, surenb@google.com, linux-mm@kvack.org, linux-rt-devel@lists.linux.dev Content-Type: text/plain; charset="UTF-8" release_module_tags() removes the area of a module, and the padding in front of it, from mod_area_mt with mas_store(&mas, NULL). Storing NULL can merge the range with its neighbours and rebalance the tree, which needs new maple tree node allocations (with GFP_NOWAIT) and therefore can fail. If the allocation fails, the area stays in the tree and still points to the module that is going away. The maple state is left in the error state, so mas_prev_range() returns NULL and the padding is not removed either. If the allocation fails when the padding is removed, the padding is leaked. Use mas_erase() to remove the entries. It retries the allocation with the tree lock dropped and cannot fail. Dropping the lock is fine because all the changes to mod_area_mt are serialized by codetag_lock. Marking the area with unloaded_mod replaces the entry in place using mas_store() which does not allocate and therefore can't fail. Fixes: 0db6f8d7820a ("alloc_tag: load module tags into separate contiguous memory") Closes: https://sashiko.dev/#/bug/linux-55c2bd22-02fc-49f6-9ee7-e43117224340 Signed-off-by: Suren Baghdasaryan --- mm/alloc_tag.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/mm/alloc_tag.c b/mm/alloc_tag.c index b4e55bbf57f6..7c12053445fe 100644 --- a/mm/alloc_tag.c +++ b/mm/alloc_tag.c @@ -1087,10 +1087,20 @@ static void release_module_tags(struct module *mod, bool used) used = false; } release_area: - mas_store(&mas, used ? &unloaded_mod : NULL); + /* + * Replacing the entry in place does not need new maple tree nodes and + * cannot fail. Removing it might, and mas_store() allocates them with + * GFP_NOWAIT. A failure would leave the area reserved forever, with a + * stale module pointer in it. Use mas_erase(), which does not fail. + */ + if (used) + mas_store(&mas, &unloaded_mod); + else + mas_erase(&mas); + val = mas_prev_range(&mas, 0); if (val == &prepend_mod) - mas_store(&mas, NULL); + mas_erase(&mas); out: mas_unlock(&mas); } -- 2.56.1.987.g2ec0ab4260-goog