fix(kmod): abort init when /proc/vpnhide_targets cannot be created

`proc_create()` returns NULL on failure (typically OOM at boot or
/proc not yet mounted). The previous code stored the NULL into
`targets_entry` and continued — `pr_info(": loaded")` fired, the
kretprobes were registered, but userspace had no way to write the
target UID list, so the module silently filtered nothing.

Treat /proc/vpnhide_targets failure as fatal: log an error,
unregister any probes that did succeed, and return -ENOMEM so
insmod surfaces the failure to the caller. /proc/vpnhide_debug
stays best-effort — losing the debug toggle just means no verbose
logging, the rest of the module is still useful.
This commit is contained in:
okhsunrog 2026-04-26 15:44:54 +03:00
parent fccc0387a2
commit 5969ed9173

View file

@ -774,7 +774,21 @@ static int __init vpnhide_init(void)
* and the VPN Hide app (both root). Apps must not see the target list. */
targets_entry =
proc_create("vpnhide_targets", 0600, NULL, &targets_proc_ops);
if (!targets_entry) {
/* Without /proc/vpnhide_targets userspace cannot configure
* the target UID list, so the module would silently filter
* nothing fail loudly instead of pretending to work. */
pr_err(MODNAME
": proc_create(vpnhide_targets) failed; aborting\n");
for (i = 0; i < ARRAY_SIZE(probes); i++)
if (probes[i].registered)
unregister_kretprobe(probes[i].krp);
return -ENOMEM;
}
debug_entry = proc_create("vpnhide_debug", 0600, NULL, &debug_proc_ops);
if (!debug_entry)
pr_warn(MODNAME
": proc_create(vpnhide_debug) failed; debug toggle unavailable\n");
pr_info(MODNAME ": loaded — write UIDs to /proc/vpnhide_targets\n");
return 0;