From nobody Tue Feb 10 06:27:49 2026 Received: from smtp-relay-internal-0.canonical.com (smtp-relay-internal-0.canonical.com [185.125.188.122]) (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 B38D3311C07 for ; Thu, 11 Dec 2025 12:47:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.125.188.122 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765457237; cv=none; b=q5QTqFOStXTLIQUjq7v0e2atoxHf3XfOK4nWjZ3ISru//6ueyYwOuYNw8+H2ybJn2p9dw6GsXsUBGVqMfIh+MQs+QLu0F3bgCrOoRxbOfS6JxGG1vAvd9RXXaM2wnicv86W95PvXe1fMprG8UXixOqh0TfeVqsOZzfEmhnVde7Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765457237; c=relaxed/simple; bh=M8eRqkgPgBxM8ofhzKDpQ/IEnkN/a4YJtGuQ31KbvR8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=jvAhcBB2d1Uq8UA1jNENMU9s+N2w7YqJoqGO2AEOfx84vMDILZVITtVjzTp6N755P0pOPmSIJunEUherc0ymXaqYEq06tkl7i5yqrWDfHJZxhZTbIT2m0NsYMYwv3VZGsmnRpgjogDIPqR4GuPZb59LiaYKcfdWLQ2nf1XrCd84= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=canonical.com; spf=pass smtp.mailfrom=canonical.com; dkim=pass (4096-bit key) header.d=canonical.com header.i=@canonical.com header.b=sRRmFPEJ; arc=none smtp.client-ip=185.125.188.122 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=canonical.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=canonical.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (4096-bit key) header.d=canonical.com header.i=@canonical.com header.b="sRRmFPEJ" Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) (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 smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id 4274F3FB52 for ; Thu, 11 Dec 2025 12:46:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20251003; t=1765457213; bh=+VWHdEQoNsPgcwFXeNNGXSus+9dIrvpb6PWtF/9Odxg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=sRRmFPEJQQ+kSBCC7dIjAdfx3GFFJKyahXHVCzgBHxFEqJAmIbmDCChphnH8YM7SQ Quyxf8yOKRNCwejQ5Q0VXN9CqEJgHb1Wob9ne0abTlA6wj032bv/hLB/SeSoDhH/yU v72ufN4V6lHpMR0n66LiMB9YWP6i/Wl1wqwSP96GI7EGb09Lt/lmRicG253G0iMaTq jMHboEL+rBqn7dUd8aLsiWJSL/I/tGLxeryCmqjMZgW2vUHutq6zDkzXC0gr4RlwK0 6FHPHzSOnMvr044Rs/WONCbDtRyLvZhPjs0BKOlo2/nBlxe5RLkwJPCH1O1OndEhDP /j6CptyO66fb6ZCPi6N7OYpxhtA0bXI1gQyGVhT6VnrUXij4KiQnyPzSFluVO1ssPE A49mdLs0v1nRkg8XuLKHBCAuYZf1ZIw1R2FkQd+E3B6PSO3B92EN5h/4VF86Tpn+dR bqY7FJT4RBoqNh7adoZSvZoIX/swr11SsdTQZTenERWYhNLTeWo7K1g5HV1KL52WdB pfluVfML/s+VzH67REGKgfPBSjrtWLoadGnFGl7X4tVdngKJIwsGfCRIr3e/qDxPo2 JiS6cQio3ZJykw+rx4DOcap8YHDxrKKKociog2i1+LA0QSHOkdLRbJmPM5p/tAUFjm /wIdk87gqwzBRXSJkaZVOTSs= Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-4779981523fso445375e9.2 for ; Thu, 11 Dec 2025 04:46:53 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765457198; x=1766061998; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=+VWHdEQoNsPgcwFXeNNGXSus+9dIrvpb6PWtF/9Odxg=; b=KYDEklob6kPZDwuko1WGbf8VeOSq9XZa2/vrLKfTd39zLxhSh8j9Is8zSr9INz1Gfl sLRo4jHsEkFcYAXLu687XRAsAo/fmgZTd7cqcvR2p/uSbvANNVa+v3zvTWAWgIYTG7G2 0rTmVv1duI74msrd5dod0rOP1+GcDZR4uxQxjYYU3Io0ahBs7URFNY9Q/V82cj/OQZSA p9ngHCNztJMk3UwhhTbXszqsYKToTEkHYVL5IiZrlBtbx69iWhMShnqkpUGg3R1MDAbP gPeiM4edv4mpF1sVyzNfQ6VVORhyqayMlhTPqaTFQAIjdXnoplViQeIK9vaIeOlTLZiS v6rw== X-Gm-Message-State: AOJu0YyeDf9QxytiJlD4gtXJn3mIkTuKXLeWjbZW1LAjAeyiamkTnutW r+X8GSLNl/YyxPoZr7CoxR5SerO/zdYPYO8Tco8grbgvKvzcbM1cDSngKTrooEka/YzBQ8PY2VC 6x0bwUqZI4kiRg07vBH2GMpnxAlFXhr5SNgP+eJ5ZYLB6FuTiIAnHnRKarFVNqHWIIVJZWLk6Db 7bmXbLbg== X-Gm-Gg: AY/fxX4YJImUeTd6d3hwD10ulNDId/lrmUOxN7DHIb2fTSAImcxz1f8BhjKOX9UE+b2 M8s2PYl6bJqKcpdWaDUikqkb5fHmb/ZvpJyOAi7FBmL50nkWdKE8uXcQEJ3WmC8+pnTXPGUaFnF gR1iGclugal8bbpgvZDsUgBEQUBzpZmTNln26H9i99XACgJgB22N9mNcUFQySV/ZeFxv5y1tZ17 EELsgMMsM+JuZf7W0uAZgacgIBcCNBIhWpW90+RTR5mnpiwhQWHeavgf+tCh7B4udd1rgx1KoS0 lAZrxdor0QVWUhPZZP83mVzoDKXSvZYx4aAaaDDZGKFFugkS8P0+aMXDajnvoU0+NCynpsikEA9 QuROamdoIY/gWrIq5E793jsyq64tbU2+UurkZgevgc9kMBG/DeKhiQMpb4EMWevFVvbv56xQlba PyAlBrkls9UgZCq7Ghjucq7bI= X-Received: by 2002:a05:600c:8b73:b0:477:b642:9dbf with SMTP id 5b1f17b1804b1-47a8379c99bmr57493685e9.32.1765457197848; Thu, 11 Dec 2025 04:46:37 -0800 (PST) X-Google-Smtp-Source: AGHT+IGW5OJd4vXzfsiWREO4WnOPxV8GVFlOiBDlk4Bt0lWdwH50jp6/D3VvS3x72AqyIflrh1rrcA== X-Received: by 2002:a05:600c:8b73:b0:477:b642:9dbf with SMTP id 5b1f17b1804b1-47a8379c99bmr57493275e9.32.1765457197424; Thu, 11 Dec 2025 04:46:37 -0800 (PST) Received: from amikhalitsyn.lan (p200300cf57022000e6219d5798620e30.dip0.t-ipconnect.de. [2003:cf:5702:2000:e621:9d57:9862:e30]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-47a89f0d6f2sm32075905e9.13.2025.12.11.04.46.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Dec 2025 04:46:37 -0800 (PST) From: Alexander Mikhalitsyn To: kees@kernel.org Cc: linux-kernel@vger.kernel.org, bpf@vger.kernel.org, Andy Lutomirski , Will Drewry , Jonathan Corbet , Shuah Khan , Aleksa Sarai , Tycho Andersen , Andrei Vagin , Christian Brauner , =?UTF-8?q?St=C3=A9phane=20Graber?= , Alexander Mikhalitsyn Subject: [PATCH v3 5/7] seccomp: handle multiple listeners case Date: Thu, 11 Dec 2025 13:46:09 +0100 Message-ID: <20251211124614.161900-6-aleksandr.mikhalitsyn@canonical.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251211124614.161900-1-aleksandr.mikhalitsyn@canonical.com> References: <20251211124614.161900-1-aleksandr.mikhalitsyn@canonical.com> 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="utf-8" Content-Transfer-Encoding: quoted-printable If we have more than one listener in the tree and lower listener wants us to continue syscall (SECCOMP_USER_NOTIF_FLAG_CONTINUE) we must consult with upper listeners first, otherwise it is a clear seccomp restrictions bypass scenario. Cc: linux-kernel@vger.kernel.org Cc: bpf@vger.kernel.org Cc: Kees Cook Cc: Andy Lutomirski Cc: Will Drewry Cc: Jonathan Corbet Cc: Shuah Khan Cc: Aleksa Sarai Cc: Tycho Andersen Cc: Andrei Vagin Cc: Christian Brauner Cc: St=C3=A9phane Graber Signed-off-by: Alexander Mikhalitsyn --- kernel/seccomp.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 64 insertions(+), 1 deletion(-) diff --git a/kernel/seccomp.c b/kernel/seccomp.c index 1a139f9ef39b..51d0d8adaffb 100644 --- a/kernel/seccomp.c +++ b/kernel/seccomp.c @@ -1268,6 +1268,69 @@ static int seccomp_do_user_notification(struct secco= mp_filter *match, return -1; } =20 +/** + * seccomp_do_user_notifications - sends seccomp notifications to the user= space + * taking into account multiple filters with listeners. + * @match: seccomp filter we are notifying first + * @sd: seccomp data (syscall_nr, args, etc) to be passed to the userspace= listener + * + * Returns + * - -1 on success if userspace provided a reply for the syscall, + * - -1 on interrupted wait, + * - 0 on success if userspace requested to continue the syscall + */ +static int seccomp_do_user_notifications(struct seccomp_filter *f, + const struct seccomp_data *sd) +{ + if (seccomp_do_user_notification(f, sd)) + goto syscall_skip; + + /* + * This check is needed to keep an old behavior where the first + * (and only) listener decides what to do with the syscall. + * Note, that even if some of the upper-level filters have + * returned SECCOMP_RET_USER_NOTIF (but have no listener fd!), + * we must ignore them in this case. + * This is how it worked before nested listeners were introduced. + */ + if (f->first_listener) + goto syscall_continue; + + /* + * If userspace wants us to skip this syscall, do so. + * But if userspace wants to continue syscall, we + * must consult with the upper-level filters listeners + * and act accordingly. + */ + for (f =3D f->prev; f; f =3D f->prev) { + u32 cur_ret; + + /* + * We only interested in listeners, no matter if notify fd + * is closed or not. + */ + if (!f->notif) + continue; + + cur_ret =3D bpf_prog_run_pin_on_cpu(f->prog, sd); + if (ACTION_ONLY(cur_ret) !=3D SECCOMP_RET_USER_NOTIF) + continue; + + if (seccomp_do_user_notification(f, sd)) + goto syscall_skip; + + if (f->first_listener) + break; + } + +syscall_continue: + /* continue syscall */ + return 0; + +syscall_skip: + return -1; +} + static int __seccomp_filter(int this_syscall, const bool recheck_after_tra= ce) { u32 filter_ret, action; @@ -1347,7 +1410,7 @@ static int __seccomp_filter(int this_syscall, const b= ool recheck_after_trace) return 0; =20 case SECCOMP_RET_USER_NOTIF: - if (seccomp_do_user_notification(match, &sd)) + if (seccomp_do_user_notifications(match, &sd)) goto skip; =20 return 0; --=20 2.43.0