l2tp: fix tunnel and session refcount leak on seq_file release
Subsystems (3)
PATCH v3 1/1 l2tp: fix tunnel and session refcount leak on seq_file release
In pppol2tp_proc_open() and l2tp_dfs_seq_open(), iteration state (pd->tunnel and pd->session) is kept in seq_file private data to allow iteration across multiple read() system calls.
However, if userspace closes /proc/net/pppol2tp or /sys/kernel/debug/l2tp/tunnels before reading to end-of-file (EOF), any tunnel or session reference stored in pd->tunnel / pd->session is left un-dropped when seq_file private data is freed.
Fix this by dropping any remaining pd->tunnel and pd->session references in pppol2tp_proc_release() and l2tp_dfs_seq_release() when closing the file.
---
v3: fix CONFIG_PROC_FS=n case (Paolo)
v2: https://lore.kernel.org/netdev/[email protected]/
net/l2tp/l2tp_debugfs.c | 4 +++ net/l2tp/l2tp_ppp.c | 56 ++++++++++++++++++++++++++++++++++++++--- 2 files changed, 57 insertions(+), 3 deletions(-)
net/l2tp/l2tp_debugfs.c +4 -0
@@ -306,6 +306,10 @@ static int l2tp_dfs_seq_release(struct inode *inode, struct file *file) seq = file->private_data; pd = seq->private; +if (pd->session) +l2tp_session_put (pd->session); +if (pd->tunnel) +l2tp_tunnel_put (pd->tunnel);if (pd->net)put_net_track (pd->net, &pd->ns_tracker);kfree (pd);
net/l2tp/l2tp_ppp.c +53 -3
77 lines not on this page · raw message
Signature · 1 line
2.55.0.679.g6767b8d81c-goog
This patch was applied to netdev/net.git (main) by Paolo Abeni <[email protected]>:
Hello:
This patch was applied to netdev/net.git (main)
by Paolo Abeni <[email protected]>:
Quoted 9 lines · On Tue, 11 Aug 2026 14:46:51 +0000 you wrote:
In
pppol2tp_proc_open()andl2tp_dfs_seq_open(), iteration state (pd->tunnelandpd->session) is kept inseq_fileprivate data to allow iteration across multipleread()system calls.However, if userspace closes
/proc/net/pppol2tpor/sys/kernel/debug/l2tp/tunnelsbefore reading to end-of-file (EOF), any tunnel or session reference stored inpd->tunnel/pd->sessionis left un-dropped whenseq_fileprivate data is freed.[...]
Here is the summary with links:
- [v3,net] l2tp: fix tunnel and session refcount leak on seq_file release
https://git.kernel.org/netdev/net/c/9006c116dd11
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html