From nobody Mon Dec 1 22:05:46 2025 Received: from smtp-relay-internal-1.canonical.com (smtp-relay-internal-1.canonical.com [185.125.188.123]) (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 53A8D30C63B for ; Mon, 1 Dec 2025 12:24:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.125.188.123 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764591867; cv=none; b=tbWmc9cHAze67TlW0Uz4EHgMPLB/G6jGba7nfvIl/BBF2Q5V1FekT4QjtquQWQZDUQSW+FKYp0AP6UFNivwEJo5NQ9AlLivHjUkGTGmM1tiLV12baQvv7i0oWK0NGBAjBsQB6MJAihrTLlyVhB5j3Rc+CZ0aoivPUilNWe2UGnM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764591867; c=relaxed/simple; bh=zX8NS3dWkP2kRHi9JuvLsUigUyl5bWfZvHSDrk2+hPs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=g4EYLn+14v0K0EX/HSQnS0xHV06g8+RQV6RWconpf4WCIakzmdwPlZNJe+bX2dS/4Plw+XgqXV6G8Oe7LOD8CbIY2/9j3lF9x/bP5HPaqfldmIPrK4qbH9xJYjR+2N2gtqH6UQlr8UPsSMsFKgIGbP8Wn2hMjFPA9/EgY6lUkQU= 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=hYjyGI8c; arc=none smtp.client-ip=185.125.188.123 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="hYjyGI8c" Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.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-1.canonical.com (Postfix) with ESMTPS id 706A93F182 for ; Mon, 1 Dec 2025 12:24:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20251003; t=1764591859; bh=GzOHE0e9hBLU7il+hYgcPRfRQ1LLK3xgtQjcXzvOJu8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=hYjyGI8c8XJXL7ztAscVs9vGSQAV8vwUxft8DWyLHfEOIiQS7HnfQny/3Sn1HXysN tlkBqqy4me8VIwbImaWQ/grRE8jt3H9YiqlJmW7WsSJGwA/TD+/p8bn40L+E4j+RJU lY78571Nesa5ENF8E5nIyMqRR38hUcoCIsE/Hhg4p/lQcWOozT4wICz5iTOPV6FHKx IcW66YBqutNbMYyOFPtwSS/wy4NG3Dj85DIoLf4LwZxieEktgovEpmDrsKCexcIVw6 5Z0y78r6t9g5IQZw+b/7+wYb2pOMaQcILnRg+vyVYJ7TjXHHWIxKe26UVySJO+aqIi Z3MNz0l6kmf1rCUsbt/3Ox53t+qzAhUDZVmcmwts4u50kq6n+kx6sYAfm+ipeudZUT eo6yadbmWlMMLPuQk//YWEQTzizUqJCNoX1tLKo53tQoXHlhXHw1LzHF8BX7Uv4AW9 riVRSJtLCf9odMo0suMCO0411hzpZZyC+CcxYlXub6VJ36HzGWMbu6Hpas9I4roR/P XMXrCMCH+ByXKDnw8UtzM9VTCyylMxxayTo8C2dNgUKv3IZTVlW7Oi5pruhpG5HAUz dTIWb0Or0ptOK9OJjBzTD4TkNDnFafc05eajMu1rTDsideQ6F+KRRDMYQV9Ydybfad N2Xq7QePuxsiP43Rhjxp29SA= Received: by mail-ed1-f69.google.com with SMTP id 4fb4d7f45d1cf-640c4609713so4865650a12.2 for ; Mon, 01 Dec 2025 04:24:19 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764591858; x=1765196658; 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=GzOHE0e9hBLU7il+hYgcPRfRQ1LLK3xgtQjcXzvOJu8=; b=oKK/zAvICk3YWUBtdJnz1qol53V1d8HMguUufdHs6+UZTTyfynoeMwwje78S4vxPNa 37kIJyDgK+RBG64M9v+UU/iIsRQWXI5w+MNFq05KlVWSKh1Wr6csVinlcCkSXlv2oqXm xXRpbUeYTaqgL6uuah3qbOoPMxjunMHafGNG1Iiy4H1EGH4dU93bQXWHzYX2ZMR722E8 yTrrfdrOJ22x+gkgCsS8g9omG2xE2Pa15BWr0gXwJAU6j5yvJLL/yUSSeoNIhyNoZkW8 AkqO4Dsbmvd0aTMpKrjwKFlJj6y1jAkcnMfDC2BYmpkp/Sf3FkF7e87+9Nl6AB/MVi4V 024Q== X-Forwarded-Encrypted: i=1; AJvYcCU8RJMtWZan6zKVoilvJZaKXucPlH6vyImtqXIuDKIi6mFVdVXDc8AG88R6eTAsiHKMblAa0p9XpMPwVSE=@vger.kernel.org X-Gm-Message-State: AOJu0Yx8biYwaSJCwBDSfRPJ2qk/ufKSZsKWz7EY4fPrerBgnsuE991N 073xV8f43UnQkHqrSv3/s9NMPRTo56wnRAO8Zg87I03c/lMlQu0UBnwIj071uEhsUsdpos/AKUa YZTu1LG6K1004ex69QAmey5fZ6CF6t8Wju3WU5qxZYGVtIbgvwHHGsqFdMXUXywux6YC33D+P+I fZ3QE5eA== X-Gm-Gg: ASbGncssPTyEJ+6spDhZqr9Uyra1vFu92XfaqDr22j5OYu9Zro33fxmE9NYKIXB0UeG EyFX7nA50xTfIw+tdj9wLl1XYoPxPOSgZM21Wcw5G/VjojWUS2tMdulboUzPVZXgRPyltV/DaTQ XpdQEuNs1sUhKJq+0siQVah9yY9VWxYILSX3XeuN05NjRzaxmXfMYWcF21nSypE03vc+n4L3zeG V/FnQ1R7Cq08IVCXBOISQ8pMh5Yxqm/4KD32Qj+WJffQ99SdM8NHAqMMk0jkREE7nLju6E8weWH EFRson1W12jYuL4v/0yKNUiX6vkEhbC2wlEToNhweTqvEynrjJTxiakEEQTdK9V5FZNSpNFuZLF eP/wf3vNo4JnD9Gd6ck50z92UQczpCpYVa4EPPuO616Xe3ITnHlGoexJsGXJ9ax3Xlh8PR5wN7w 7TDcJCI+u1PH1HK0GpMPqP7ePO X-Received: by 2002:a05:6402:26c1:b0:647:5c87:8668 with SMTP id 4fb4d7f45d1cf-6475c8786c8mr12140911a12.14.1764591858553; Mon, 01 Dec 2025 04:24:18 -0800 (PST) X-Google-Smtp-Source: AGHT+IFnjM0Qzg6CtgwzGYH8gmhz+bLP0gt4lrDJ9TM3/lU3ORJOfhu2tpvth2CTJnOUWADyLTe8JA== X-Received: by 2002:a05:6402:26c1:b0:647:5c87:8668 with SMTP id 4fb4d7f45d1cf-6475c8786c8mr12140891a12.14.1764591858195; Mon, 01 Dec 2025 04:24:18 -0800 (PST) Received: from amikhalitsyn.lan (p200300cf5749de007c66abd95f8bdeba.dip0.t-ipconnect.de. [2003:cf:5749:de00:7c66:abd9:5f8b:deba]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-64750a6ea36sm12307884a12.2.2025.12.01.04.24.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Dec 2025 04:24:17 -0800 (PST) From: Alexander Mikhalitsyn To: kees@kernel.org Cc: linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, Andy Lutomirski , Will Drewry , Jonathan Corbet , Shuah Khan , Tycho Andersen , Andrei Vagin , Christian Brauner , =?UTF-8?q?St=C3=A9phane=20Graber?= , Alexander Mikhalitsyn Subject: [PATCH v1 2/6] seccomp: prepare seccomp_run_filters() to support more than one listener Date: Mon, 1 Dec 2025 13:23:59 +0100 Message-ID: <20251201122406.105045-3-aleksandr.mikhalitsyn@canonical.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251201122406.105045-1-aleksandr.mikhalitsyn@canonical.com> References: <20251201122406.105045-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 Prepare seccomp_run_filters() function to support more than one listener in the seccomp tree. In this patch, we only introduce a new struct seccomp_filter_matches with kdoc and modify seccomp_run_filters() signature correspondingly. No functional change intended. Cc: linux-doc@vger.kernel.org Cc: linux-kernel@vger.kernel.org Cc: Kees Cook Cc: Andy Lutomirski Cc: Will Drewry Cc: Jonathan Corbet Cc: Shuah Khan Cc: Tycho Andersen Cc: Andrei Vagin Cc: Christian Brauner Cc: St=C3=A9phane Graber Signed-off-by: Alexander Mikhalitsyn --- kernel/seccomp.c | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/kernel/seccomp.c b/kernel/seccomp.c index f944ea5a2716..c9a1062a53bd 100644 --- a/kernel/seccomp.c +++ b/kernel/seccomp.c @@ -237,6 +237,9 @@ struct seccomp_filter { /* Limit any path through the tree to 256KB worth of instructions. */ #define MAX_INSNS_PER_PATH ((1 << 18) / sizeof(struct sock_filter)) =20 +/* Limit number of listeners through the tree. */ +#define MAX_LISTENERS_PER_PATH 8 + /* * Endianness is explicitly ignored and left for BPF program authors to ma= nage * as per the specific architecture. @@ -391,18 +394,38 @@ static inline bool seccomp_cache_check_allow(const st= ruct seccomp_filter *sfilte } #endif /* SECCOMP_ARCH_NATIVE */ =20 +/** + * struct seccomp_filter_matches - container for seccomp filter match resu= lts + * + * @n: A number of filters matched. + * @filters: An array of (struct seccomp_filter) pointers. + * Holds pointers to filters that matched during evaluation. + * A first one in the array is the one with the least permissive + * action result. + * + * If final action result is less (or more) permissive than SECCOMP_RET_US= ER_NOTIF, + * only the most restrictive filter is stored in the array's first element. + * If final action result is SECCOMP_RET_USER_NOTIF, we need to track + * all filters that resulted in the same action to support multiple listen= ers + * in seccomp tree. + */ +struct seccomp_filter_matches { + unsigned char n; + struct seccomp_filter *filters[MAX_LISTENERS_PER_PATH]; +}; + #define ACTION_ONLY(ret) ((s32)((ret) & (SECCOMP_RET_ACTION_FULL))) /** * seccomp_run_filters - evaluates all seccomp filters against @sd * @sd: optional seccomp data to be passed to filters - * @match: stores struct seccomp_filter that resulted in the return value, + * @matches: array of struct seccomp_filter pointers that resulted in the = return value, * unless filter returned SECCOMP_RET_ALLOW, in which case it will * be unchanged. * * Returns valid seccomp BPF response codes. */ static u32 seccomp_run_filters(const struct seccomp_data *sd, - struct seccomp_filter **match) + struct seccomp_filter_matches *matches) { u32 ret =3D SECCOMP_RET_ALLOW; /* Make sure cross-thread synced filter points somewhere sane. */ @@ -425,7 +448,8 @@ static u32 seccomp_run_filters(const struct seccomp_dat= a *sd, =20 if (ACTION_ONLY(cur_ret) < ACTION_ONLY(ret)) { ret =3D cur_ret; - *match =3D f; + matches->n =3D 1; + matches->filters[0] =3D f; } } return ret; @@ -1252,6 +1276,7 @@ static int __seccomp_filter(int this_syscall, const b= ool recheck_after_trace) { u32 filter_ret, action; struct seccomp_data sd; + struct seccomp_filter_matches matches =3D {}; struct seccomp_filter *match =3D NULL; int data; =20 @@ -1263,7 +1288,9 @@ static int __seccomp_filter(int this_syscall, const b= ool recheck_after_trace) =20 populate_seccomp_data(&sd); =20 - filter_ret =3D seccomp_run_filters(&sd, &match); + filter_ret =3D seccomp_run_filters(&sd, &matches); + + match =3D matches.filters[0]; data =3D filter_ret & SECCOMP_RET_DATA; action =3D filter_ret & SECCOMP_RET_ACTION_FULL; =20 --=20 2.43.0