Patch "sctp: add bpf_bypass_getsockopt proto callback" has been added to the 5.15-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    sctp: add bpf_bypass_getsockopt proto callback

to the 5.15-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     sctp-add-bpf_bypass_getsockopt-proto-callback.patch
and it can be found in the queue-5.15 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit 8af62ddacd308c1ce7f55cc8fdaa7d5a63fce756
Author: Alexander Mikhalitsyn <alexander@xxxxxxxxxxxxx>
Date:   Thu May 11 15:25:06 2023 +0200

    sctp: add bpf_bypass_getsockopt proto callback
    
    [ Upstream commit 2598619e012cee5273a2821441b9a051ad931249 ]
    
    Implement ->bpf_bypass_getsockopt proto callback and filter out
    SCTP_SOCKOPT_PEELOFF, SCTP_SOCKOPT_PEELOFF_FLAGS and SCTP_SOCKOPT_CONNECTX3
    socket options from running eBPF hook on them.
    
    SCTP_SOCKOPT_PEELOFF and SCTP_SOCKOPT_PEELOFF_FLAGS options do fd_install(),
    and if BPF_CGROUP_RUN_PROG_GETSOCKOPT hook returns an error after success of
    the original handler sctp_getsockopt(...), userspace will receive an error
    from getsockopt syscall and will be not aware that fd was successfully
    installed into a fdtable.
    
    As pointed by Marcelo Ricardo Leitner it seems reasonable to skip
    bpf getsockopt hook for SCTP_SOCKOPT_CONNECTX3 sockopt too.
    Because internaly, it triggers connect() and if error is masked
    then userspace will be confused.
    
    This patch was born as a result of discussion around a new SCM_PIDFD interface:
    https://lore.kernel.org/all/20230413133355.350571-3-aleksandr.mikhalitsyn@xxxxxxxxxxxxx/
    
    Fixes: 0d01da6afc54 ("bpf: implement getsockopt and setsockopt hooks")
    Cc: Daniel Borkmann <daniel@xxxxxxxxxxxxx>
    Cc: Christian Brauner <brauner@xxxxxxxxxx>
    Cc: Stanislav Fomichev <sdf@xxxxxxxxxx>
    Cc: Neil Horman <nhorman@xxxxxxxxxxxxx>
    Cc: Marcelo Ricardo Leitner <marcelo.leitner@xxxxxxxxx>
    Cc: Xin Long <lucien.xin@xxxxxxxxx>
    Cc: linux-sctp@xxxxxxxxxxxxxxx
    Cc: linux-kernel@xxxxxxxxxxxxxxx
    Cc: netdev@xxxxxxxxxxxxxxx
    Suggested-by: Stanislav Fomichev <sdf@xxxxxxxxxx>
    Acked-by: Stanislav Fomichev <sdf@xxxxxxxxxx>
    Signed-off-by: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@xxxxxxxxxxxxx>
    Acked-by: Xin Long <lucien.xin@xxxxxxxxx>
    Signed-off-by: David S. Miller <davem@xxxxxxxxxxxxx>
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/net/sctp/socket.c b/net/sctp/socket.c
index 2bbc81ddb9e08..ed35d4a4c5253 100644
--- a/net/sctp/socket.c
+++ b/net/sctp/socket.c
@@ -8287,6 +8287,22 @@ static int sctp_getsockopt(struct sock *sk, int level, int optname,
 	return retval;
 }
 
+static bool sctp_bpf_bypass_getsockopt(int level, int optname)
+{
+	if (level == SOL_SCTP) {
+		switch (optname) {
+		case SCTP_SOCKOPT_PEELOFF:
+		case SCTP_SOCKOPT_PEELOFF_FLAGS:
+		case SCTP_SOCKOPT_CONNECTX3:
+			return true;
+		default:
+			return false;
+		}
+	}
+
+	return false;
+}
+
 static int sctp_hash(struct sock *sk)
 {
 	/* STUB */
@@ -9655,6 +9671,7 @@ struct proto sctp_prot = {
 	.shutdown    =	sctp_shutdown,
 	.setsockopt  =	sctp_setsockopt,
 	.getsockopt  =	sctp_getsockopt,
+	.bpf_bypass_getsockopt	= sctp_bpf_bypass_getsockopt,
 	.sendmsg     =	sctp_sendmsg,
 	.recvmsg     =	sctp_recvmsg,
 	.bind        =	sctp_bind,
@@ -9707,6 +9724,7 @@ struct proto sctpv6_prot = {
 	.shutdown	= sctp_shutdown,
 	.setsockopt	= sctp_setsockopt,
 	.getsockopt	= sctp_getsockopt,
+	.bpf_bypass_getsockopt	= sctp_bpf_bypass_getsockopt,
 	.sendmsg	= sctp_sendmsg,
 	.recvmsg	= sctp_recvmsg,
 	.bind		= sctp_bind,



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux