From nobody Tue Sep 9 21:31:46 2025 Received: from mailtransmit05.runbox.com (mailtransmit05.runbox.com [185.226.149.38]) (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 9F23F346A0D for ; Fri, 5 Sep 2025 11:12:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.226.149.38 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757070731; cv=none; b=f2ejx2fsrPsxQoLEySDQoAtCzx5gUB/w4M8nX34nqR2R49VcSfdTOPU6anNzAlc0eb0a8yHfTp9Rnie5hU3K2YbW8ItUYamgMT5ICQVKL0DsRkqdLruaSMFbzlkDmieYoOHOHmjEFU53p/iCqhkyvTp6K0+VLvQ60IsLyXZJhno= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757070731; c=relaxed/simple; bh=7Tsy7ROVoOHxxVMAnzKBn0Y5eMA7rE7joEcmL2lJBVk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=p1/tcMRf6IY+0UNydQYcQJPHoQSvpf08PwSFn4Dvzc9T3Ke39A2va4N4/NIH+5MQxRWE8zUkmywpyzazcC7F0B+d+0uRNnUo6Fm7sT6HV8lQXPR17I3cu8QsM6GtHXAnrpO+zqcbMpp3UDm5CeE4NzwZI0Off82LB1ALVFyOjeQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=rbox.co; spf=pass smtp.mailfrom=rbox.co; dkim=pass (2048-bit key) header.d=rbox.co header.i=@rbox.co header.b=daZ+R/x2; arc=none smtp.client-ip=185.226.149.38 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=rbox.co Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rbox.co Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rbox.co header.i=@rbox.co header.b="daZ+R/x2" Received: from mailtransmit02.runbox ([10.9.9.162] helo=aibo.runbox.com) by mailtransmit05.runbox.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.93) (envelope-from ) id 1uuUMQ-003THx-A3; Fri, 05 Sep 2025 13:12:06 +0200 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=rbox.co; s=selector1; h=Cc:To:In-Reply-To:References:Message-Id: Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date:From; bh=+pRX1EHWIu4uVLS1iKQ0e4UmcUny8V+/+FbSvwtoeV8=; b=daZ+R/x2+DfqwfHt7UmEv0f802 4zzpGOT3I0NOlRE6zmjhR4NBnX5u67d99vXvu0HMVURiQzhp/IOOAMGkwxSolHYkqHDwcipT3n6hC r9cAo/E2e93lksbAf92fBlQWLAjZYwFfxd0gQiouIs3Jo0ky9sPZY7GFx7NbegiBxJcJswT9nk0K8 bUNpMG0+NDLYRhDcqieQ1ScSvg9ZcRj1x6fQcbLYp6Wp+oKvBc9CtGX1C7Xm9HPZUCOGzbC8Ao6Yi V4URgJKchAebB+b8xMDbgKIVhmPnept/zuSZ7Y/rq/qUx8rZSCIFzcafJoUllhOl0/xQRPv2yt+pP 96BvdtYg==; Received: from [10.9.9.73] (helo=submission02.runbox) by mailtransmit02.runbox with esmtp (Exim 4.86_2) (envelope-from ) id 1uuUMP-0002Jd-OB; Fri, 05 Sep 2025 13:12:06 +0200 Received: by submission02.runbox with esmtpsa [Authenticated ID (604044)] (TLS1.2:ECDHE_SECP256R1__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.93) id 1uuUMA-002yZ1-19; Fri, 05 Sep 2025 13:11:50 +0200 From: Michal Luczaj Date: Fri, 05 Sep 2025 13:11:41 +0200 Subject: [PATCH bpf-next 1/5] selftests/bpf: sockmap_redir: Simplify try_recv() 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 Message-Id: <20250905-redir-test-pass-drop-v1-1-9d9e43ff40df@rbox.co> References: <20250905-redir-test-pass-drop-v1-0-9d9e43ff40df@rbox.co> In-Reply-To: <20250905-redir-test-pass-drop-v1-0-9d9e43ff40df@rbox.co> To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Eduard Zingerman , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Mykola Lysenko , Shuah Khan Cc: bpf@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Michal Luczaj X-Mailer: b4 0.14.2 try_recv() was meant to support both @expect_success cases, but all the callers use @expect_success=3Dfalse anyway. Drop the unused logic and fold = in MSG_DONTWAIT. Adapt callers. Subtle change here: recv() return value of 0 will also be considered (an unexpected) success. Signed-off-by: Michal Luczaj Reviewed-by: Jakub Sitnicki --- .../selftests/bpf/prog_tests/sockmap_redir.c | 25 +++++++++---------= ---- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/tools/testing/selftests/bpf/prog_tests/sockmap_redir.c b/tools= /testing/selftests/bpf/prog_tests/sockmap_redir.c index 9c461d93113db20de65ac353f92dfdbe32ffbd3b..c1bf1076e8152b7d83c3e07e2dc= e746b5a39cf7e 100644 --- a/tools/testing/selftests/bpf/prog_tests/sockmap_redir.c +++ b/tools/testing/selftests/bpf/prog_tests/sockmap_redir.c @@ -144,17 +144,14 @@ static void get_redir_params(struct redir_spec *redir, *redirect_flags =3D 0; } =20 -static void try_recv(const char *prefix, int fd, int flags, bool expect_su= ccess) +static void fail_recv(const char *prefix, int fd, int more_flags) { ssize_t n; char buf; =20 - errno =3D 0; - n =3D recv(fd, &buf, 1, flags); - if (n < 0 && expect_success) - FAIL_ERRNO("%s: unexpected failure: retval=3D%zd", prefix, n); - if (!n && !expect_success) - FAIL("%s: expected failure: retval=3D%zd", prefix, n); + n =3D recv(fd, &buf, 1, MSG_DONTWAIT | more_flags); + if (n >=3D 0) + FAIL("%s: unexpected success: retval=3D%zd", prefix, n); } =20 static void handle_unsupported(int sd_send, int sd_peer, int sd_in, int sd= _out, @@ -188,13 +185,13 @@ static void handle_unsupported(int sd_send, int sd_pe= er, int sd_in, int sd_out, } =20 /* Ensure queues are empty */ - try_recv("bpf.recv(sd_send)", sd_send, MSG_DONTWAIT, false); + fail_recv("bpf.recv(sd_send)", sd_send, 0); if (sd_in !=3D sd_send) - try_recv("bpf.recv(sd_in)", sd_in, MSG_DONTWAIT, false); + fail_recv("bpf.recv(sd_in)", sd_in, 0); =20 - try_recv("bpf.recv(sd_out)", sd_out, MSG_DONTWAIT, false); + fail_recv("bpf.recv(sd_out)", sd_out, 0); if (sd_recv !=3D sd_out) - try_recv("bpf.recv(sd_recv)", sd_recv, MSG_DONTWAIT, false); + fail_recv("bpf.recv(sd_recv)", sd_recv, 0); } =20 static void test_send_redir_recv(int sd_send, int send_flags, int sd_peer, @@ -257,15 +254,13 @@ static void test_send_redir_recv(int sd_send, int sen= d_flags, int sd_peer, =20 if (send_flags & MSG_OOB) { /* Fail reading OOB while in sockmap */ - try_recv("bpf.recv(sd_out, MSG_OOB)", sd_out, - MSG_OOB | MSG_DONTWAIT, false); + fail_recv("bpf.recv(sd_out, MSG_OOB)", sd_out, MSG_OOB); =20 /* Remove sd_out from sockmap */ xbpf_map_delete_elem(maps->out, &u32(0)); =20 /* Check that OOB was dropped on redirect */ - try_recv("recv(sd_out, MSG_OOB)", sd_out, - MSG_OOB | MSG_DONTWAIT, false); + fail_recv("recv(sd_out, MSG_OOB)", sd_out, MSG_OOB); =20 goto del_in; } --=20 2.50.1 From nobody Tue Sep 9 21:31:46 2025 Received: from mailtransmit04.runbox.com (mailtransmit04.runbox.com [185.226.149.37]) (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 CE3BC3451CC for ; Fri, 5 Sep 2025 11:11:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.226.149.37 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757070726; cv=none; b=ieYFwI4bnZuwmkiO5yXQc0uJuODtVAgTKmRRDH2A13Nvx9RxjVrs8zp7qmZaQAyiby4FJ0CBdxbXA3tckuonaPmDvDUjmcUPpkN5/mwkJ3KvF2vDP345bdHGnr56jht3vmIBB4gJss+P8pRwlVRAe+PSZ1YicMVv50iN8JGVQ6c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757070726; c=relaxed/simple; bh=5l2WmyIrw4huA09wl6EzkxVuMibO25q87hLx+ZzI/VI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=SiEGAXaFYAzrobOdIvckIwGtbpYAyE0UX2uyEpBL8gWCetyH0sHLcviYu0VUgOkGl1scyOP/Ky4bmayo4lTlZtnjF1uarawcv74DkhTwemLAQi4+DJOvyWqh3X19COVN3o6ipRmTyWrHSDNhJDQnIev634KuG3dMM4PdULmk2F4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=rbox.co; spf=pass smtp.mailfrom=rbox.co; dkim=pass (2048-bit key) header.d=rbox.co header.i=@rbox.co header.b=oXYlez50; arc=none smtp.client-ip=185.226.149.37 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=rbox.co Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rbox.co Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rbox.co header.i=@rbox.co header.b="oXYlez50" Received: from mailtransmit03.runbox ([10.9.9.163] helo=aibo.runbox.com) by mailtransmit04.runbox.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.93) (envelope-from ) id 1uuUME-003UQ7-16; Fri, 05 Sep 2025 13:11:54 +0200 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=rbox.co; s=selector1; h=Cc:To:In-Reply-To:References:Message-Id: Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date:From; bh=tNtuGg01lWaBXl/Af0XL6hoU9LuTDSKEgUeGslbsWt4=; b=oXYlez50bt20WSNhQDLhduPHNd m9CcOgL/j6H789vkbYAhzrAgaH8JghjdQbCh7KnPCU5MDzddOpTVp2JMMVZx7IKFGlwZ6LwjlYRqC I9F1CGUTt4/D7Ofc+INuTxukPdnaD0WgU2ZDiRBsqnXpsCR9+eLAsDsHegQXTqB1y+x8FdYAcR/00 bUtB5Y4fcmeRoQTgQIh0EEFpgk4I7+/7+RQXne6ydWo2/Ce+oG+gi2/hhoMNPPBRc5SZxW8VHt6p1 iy1k2EUy5tJNdLVS1VVH7e4Z1NxXgU0Xm399ftttwWb9uFEKEuP9Vkl4cDmtuqXwE/pAU+LVvOKLH +EhTRsxw==; Received: from [10.9.9.73] (helo=submission02.runbox) by mailtransmit03.runbox with esmtp (Exim 4.86_2) (envelope-from ) id 1uuUMD-00006H-8d; Fri, 05 Sep 2025 13:11:53 +0200 Received: by submission02.runbox with esmtpsa [Authenticated ID (604044)] (TLS1.2:ECDHE_SECP256R1__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.93) id 1uuUMB-002yZ1-0q; Fri, 05 Sep 2025 13:11:51 +0200 From: Michal Luczaj Date: Fri, 05 Sep 2025 13:11:42 +0200 Subject: [PATCH bpf-next 2/5] selftests/bpf: sockmap_redir: Fix OOB handling 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 Message-Id: <20250905-redir-test-pass-drop-v1-2-9d9e43ff40df@rbox.co> References: <20250905-redir-test-pass-drop-v1-0-9d9e43ff40df@rbox.co> In-Reply-To: <20250905-redir-test-pass-drop-v1-0-9d9e43ff40df@rbox.co> To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Eduard Zingerman , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Mykola Lysenko , Shuah Khan Cc: bpf@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Michal Luczaj X-Mailer: b4 0.14.2 In some test cases, OOB packets might have been left unread. Flush them out and introduce additional checks. Signed-off-by: Michal Luczaj --- tools/testing/selftests/bpf/prog_tests/sockmap_redir.c | 16 ++++++++++++++= ++ 1 file changed, 16 insertions(+) diff --git a/tools/testing/selftests/bpf/prog_tests/sockmap_redir.c b/tools= /testing/selftests/bpf/prog_tests/sockmap_redir.c index c1bf1076e8152b7d83c3e07e2dce746b5a39cf7e..4997e72c14345b274367f3f2f41= 15c39d1ae48c9 100644 --- a/tools/testing/selftests/bpf/prog_tests/sockmap_redir.c +++ b/tools/testing/selftests/bpf/prog_tests/sockmap_redir.c @@ -184,6 +184,19 @@ static void handle_unsupported(int sd_send, int sd_pee= r, int sd_in, int sd_out, FAIL_ERRNO("unsupported: packet missing, retval=3D%zd", n); } =20 + /* af_unix send("ab", MSG_OOB) spits out 2 packets, but only the latter + * ("b") is designated OOB. If the peer is in a sockmap, the OOB packet + * will be silently dropped. Otherwise OOB stays in the queue and should + * be taken care of. + */ + if ((send_flags & MSG_OOB) && !pass && !drop) { + errno =3D 0; + n =3D recv_timeout(sd_peer, &recv_buf, 1, MSG_OOB, IO_TIMEOUT_SEC); + /* Ignore unsupported sk_msg error */ + if (n !=3D 1 && errno !=3D EOPNOTSUPP) + FAIL_ERRNO("recv(OOB): retval=3D%zd", n); + } + /* Ensure queues are empty */ fail_recv("bpf.recv(sd_send)", sd_send, 0); if (sd_in !=3D sd_send) @@ -192,6 +205,9 @@ static void handle_unsupported(int sd_send, int sd_peer= , int sd_in, int sd_out, fail_recv("bpf.recv(sd_out)", sd_out, 0); if (sd_recv !=3D sd_out) fail_recv("bpf.recv(sd_recv)", sd_recv, 0); + + fail_recv("recv(sd_peer, OOB)", sd_peer, MSG_OOB); + fail_recv("recv(sd_out, OOB)", sd_out, MSG_OOB); } =20 static void test_send_redir_recv(int sd_send, int send_flags, int sd_peer, --=20 2.50.1 From nobody Tue Sep 9 21:31:46 2025 Received: from mailtransmit04.runbox.com (mailtransmit04.runbox.com [185.226.149.37]) (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 3CC7F3451DC for ; Fri, 5 Sep 2025 11:12:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.226.149.37 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757070728; cv=none; b=BLiT7/VsJZT2mzcVuhGJhGHGVRmJEanhdRuPwGr+nFYirk5qbYCNH5Oh2aHhIm5uck8EmlJQcba5wiE/4Ghl02VNtY68Ip8i921kaZfrpf8iZpedjL/0WGVffMmAvs8LPuBdzA3Zr67qUtbpVs7j5PC2+N9gea/lP3MnOofNTx4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757070728; c=relaxed/simple; bh=uFSjXhlUsJWf4M8iMNwEYj1BtPc+bInOKVbCCpbhzLk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=nQYTKUnQ7GOtjC70YAHw7SI9iOXAVEFX3InDAzPW/0kyQcyfyauZWlTQGlw3Ua7ERpyszA1tvTdwvOR76a+KFrKOHmZlGNsyOZvS8H5tzIhH/CQeOTHovh2+/OotgBk05YavMts4lxNiz5qFTUTv1jgoeAhItC/+/2uQ391f6RA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=rbox.co; spf=pass smtp.mailfrom=rbox.co; dkim=pass (2048-bit key) header.d=rbox.co header.i=@rbox.co header.b=OScDwel8; arc=none smtp.client-ip=185.226.149.37 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=rbox.co Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rbox.co Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rbox.co header.i=@rbox.co header.b="OScDwel8" Received: from mailtransmit02.runbox ([10.9.9.162] helo=aibo.runbox.com) by mailtransmit04.runbox.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.93) (envelope-from ) id 1uuUMN-003UQX-EZ; Fri, 05 Sep 2025 13:12:03 +0200 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=rbox.co; s=selector1; h=Cc:To:In-Reply-To:References:Message-Id: Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date:From; bh=8Ml/q57UnovbWFQocDRim2+luhY4OknJEfSmVdybkuI=; b=OScDwel8s11nxTMsFIDA9bxW7T sRmcXxT+LTpyHSsquN/PHS5Lx6S+yeS9jsZXjNhHfgAKUxwtxoloAf8dZ4QnTRC0IFXP8JGbtudiy EbJ6hvCRH+gSJVWHM0ulyQN/u6MB3h1IG1qOv6zRJ2WmBSoG10Bq2pT1zvc8gsYlzH0o5cSBSVtNE aFxbS8jzqdM+jszm8fs6Ggu38s0Kj5sI+T8sldenOnz6DMh29sFvgDGSwJY/X4APATmdog8OSjnJq Ry0yKziN0w1Gy99irgwo4g532aJSFkC+yygazNr79XdV2hLGAm6oEGHlVSbuA26lGGaz4PLNanxj5 SFBQzAFQ==; Received: from [10.9.9.73] (helo=submission02.runbox) by mailtransmit02.runbox with esmtp (Exim 4.86_2) (envelope-from ) id 1uuUMK-0002Gw-Te; Fri, 05 Sep 2025 13:12:02 +0200 Received: by submission02.runbox with esmtpsa [Authenticated ID (604044)] (TLS1.2:ECDHE_SECP256R1__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.93) id 1uuUMC-002yZ1-0N; Fri, 05 Sep 2025 13:11:52 +0200 From: Michal Luczaj Date: Fri, 05 Sep 2025 13:11:43 +0200 Subject: [PATCH bpf-next 3/5] selftests/bpf: sockmap_redir: Rename functions 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 Message-Id: <20250905-redir-test-pass-drop-v1-3-9d9e43ff40df@rbox.co> References: <20250905-redir-test-pass-drop-v1-0-9d9e43ff40df@rbox.co> In-Reply-To: <20250905-redir-test-pass-drop-v1-0-9d9e43ff40df@rbox.co> To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Eduard Zingerman , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Mykola Lysenko , Shuah Khan Cc: bpf@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Michal Luczaj X-Mailer: b4 0.14.2 Preparatory patch before adding SK_PASS/SK_DROP support: test_redir() =3D> test_sockets() test_socket() =3D> test_redir() test_send_redir_recv() =3D> test_send_recv() After the change (and the following patch) the call stack will be: serial_test_sockmap_redir test_map test_sockets test_redir test_send_recv (test_verdict) (test_send_recv) Signed-off-by: Michal Luczaj --- .../selftests/bpf/prog_tests/sockmap_redir.c | 25 +++++++++++-------= ---- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/tools/testing/selftests/bpf/prog_tests/sockmap_redir.c b/tools= /testing/selftests/bpf/prog_tests/sockmap_redir.c index 4997e72c14345b274367f3f2f4115c39d1ae48c9..9fc5b4dd323d8554e6dc89d06be= 9054612e41020 100644 --- a/tools/testing/selftests/bpf/prog_tests/sockmap_redir.c +++ b/tools/testing/selftests/bpf/prog_tests/sockmap_redir.c @@ -210,9 +210,8 @@ static void handle_unsupported(int sd_send, int sd_peer= , int sd_in, int sd_out, fail_recv("recv(sd_out, OOB)", sd_out, MSG_OOB); } =20 -static void test_send_redir_recv(int sd_send, int send_flags, int sd_peer, - int sd_in, int sd_out, int sd_recv, - struct maps *maps, int status) +static void test_send_recv(int sd_send, int send_flags, int sd_peer, int s= d_in, + int sd_out, int sd_recv, struct maps *maps, int status) { unsigned int drop, pass; char *send_buf =3D "ab"; @@ -335,9 +334,9 @@ static int get_support_status(enum prog_type type, cons= t char *in, return status; } =20 -static void test_socket(enum bpf_map_type type, struct redir_spec *redir, - struct maps *maps, struct socket_spec *s_in, - struct socket_spec *s_out) +static void test_redir(enum bpf_map_type type, struct redir_spec *redir, + struct maps *maps, struct socket_spec *s_in, + struct socket_spec *s_out) { int fd_in, fd_out, fd_send, fd_peer, fd_recv, flags, status; const char *in_str, *out_str; @@ -367,12 +366,12 @@ static void test_socket(enum bpf_map_type type, struc= t redir_spec *redir, if (!test__start_subtest(s)) return; =20 - test_send_redir_recv(fd_send, flags, fd_peer, fd_in, fd_out, fd_recv, - maps, status); + test_send_recv(fd_send, flags, fd_peer, fd_in, fd_out, fd_recv, maps, + status); } =20 -static void test_redir(enum bpf_map_type type, struct redir_spec *redir, - struct maps *maps) +static void test_sockets(enum bpf_map_type type, struct redir_spec *redir, + struct maps *maps) { struct socket_spec *s, sockets[] =3D { { AF_INET, SOCK_STREAM }, @@ -395,7 +394,7 @@ static void test_redir(enum bpf_map_type type, struct r= edir_spec *redir, =20 /* Intra-proto */ for (s =3D sockets; s < sockets + ARRAY_SIZE(sockets); s++) - test_socket(type, redir, maps, s, s); + test_redir(type, redir, maps, s, s); =20 /* Cross-proto */ for (int i =3D 0; i < ARRAY_SIZE(sockets); i++) { @@ -409,7 +408,7 @@ static void test_redir(enum bpf_map_type type, struct r= edir_spec *redir, in->sotype =3D=3D out->sotype)) continue; =20 - test_socket(type, redir, maps, in, out); + test_redir(type, redir, maps, in, out); } } out: @@ -460,7 +459,7 @@ static void test_map(enum bpf_map_type type) if (xbpf_prog_attach(prog_fd, maps.in, attach_type, 0)) return; =20 - test_redir(type, r, &maps); + test_sockets(type, r, &maps); =20 if (xbpf_prog_detach2(prog_fd, maps.in, attach_type)) return; --=20 2.50.1 From nobody Tue Sep 9 21:31:46 2025 Received: from mailtransmit04.runbox.com (mailtransmit04.runbox.com [185.226.149.37]) (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 DAED8342CBB; Fri, 5 Sep 2025 11:12:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.226.149.37 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757070729; cv=none; b=EPKNHEUQBc8lnd9hRcrpf8i/2CPrBrO7h6cRjUQmyEEN+bVvHYe6aOdwiPbc1/aIOjMHlrr7emUu1cJsHiIvGGzSnuOr3J+EP4WlYzwNUm1x1WXzoYYKh45legHOlbSkl0D54mrnpVJJC+klDMMiVUSjixDrKRFtXNH+ow9lel8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757070729; c=relaxed/simple; bh=Dp9qrhweroc3zKnQINaoYc9xx4s5tbRN5FpOMFLYIe4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ExQcf1zTR04TnH7Yyw+1AdUjeFUKRIIT3TjVBf1FsTtp/hnFayVxDERXiH/0vSMnx4sph6+uDoZwuy73mA2WxLMcxfOKiDNff2XJc/WHTIzGPEGieJD3zPXGl2QgKXC2URgRiYidv5xzynFIv+c6IWpAosMH++YuzrrXRTI0Wwg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=rbox.co; spf=pass smtp.mailfrom=rbox.co; dkim=pass (2048-bit key) header.d=rbox.co header.i=@rbox.co header.b=VDDUzwc5; arc=none smtp.client-ip=185.226.149.37 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=rbox.co Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rbox.co Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rbox.co header.i=@rbox.co header.b="VDDUzwc5" Received: from mailtransmit02.runbox ([10.9.9.162] helo=aibo.runbox.com) by mailtransmit04.runbox.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.93) (envelope-from ) id 1uuUMO-003UQh-KZ; Fri, 05 Sep 2025 13:12:04 +0200 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=rbox.co; s=selector1; h=Cc:To:In-Reply-To:References:Message-Id: Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date:From; bh=rVsHhBOsXNiF0cE1EN8PVJpEUHIXi3i0lXd+CCf7ckk=; b=VDDUzwc5WEdL4k2SWHKgpkMWQk Hq9+AFZy7IU5yAgP+Kks7dxRKbVc1k2koyTjzh4INf50UR8IA+m3XSQqzh2odgbIyl/xll4K+EckN 6snWGSijYVEMeygL/u8uuUO0h8wIhjKd/ufKcY4ucp5/mmxPCyY7a0ThrUXu2Ysmg9ShYG7Fpm3mw dIvc3eY8Y+UBbWxyMjRvvXal6i8jkqQ2acWdVLkqT7cUoQhewG7kTspPo+yJoQfKktOkOSPpDaZ/k yPYy2tc2YLZrKZu5V/kxIg/WcOA0vNe4KqBmAVcrDSzJE62+hsL3r14lY73Nx4WJ8O6TQ+wyqkGkG PaAMsHxw==; Received: from [10.9.9.73] (helo=submission02.runbox) by mailtransmit02.runbox with esmtp (Exim 4.86_2) (envelope-from ) id 1uuUMN-0002Ie-Aw; Fri, 05 Sep 2025 13:12:04 +0200 Received: by submission02.runbox with esmtpsa [Authenticated ID (604044)] (TLS1.2:ECDHE_SECP256R1__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.93) id 1uuUMC-002yZ1-Ur; Fri, 05 Sep 2025 13:11:53 +0200 From: Michal Luczaj Date: Fri, 05 Sep 2025 13:11:44 +0200 Subject: [PATCH bpf-next 4/5] selftests/bpf: sockmap_redir: Let test specify skel's redirect_type 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 Message-Id: <20250905-redir-test-pass-drop-v1-4-9d9e43ff40df@rbox.co> References: <20250905-redir-test-pass-drop-v1-0-9d9e43ff40df@rbox.co> In-Reply-To: <20250905-redir-test-pass-drop-v1-0-9d9e43ff40df@rbox.co> To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Eduard Zingerman , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Mykola Lysenko , Shuah Khan Cc: bpf@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Michal Luczaj X-Mailer: b4 0.14.2 Preparatory patch before adding SK_PASS/SK_DROP support: allow to dynamically switch BPF program's redirect_type. This way, after setting up for a redirection, test can make the BPF program skip the actual bpf_{sk,msg}_redirect_{map,hash} part and return a specified verdict. Signed-off-by: Michal Luczaj --- tools/testing/selftests/bpf/prog_tests/sockmap_redir.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/bpf/prog_tests/sockmap_redir.c b/tools= /testing/selftests/bpf/prog_tests/sockmap_redir.c index 9fc5b4dd323d8554e6dc89d06be9054612e41020..f89df1ca1174800d801f221a819= b099abf911450 100644 --- a/tools/testing/selftests/bpf/prog_tests/sockmap_redir.c +++ b/tools/testing/selftests/bpf/prog_tests/sockmap_redir.c @@ -371,7 +371,7 @@ static void test_redir(enum bpf_map_type type, struct r= edir_spec *redir, } =20 static void test_sockets(enum bpf_map_type type, struct redir_spec *redir, - struct maps *maps) + struct maps *maps, int *skel_redir_type) { struct socket_spec *s, sockets[] =3D { { AF_INET, SOCK_STREAM }, @@ -392,6 +392,8 @@ static void test_sockets(enum bpf_map_type type, struct= redir_spec *redir, if (socket_spec_pairs(s)) goto out; =20 + *skel_redir_type =3D type; + /* Intra-proto */ for (s =3D sockets; s < sockets + ARRAY_SIZE(sockets); s++) test_redir(type, redir, maps, s, s); @@ -451,7 +453,6 @@ static void test_map(enum bpf_map_type type) return; } =20 - skel->bss->redirect_type =3D type; maps.verd =3D bpf_map__fd(skel->maps.verdict_map); get_redir_params(r, skel, &prog_fd, &attach_type, &skel->bss->redirect_flags); @@ -459,7 +460,7 @@ static void test_map(enum bpf_map_type type) if (xbpf_prog_attach(prog_fd, maps.in, attach_type, 0)) return; =20 - test_sockets(type, r, &maps); + test_sockets(type, r, &maps, &skel->bss->redirect_type); =20 if (xbpf_prog_detach2(prog_fd, maps.in, attach_type)) return; --=20 2.50.1 From nobody Tue Sep 9 21:31:46 2025 Received: from mailtransmit05.runbox.com (mailtransmit05.runbox.com [185.226.149.38]) (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 67CD234A32D; Fri, 5 Sep 2025 11:12:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.226.149.38 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757070739; cv=none; b=GAMFHn78haTdVG+tUlxrJjxpr7FLdT32ZgxJgsB1uv88XsUUpFRsNgQyZZJTOD5rH5WumtAZ8uz5AfmTsA6wR57w7ZJ26UEXHJC2uj0y9boNZOW+NJQ+4zyoBPeeIN6hSICvgKMIAcgc18tc9PEiXqhf+dqjkPaNhABgV7UF4Vk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757070739; c=relaxed/simple; bh=t6Rj18HPnifnNiTJet0Gv+ZbNp1682MFTdRToJhRwwg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=gSMdFlTmJ/bXQ6FA6bQQncMcwu12/sDx0TR5HpJ21HJN3ZqcnDcMJfhPlimiFm87LQ13N6l86itBAhdE5RdwrDnrjUBpArDHBG1rZrDTPIaFQaYH09/E0tvVzPaEuQg2dSpXpWLjvfLeRVr1nKr0tvX+waFiFn23kIt3WAR5+c8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=rbox.co; spf=pass smtp.mailfrom=rbox.co; dkim=pass (2048-bit key) header.d=rbox.co header.i=@rbox.co header.b=lQsned7G; arc=none smtp.client-ip=185.226.149.38 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=rbox.co Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rbox.co Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rbox.co header.i=@rbox.co header.b="lQsned7G" Received: from mailtransmit02.runbox ([10.9.9.162] helo=aibo.runbox.com) by mailtransmit05.runbox.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.93) (envelope-from ) id 1uuUMY-003TJp-LR; Fri, 05 Sep 2025 13:12:14 +0200 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=rbox.co; s=selector1; h=Cc:To:In-Reply-To:References:Message-Id: Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date:From; bh=tPRtNOCc0T6RXMXNRg93pifV3fla/+JNX7dzc2AQnI4=; b=lQsned7G591sjWTg+WIeXFDsFP G6lUF3KH/00ujbWTTLtvPtPt5OWvmY3LH7PRnAs14sD3bOg+fmbL4k+6Nwt6ytSIJ5nsJO9yabOMZ 2C5gesKoyFpKoxb53IYmluP27TPjoVV81qGGJqBAoOXXSPIZlwVSduAIy43Og9+1F9gIMFPIbKXVT +7RsrbI34M/O5zXXsQbfq2maRdKZoBKzvO8zWl9PljcZAd1HTJ65lGWRxeyXTqbSLZb35zEeCwTEf xMLSypz2IEcaPlOrbbQuKaQqrpwU3sjndNntADiv++8XO2gCUvgtApF1YQ8RjXtST8++eOSvGSbcu JfWQzLWw==; Received: from [10.9.9.73] (helo=submission02.runbox) by mailtransmit02.runbox with esmtp (Exim 4.86_2) (envelope-from ) id 1uuUMY-0002K3-Ak; Fri, 05 Sep 2025 13:12:14 +0200 Received: by submission02.runbox with esmtpsa [Authenticated ID (604044)] (TLS1.2:ECDHE_SECP256R1__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.93) id 1uuUMD-002yZ1-UJ; Fri, 05 Sep 2025 13:11:54 +0200 From: Michal Luczaj Date: Fri, 05 Sep 2025 13:11:45 +0200 Subject: [PATCH bpf-next 5/5] selftests/bpf: sockmap_redir: Support no-redirect SK_DROP/SK_PASS 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 Message-Id: <20250905-redir-test-pass-drop-v1-5-9d9e43ff40df@rbox.co> References: <20250905-redir-test-pass-drop-v1-0-9d9e43ff40df@rbox.co> In-Reply-To: <20250905-redir-test-pass-drop-v1-0-9d9e43ff40df@rbox.co> To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Eduard Zingerman , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Mykola Lysenko , Shuah Khan Cc: bpf@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Michal Luczaj , Jiayuan Chen X-Mailer: b4 0.14.2 Add tests that make the BPF programs skip the actual redirect and immediately return SK_DROP/SK_PASS. Suggested-by: Jiayuan Chen Signed-off-by: Michal Luczaj --- .../selftests/bpf/prog_tests/sockmap_redir.c | 74 ++++++++++++++++++= +--- 1 file changed, 65 insertions(+), 9 deletions(-) diff --git a/tools/testing/selftests/bpf/prog_tests/sockmap_redir.c b/tools= /testing/selftests/bpf/prog_tests/sockmap_redir.c index f89df1ca1174800d801f221a819b099abf911450..4c752000bbd8c84684b2df81eb3= 89be953d8ba02 100644 --- a/tools/testing/selftests/bpf/prog_tests/sockmap_redir.c +++ b/tools/testing/selftests/bpf/prog_tests/sockmap_redir.c @@ -18,6 +18,10 @@ * AF_UNIX, SOCK_DGRAM * AF_VSOCK, SOCK_STREAM * AF_VSOCK, SOCK_SEQPACKET + * x + * SK_REDIRECT + * SK_DROP + * SK_PASS */ =20 #include @@ -65,6 +69,10 @@ */ #define UNSUPPORTED_RACY_VERD _BITUL(1) =20 +/* Mark for an immediate SK_DROP/SK_PASS, i.e. BPF program will not redire= ct. + */ +#define NO_REDIRECT _BITUL(2) + enum prog_type { SK_MSG_EGRESS, SK_MSG_INGRESS, @@ -154,8 +162,9 @@ static void fail_recv(const char *prefix, int fd, int m= ore_flags) FAIL("%s: unexpected success: retval=3D%zd", prefix, n); } =20 -static void handle_unsupported(int sd_send, int sd_peer, int sd_in, int sd= _out, - int sd_recv, int map_verd, int status) +static void handle_unsupported(int sd_send, int send_flags, int sd_peer, + int sd_in, int sd_out, int sd_recv, + int map_verd, int status) { unsigned int drop, pass; char recv_buf; @@ -171,7 +180,7 @@ static void handle_unsupported(int sd_send, int sd_peer= , int sd_in, int sd_out, goto get_verdict; } =20 - if (pass !=3D 0) { + if (pass && !(status & NO_REDIRECT)) { FAIL("unsupported: wanted verdict pass 0, have %u", pass); return; } @@ -237,14 +246,14 @@ static void test_send_recv(int sd_send, int send_flag= s, int sd_peer, int sd_in, FAIL("incomplete send"); if (n < 0) { /* sk_msg redirect combo not supported? */ - if (status & SUPPORTED || errno !=3D EACCES) + if (errno !=3D EACCES) FAIL_ERRNO("send"); goto out; } =20 - if (!(status & SUPPORTED)) { - handle_unsupported(sd_send, sd_peer, sd_in, sd_out, sd_recv, - maps->verd, status); + if (!(status & SUPPORTED) || (status & NO_REDIRECT)) { + handle_unsupported(sd_send, send_flags, sd_peer, sd_in, sd_out, + sd_recv, maps->verd, status); goto out; } =20 @@ -326,9 +335,10 @@ static int is_redir_supported(enum prog_type type, con= st char *in, static int get_support_status(enum prog_type type, const char *in, const char *out) { - int status =3D is_redir_supported(type, in, out); + int status =3D in ? is_redir_supported(type, in, out) : 0; =20 - if (type =3D=3D SK_SKB_INGRESS && strstarts(out, "v_")) + if ((type =3D=3D SK_SKB_INGRESS || type =3D=3D SK_SKB_EGRESS) && + strstarts(out, "v_")) status |=3D UNSUPPORTED_RACY_VERD; =20 return status; @@ -370,6 +380,41 @@ static void test_redir(enum bpf_map_type type, struct = redir_spec *redir, status); } =20 +static void test_verdict(enum bpf_map_type type, struct redir_spec *redir, + struct maps *maps, struct socket_spec *s_in, + enum sk_action action) +{ + int fd_in, fd_out, fd_send, fd_peer, fd_recv, flags, status; + char s[MAX_TEST_NAME]; + const char *s_str; + + fd_in =3D s_in->in[0]; + fd_out =3D s_in->in[1]; + fd_send =3D s_in->in[redir->idx_send]; + fd_peer =3D s_in->in[redir->idx_send ^ 1]; + fd_recv =3D s_in->in[redir->idx_send ^ 1]; + flags =3D s_in->send_flags; + + s_str =3D socket_kind_to_str(fd_in); + status =3D get_support_status(redir->prog_type, NULL, s_str); + status |=3D NO_REDIRECT; + + snprintf(s, sizeof(s), + "%-4s %-17s %-7s %-5s%6s", + /* hash sk_skb-to-ingress u_str pass (OOB) */ + type =3D=3D BPF_MAP_TYPE_SOCKMAP ? "map" : "hash", + redir->name, + s_str, + action =3D=3D SK_PASS ? "pass" : "drop", + flags & MSG_OOB ? "(OOB)" : ""); + + if (!test__start_subtest(s)) + return; + + test_send_recv(fd_send, flags, fd_peer, fd_in, fd_out, fd_recv, maps, + status); +} + static void test_sockets(enum bpf_map_type type, struct redir_spec *redir, struct maps *maps, int *skel_redir_type) { @@ -413,6 +458,17 @@ static void test_sockets(enum bpf_map_type type, struc= t redir_spec *redir, test_redir(type, redir, maps, in, out); } } + + /* No redirect: SK_DROP */ + *skel_redir_type =3D __MAX_BPF_MAP_TYPE + SK_DROP; + for (s =3D sockets; s < sockets + ARRAY_SIZE(sockets); s++) + test_verdict(type, redir, maps, s, SK_DROP); + + /* No redirect: SK_PASS */ + *skel_redir_type =3D __MAX_BPF_MAP_TYPE + SK_PASS; + for (s =3D sockets; s < sockets + ARRAY_SIZE(sockets); s++) + test_verdict(type, redir, maps, s, SK_PASS); + out: while (--s >=3D sockets) socket_spec_close(s); --=20 2.50.1