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 73C8139CD0E; Sat, 12 Sep 2026 11:39:37 +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=1789213178; cv=none; b=kJtpASYzJ8h4FQPIf7JwiXCe31hIOt3qC6r2hJPvSPPC6rQeWZ/LE/3YGGrNXxq004IZ59NudOzI4bvVDpKFddg+d+NOLzbcf0G12/A6yWGQDyFCh0gG0XruNPL2yRCL6EC/KO+4DfZatuSv8ORsbo7RnQLBvMVhz2zKBjclv2o= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789213178; c=relaxed/simple; bh=cTGMGFeMu7aqeVfVeLTJSSfQbbs82ixEAYnclswaEhM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lmcmIYUU5XcpwVBEExpLljXqZgIkLHjZeHj42TanDTN/VI2L84eEY79LhGrsDP4Qtf/N8ETqb39H95a1DXQ/l8JQ0PGQimFbeQqAAyCKZCv4chh89nJJc5gmwG2cimwZqWmmJYEPV8iyEviStx+AgrL97N1NC/ZHada5wk1V3Hc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=n825yyoH; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="n825yyoH" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5D4EE1F000FF; Sat, 12 Sep 2026 11:39:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1789213177; bh=wwTQaLFOc4F6ZoGJr3MLetuC6oWhhxvoXfpXFuvdZ3U=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=n825yyoHOObuQq6oec2lnwlNj50qVoBgpxfzw0DF90pAqGVDWt4h1GyWUZBnUXpnH GFwIXDMPKi0DGaxaPgSA8ZF6ne27552D2lB+w1ikhRJLLuCY7r4SCP2JInNINQyTRP 2FPjXizMFs+W5nRP6bLgS5HyS+c5tk/hBgN3dLik= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Sashiko , "Masami Hiramatsu (Google)" Subject: [PATCH 6.12 0068/1376] kprobes: Protect kprobe_blacklist with RCU Date: Sat, 12 Sep 2026 08:41:34 +0200 Message-ID: <20260912065609.074600634@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260912065607.535295758@linuxfoundation.org> References: <20260912065607.535295758@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: Masami Hiramatsu (Google) commit 0c4256196b3a105307e2235fbfd85e768bbcdd0f upstream. __within_kprobe_blacklist() traverses kprobe_blacklist without holding kprobe_mutex. When a module is unloaded, kprobe_remove_area_blacklist() removes blacklist entries and immediately frees them with kfree(). A concurrent call to within_kprobe_blacklist() can therefore dereference freed memory. Furthermore, within_kprobe_blacklist() can be called in atomic or non-preemptible contexts where the sleeping kprobe_mutex cannot be taken. Protect kprobe_blacklist with RCU. Use guard(rcu)() and list_for_each_entry_rcu() for traversal, list_add_tail_rcu() for insertions, list_del_rcu() for deletions, and kfree_rcu() to reclaim entries safely after a grace period. Link: https://lore.kernel.org/all/178810004323.64882.16493230858653316962.stgit@devnote2/ Fixes: 376e242429bf ("kprobes: Introduce NOKPROBE_SYMBOL() macro to maintain kprobes blacklist") Cc: stable@vger.kernel.org Reported-by: Sashiko Closes: https://lore.kernel.org/all/20260807155802.F06041F000E9@smtp.kernel.org/ Assisted-by: Antigravity:gemini-3.7-flash Signed-off-by: Masami Hiramatsu (Google) Signed-off-by: Greg Kroah-Hartman --- include/linux/kprobes.h | 1 + kernel/kprobes.c | 14 ++++++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) --- a/include/linux/kprobes.h +++ b/include/linux/kprobes.h @@ -181,6 +181,7 @@ struct kprobe_blacklist_entry { struct list_head list; unsigned long start_addr; unsigned long end_addr; + struct rcu_head rcu; }; #ifdef CONFIG_KPROBES --- a/kernel/kprobes.c +++ b/kernel/kprobes.c @@ -1393,8 +1393,14 @@ static bool __within_kprobe_blacklist(un /* * If 'kprobe_blacklist' is defined, check the address and * reject any probe registration in the prohibited area. + * Note: this can return true during transition period where + * (start_addr, end_addr) in the black list is shrinking + * but old entry has not been removed yet. This is acceptable + * because the worst case is that we reject more probes than + * we should. */ - list_for_each_entry(ent, &kprobe_blacklist, list) { + guard(rcu)(); + list_for_each_entry_rcu(ent, &kprobe_blacklist, list) { if (addr >= ent->start_addr && addr < ent->end_addr) return true; } @@ -2474,7 +2480,7 @@ int kprobe_add_ksym_blacklist(unsigned l ent->start_addr = entry; ent->end_addr = entry + size; INIT_LIST_HEAD(&ent->list); - list_add_tail(&ent->list, &kprobe_blacklist); + list_add_tail_rcu(&ent->list, &kprobe_blacklist); return (int)size; } @@ -2568,8 +2574,8 @@ static void kprobe_remove_area_blacklist list_for_each_entry_safe(ent, n, &kprobe_blacklist, list) { if (ent->start_addr < start || ent->start_addr >= end) continue; - list_del(&ent->list); - kfree(ent); + list_del_rcu(&ent->list); + kfree_rcu(ent, rcu); } }