From: Peter Zijlstra <peterz@infradead.org>
To: Jann Horn <jannh@google.com>
Cc: John Johansen <john.johansen@canonical.com>,
John Johansen <john@apparmor.net>,
Georgia Garcia <georgia.garcia@canonical.com>,
apparmor@lists.ubuntu.com, Paul Moore <paul@paul-moore.com>,
"Serge E. Hallyn" <serge@hallyn.com>,
James Morris <jmorris@namei.org>,
Christian Brauner <brauner@kernel.org>,
Al Viro <viro@zeniv.linux.org.uk>,
linux-security-module <linux-security-module@vger.kernel.org>,
kernel list <linux-kernel@vger.kernel.org>,
stable@vger.kernel.org
Subject: Re: [PATCH] apparmor: fix cred UAF caused by begin_current_label_crit_section()
Date: Thu, 6 Aug 2026 09:32:44 +0200 [thread overview]
Message-ID: <20260806073244.GM49951@noisy.programming.kicks-ass.net> (raw)
In-Reply-To: <20260714-fix-apparmor-cred-uaf-v1-1-be40e8c83b90@google.com>
On Tue, Jul 14, 2026 at 05:38:07PM +0200, Jann Horn wrote:
> diff --git a/include/linux/task_work.h b/include/linux/task_work.h
> index 0646804860ff..ce19fc14060c 100644
> --- a/include/linux/task_work.h
> +++ b/include/linux/task_work.h
> @@ -33,6 +33,7 @@ struct callback_head *task_work_cancel_match(struct task_struct *task,
> bool (*match)(struct callback_head *, void *data), void *data);
> struct callback_head *task_work_cancel_func(struct task_struct *, task_work_func_t);
> bool task_work_cancel(struct task_struct *task, struct callback_head *cb);
> +bool task_work_has_func(struct task_struct *task, task_work_func_t func);
> void task_work_run(void);
>
> static inline void exit_task_work(struct task_struct *task)
> diff --git a/kernel/task_work.c b/kernel/task_work.c
> index 0f7519f8e7c9..f83d1528e0bc 100644
> --- a/kernel/task_work.c
> +++ b/kernel/task_work.c
> @@ -189,6 +189,20 @@ bool task_work_cancel(struct task_struct *task, struct callback_head *cb)
> return ret == cb;
> }
>
> +bool task_work_has_func(struct task_struct *task, task_work_func_t func)
> +{
> + struct callback_head *work;
> +
> + if (!task_work_pending(task))
> + return false;
> + guard(raw_spinlock_irqsave)(&task->pi_lock);
> + for (work = READ_ONCE(task->task_works); work; work = READ_ONCE(work->next)) {
> + if (work->func == func)
> + return true;
> + }
> + return false;
> +}
> +
> /**
> * task_work_run - execute the works added by task_work_add()
> *
This thing is quite terrible. And AFAICT the only purpose is to
determine if said task already has said function enqueued. Why not add a
single bit to struct task_struct for this? I'm sure we have a spare bit
somewhere.
> +/* replace the current task's stale label on syscall return */
> +void aa_schedule_stale_label_replacement(void)
> +{
> + struct callback_head *tw;
> +
> + if (task_work_has_func(current, aa_replace_stale_label_tw_func))
> + return;
> + tw = kmalloc_obj(struct callback_head);
> + if (!tw)
> + return;
> + init_task_work(tw, aa_replace_stale_label_tw_func);
> + if (task_work_add(current, tw, TWA_RESUME))
> + kfree(tw);
> +}
next prev parent reply other threads:[~2026-08-06 7:32 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-14 15:38 Jann Horn
2026-07-14 15:49 ` Jann Horn
2026-08-05 15:10 ` Jann Horn
2026-08-05 23:13 ` John Johansen
2026-08-06 0:02 ` John Johansen
2026-08-06 13:14 ` Jann Horn
2026-08-06 7:32 ` Peter Zijlstra [this message]
2026-08-06 8:06 ` John Johansen
2026-08-06 13:11 ` Jann Horn
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=20260806073244.GM49951@noisy.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=apparmor@lists.ubuntu.com \
--cc=brauner@kernel.org \
--cc=georgia.garcia@canonical.com \
--cc=jannh@google.com \
--cc=jmorris@namei.org \
--cc=john.johansen@canonical.com \
--cc=john@apparmor.net \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-security-module@vger.kernel.org \
--cc=paul@paul-moore.com \
--cc=serge@hallyn.com \
--cc=stable@vger.kernel.org \
--cc=viro@zeniv.linux.org.uk \
/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
all inboxes | Powered by JetHome®