Re: [PATCH] seccomp: Add SECCOMP_CLONE_FILTER operation

From
Tom Hromatka <hidden>
Date
2025-09-04 14:26:47
Also in
bpf, linux-kselftest, lkml
Reply to
Alexei Starovoitov, 2025-09-03
On 9/3/25 4:44 PM, Alexei Starovoitov wrote:
On Wed, Sep 3, 2025 at 1:52 PM Tom Hromatka [off-list ref] wrote:
quoted
On 9/3/25 2:45 PM, Alexei Starovoitov wrote:
quoted
On Wed, Sep 3, 2025 at 1:38 PM Tom Hromatka [off-list ref] wrote:
quoted

+
+       spin_lock_irq(&current->sighand->siglock);
+       spin_lock_irq(&task->sighand->siglock);
+
+       if (atomic_read(&task->seccomp.filter_count) == 0) {
+               spin_unlock_irq(&task->sighand->siglock);
+               spin_unlock_irq(&current->sighand->siglock);
did you copy this pattern from somewhere ?
It's obviously buggy.
I tried to mimic the logic in copy_seccomp() in kernel/fork.c,
but as you point out, I probably messed it up :).

Do you have recommendations for a better design pattern?
Several things look wrong here.
Double _irq() is one obvious bug.
This snippet addresses the double irq issue.  I also added a
check to make sure that task != current.  (A user shouldn't
do that but who knows what they'll actually do.)

        if (task == current) {
                put_task_struct(task);
                return -EINVAL;
        }

        spin_lock_irq(&current->sighand->siglock);
        spin_lock(&task->sighand->siglock);

        if (atomic_read(&task->seccomp.filter_count) == 0) {
                spin_unlock(&task->sighand->siglock);
                spin_unlock_irq(&current->sighand->siglock);
                put_task_struct(task);
                return -EINVAL;
        }

        get_seccomp_filter(task);
        current->seccomp = task->seccomp;

        spin_unlock(&task->sighand->siglock);

        set_task_syscall_work(current, SECCOMP);

        spin_unlock_irq(&current->sighand->siglock);

Let me know if there are other fixes I need to add.

Thanks so much!

Tom
Thread (13 messages) 13 messages, 6 authors, last reply 2025-09-05
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help