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 2FEC43914EB; Sat, 12 Sep 2026 15:46:39 +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=1789228001; cv=none; b=IOmUjBkjVBAr2rkcuJobMRhFxugqBLcSQHp+hLghuyVxFxtxTR0H5mF9ve7vKXLn3RDC/Xd5ZJMsirXlDL9Oe6rMluYetPUTsIA06Dl05DbSy8XKSJxnxyXtZmwt7gBkjOZPLHGKQfLkC/RWBGJ7i58kb5kPXNZ5it6Eic06gg0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789228001; c=relaxed/simple; bh=+qcpcevXQmtqssj8LH6cGQUDuOCPZJSrR5wrpnB2A14=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rTgPXgXYtOsJeNU2gOdMvDWbna/qiLpCQRRcfi8M3YgAC1NALWtNzlD48SrtSn+cYMrIV7gHdxF5iNB9tltDm0tGcI8t3ilVRR9Z5b2hF1dcGD7CYTcYmmk06UlWwGtXJsLH4Dz02fmGZtG/RfYKrWWioVglin77AWQh1xgRNaU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=R4QhHOWJ; 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="R4QhHOWJ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9D6D61F000FF; Sat, 12 Sep 2026 15:46:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1789227998; bh=vL46M8+2RMQsf7PDdBA8stk2I+SzoDqKFQyIAoXmyS8=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=R4QhHOWJbUOoFAg3kCaLK4KHEDysdEOqPO9qSWBwpWtwzgf0o5figGWmcseitkXZj aiRzfxWD74rvQJaRKCGMDLxwJaCixLtymXVMkYfMP40zuCNpHy5oiKkfFZJLET/ifv ces8FEd4ek4PjzjyQuNuSIrzUOkB9hdtkZmlTbro= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Sashiko , "Masami Hiramatsu (Google)" Subject: [PATCH 6.1 0297/1191] kprobes: Protect kprobe_blacklist with RCU Date: Sat, 12 Sep 2026 08:50:25 +0200 Message-ID: <20260912065554.901343655@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260912065548.086904252@linuxfoundation.org> References: <20260912065548.086904252@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.1-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 @@ -186,6 +186,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 @@ -1384,8 +1384,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; } @@ -2478,7 +2484,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; } @@ -2507,8 +2513,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); } }