[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20230919131038.GC39346@noisy.programming.kicks-ass.net>
Date: Tue, 19 Sep 2023 15:10:38 +0200
From: Peter Zijlstra <peterz@...radead.org>
To: Linus Torvalds <torvalds@...ux-foundation.org>
Cc: Bartosz Golaszewski <bartosz.golaszewski@...aro.org>,
Alexey Dobriyan <adobriyan@...il.com>,
linux-kernel@...r.kernel.org,
Linus Walleij <linus.walleij@...aro.org>,
akpm@...ux-foundation.org
Subject: Re: Buggy __free(kfree) usage pattern already in tree
On Tue, Sep 19, 2023 at 02:59:54PM +0200, Peter Zijlstra wrote:
> + scoped_guard (mutex_intr, &task->signal->cred_guard_mutex) {
>
> + scoped_guard (task_lock, task) {
> + retval = __ptrace_may_access(task, PTRACE_MODE_ATTACH_REALCREDS);
> + if (retval)
> + return retval;
> + }
>
> + scoped_guard (write_lock, &tasklist_lock) {
> + if (unlikely(task->exit_state))
> + return -EPERM;
> + if (task->ptrace)
> + return -EPERM;
>
> + task->ptrace = flags;
>
> + ptrace_link(task, current);
> +
> + /* SEIZE doesn't trap tracee on attach */
> + if (!seize)
> + send_sig_info(SIGSTOP, SEND_SIG_PRIV, task);
> +
> + ptrace_set_stopped(task);
> +
> + }
> +
> + goto success;
> }
> + return -ERESTARTNOINTR;
>
> +success:
> + /*
> + * We do not bother to change retval or clear JOBCTL_TRAPPING
> + * if wait_on_bit() was interrupted by SIGKILL. The tracer will
> + * not return to user-mode, it will exit and clear this bit in
> + * __ptrace_unlink() if it wasn't already cleared by the tracee;
> + * and until then nobody can ptrace this task.
> + */
> + wait_on_bit(&task->jobctl, JOBCTL_TRAPPING_BIT, TASK_KILLABLE);
> + proc_ptrace_connector(task, PTRACE_ATTACH);
> +
> + return 0;
This isn't exactly nice..
I tried something like:
scoped_cond_guard (mutex_intr, return -EINTR, &task->signal->cred_guard_mutex) {
...
}
Which I can make work, but then I also tried to capture my other case:
scoped_cond_guard (rwsem_down_intr, if (task) return -EINTR,
task ? &task->signal->exec_guard_mutex : NULL) {
...
}
But I can't get that to work because of that extra if, the not case
doesn't fall through and do the body.
Anyway, I'll poke more..
Powered by blists - more mailing lists