BPF List
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Sasha Levin" <sashal@kernel.org>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH v3] killswitch: add per-function short-circuit mitigation primitive
Date: Sun, 17 May 2026 14:17:41 +0000	[thread overview]
Message-ID: <20260517141742.0856DC2BCB8@smtp.kernel.org> (raw)
In-Reply-To: <20260517134858.146569-1-sashal@kernel.org>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Calling __module_address() without rcu_read_lock() or module_mutex in ks_module_notify() triggers lockdep splats and risks a Use-After-Free.
- [Medium] The command parser in ks_control_write() rigidly fails with -EINVAL if there are multiple spaces or tabs between arguments.
--

commit 41367b8b3bd9a102ede7118d0216e23f583793b2
Author: Sasha Levin <sashal@kernel.org>

killswitch: add per-function short-circuit mitigation primitive

This commit introduces a killswitch mitigation primitive, which allows
an administrator to force a given function to return a specified value
without executing its body. This is intended to mitigate security issues
until a patch can be deployed. It is operated via a securityfs interface.

> diff --git a/kernel/killswitch.c b/kernel/killswitch.c
> new file mode 100644
> index 0000000000000..7f509c62ea748
> --- /dev/null
> +++ b/kernel/killswitch.c

[ ... ]

> +static int ks_module_notify(struct notifier_block *nb, unsigned long action,
> +			    void *data)
> +{
> +	struct module *mod = data;
> +	struct ks_attr *attr, *n;
> +
> +	if (action != MODULE_STATE_GOING)
> +		return NOTIFY_DONE;
> +
> +	mutex_lock(&ks_lock);
> +	list_for_each_entry_safe(attr, n, &ks_engaged_list, list) {
> +		if (!attr->kp.addr ||
> +		    __module_address((unsigned long)attr->kp.addr) != mod)

Does this need to be wrapped in an rcu_read_lock() and rcu_read_unlock()?

The __module_address() function traverses the RCU-protected module latch tree
and requires the caller to hold module_mutex or be within an RCU read-side
critical section.

The module subsystem drops the module_mutex before invoking the blocking
notifier chain, so this code executes without it.

Can this trigger a lockdep warning or risk a use-after-free if concurrent
operations modify the tree during traversal?

> +			continue;
> +
> +		pr_warn("killswitch: %s mitigation lost: module %s unloading; re-engage after reload if still needed\n",
> +			attr->kp.symbol_name, mod->name);

[ ... ]

> +static ssize_t ks_control_write(struct file *file, const char __user *ubuf,
> +				size_t count, loff_t *ppos)
> +{
> +	char *buf, *cur, *verb, *sym, *retstr;
> +	long retval = 0;
> +	int ret;

[ ... ]

> +	cur = strim(buf);
> +	verb = strsep(&cur, " \t\n");
> +	if (!verb || !*verb) {
> +		ret = -EINVAL;
> +		goto out;
> +	}
> +
> +	if (!strcmp(verb, "disengage_all")) {
> +		mutex_lock(&ks_lock);
> +		ks_disengage_all_locked();
> +		mutex_unlock(&ks_lock);
> +		ret = count;
> +		goto out;
> +	}
> +
> +	sym = strsep(&cur, " \t\n");
> +	if (!sym || !*sym) {

Is it possible for valid input to be rejected here if there are consecutive
spaces between tokens?

If a user or script writes "engage  my_func  0" with multiple spaces,
strsep() replaces the first space with a null terminator and returns an empty
string for the subsequent space.

The check !*sym would then interpret this empty token as invalid input and
abort with -EINVAL.

Would it be better to use skip_spaces() or a loop to handle natural variations
in whitespace?

> +		ret = -EINVAL;
> +		goto out;
> +	}
> +
> +	if (!strcmp(verb, "disengage")) {
> +		ret = __ks_disengage(sym);
> +		ret = ret ? ret : count;
> +		goto out;
> +	}
> +
> +	if (strcmp(verb, "engage")) {
> +		ret = -EINVAL;
> +		goto out;
> +	}
> +
> +	retstr = strsep(&cur, " \t\n");
> +	if (!retstr || !*retstr) {

Could this also fail similarly if there are consecutive spaces before the
return value token?

> +		ret = -EINVAL;
> +		goto out;
> +	}

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260517134858.146569-1-sashal@kernel.org?part=1

  reply	other threads:[~2026-05-17 14:17 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20260508195749.1885522-1-sashal@kernel.org>
2026-05-17 13:48 ` [PATCH v3] killswitch: add per-function short-circuit mitigation primitive Sasha Levin
2026-05-17 14:17   ` sashiko-bot [this message]
2026-05-17 19:19   ` Brandon Taylor
2026-05-18  5:23     ` Greg Kroah-Hartman
2026-05-18  6:37   ` Song Liu
2026-05-18 13:33     ` Sasha Levin
2026-05-18 23:59       ` Song Liu
2026-05-19  0:22         ` Sasha Levin
2026-05-19 12:13         ` Daniel Borkmann
2026-05-19 19:57           ` Sasha Levin
2026-05-19 22:00             ` Song Liu
2026-05-21 14:38               ` Sasha Levin
2026-05-21 18:02                 ` Song Liu
2026-05-21  9:11             ` Daniel Borkmann
2026-05-21 15:31               ` Sasha Levin
2026-05-21 18:16                 ` Song Liu
2026-05-23 13:41                   ` Sasha Levin
2026-05-26 13:10                     ` Daniel Borkmann
2026-05-26 14:29                       ` Sasha Levin
2026-05-18 23:52   ` Song Liu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260517141742.0856DC2BCB8@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=sashal@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox