From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5B0C527FB18 for ; Tue, 14 Apr 2026 16:48:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776185312; cv=none; b=uLOhrb/OIPu4r7sT/gRlJCo14nHd1DFdChHDDmYucgpS+TMO7RN7sMZZQovEKEtu6UzXaVFjoB/0Gw2+/a073rJwFJldeQtQTxQd0W9DQ3R7fZYRi7mU11PyZWhZKT3bwFE/wj+9X1NRnRYnMv6GB2KPGQ3GF8MT9Y4UBj8Z9eI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776185312; c=relaxed/simple; bh=3hR2njnT7RscECO/allhu911VlYJMrXNfxudKFEtiOU=; h=Date:From:To:Cc:Subject:Message-ID:MIME-Version:Content-Type: Content-Disposition:In-Reply-To; b=p+93ZGNDc3zEcuuP9PaaHFVqr7H2t/jrifda+G/k5rd77U/NrQJ63wDC0R+eoURDEKHN6L3eIJgBPotefYT2+XqRyfneDjb3cKPyiGw7/cZ0ctvgp76Yq20esvDX5+tbo0ET6DSzOkXOyiR9z8qC+R6pQB9qdWW52HUbznVEpZc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=a9DU8Y3g; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="a9DU8Y3g" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1776185310; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to; bh=U7zZbgDsmpcD5l43TqPUEsDDeTmo8/Ubh8efFwjMxsg=; b=a9DU8Y3gDmIKXK30BPxy6KX/Plk16vA5T+9nIcPyKRlSnF491tnyVAAN3CGqJTDzptrE/+ rdOuZK3Bk8WIGHfu2kSyBIOs4E7cGknTfPALIb7iY7PSWT1ygvUW67Y4KEPG4cEO4llVM5 c/hPsi7H9l5R/sJ7tQUfdwcZlkvFMPo= Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-20-d9aGQxjKPOqmoHhKc9ALEQ-1; Tue, 14 Apr 2026 12:48:26 -0400 X-MC-Unique: d9aGQxjKPOqmoHhKc9ALEQ-1 X-Mimecast-MFC-AGG-ID: d9aGQxjKPOqmoHhKc9ALEQ_1776185305 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id DDB20180049F; Tue, 14 Apr 2026 16:48:24 +0000 (UTC) Received: from fedora (unknown [10.44.48.62]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with SMTP id 93D25195608E; Tue, 14 Apr 2026 16:48:21 +0000 (UTC) Received: by fedora (nbSMTP-1.00) for uid 1000 oleg@redhat.com; Tue, 14 Apr 2026 18:48:24 +0200 (CEST) Date: Tue, 14 Apr 2026 18:48:20 +0200 From: Oleg Nesterov To: Andy Lutomirski , Kees Cook , Peter Zijlstra , Thomas Gleixner , Will Drewry Cc: Kusaram Devineni , Max Ver , linux-kernel@vger.kernel.org Subject: [RFC PATCH 2/2] seccomp: defer syscall_rollback() to get_signal() Message-ID: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Currently, seccomp_nack_syscall() calls syscall_rollback() immediately. Because this restores the original registers, the syscall exit path sees the original syscall number as the return value. This confuses audit_syscall_exit(), trace_syscall_exit(), and ptrace. Change seccomp_nack_syscall() to call syscall_set_return_value(-EINTR), and add the new check_force_sig_seccomp() helper called by get_signal() which does syscall_rollback() if the signal was sent by seccomp. Note that the si_code == SYS_SECCOMP check in check_force_sig_seccomp() is not 100% reliable, see the comment in check_force_sig_seccomp(), but I hope we don't really care. Reported-by: Max Ver Closes: https://lore.kernel.org/all/CABjJbFJO+p3jA1r0gjUZrCepQb1Fab3kqxYhc_PSfoqo21ypeQ@mail.gmail.com/ Signed-off-by: Oleg Nesterov --- kernel/seccomp.c | 4 ++-- kernel/signal.c | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/kernel/seccomp.c b/kernel/seccomp.c index cb8dd78791cd..a8d103054212 100644 --- a/kernel/seccomp.c +++ b/kernel/seccomp.c @@ -1258,8 +1258,8 @@ static int seccomp_do_user_notification(int this_syscall, static void seccomp_nack_syscall(int this_syscall, int data, bool force_coredump) { - /* Show the handler or coredump the original registers. */ - syscall_rollback(current, current_pt_regs()); + /* check_force_sig_seccomp() will restore the original registers */ + syscall_set_return_value(current, current_pt_regs(), -EINTR, 0); /* Let the filter pass back 16 bits of data. */ force_sig_seccomp(this_syscall, data, force_coredump); } diff --git a/kernel/signal.c b/kernel/signal.c index d65d0fe24bfb..b93e37517d6d 100644 --- a/kernel/signal.c +++ b/kernel/signal.c @@ -2796,6 +2796,24 @@ static void hide_si_addr_tag_bits(struct ksignal *ksig) } } +static inline void check_force_sig_seccomp(kernel_siginfo_t *info) +{ + /* + * See seccomp_nack_syscall(). Show the original registers to + * the handler or coredump. + * + * Note: a task can send a .si_code == SYS_SECCOMP signal to + * itself, but syscall_rollback() is harmless in this case. + * SYS_SECCOMP can also be missed if a prior SIGSYS was pending + * and blocked before force_sig_seccomp(), but in that case the + * seccomp siginfo is already lost anyway. + */ + if (IS_ENABLED(CONFIG_SECCOMP_FILTER)) { + if (info->si_code == SYS_SECCOMP) + syscall_rollback(current, current_pt_regs()); + } +} + bool get_signal(struct ksignal *ksig) { struct sighand_struct *sighand = current->sighand; @@ -2916,6 +2934,8 @@ bool get_signal(struct ksignal *ksig) if (!signr) break; /* will return 0 */ + check_force_sig_seccomp(&ksig->info); + if (unlikely(current->ptrace) && (signr != SIGKILL) && !(sighand->action[signr -1].sa.sa_flags & SA_IMMUTABLE)) { signr = ptrace_signal(signr, &ksig->info, type); -- 2.52.0