Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

tcp: Restrict SO_TXREHASH to TCP socket.

sk->sk_txrehash is only used for TCP.

Let's restrict SO_TXREHASH to TCP to reflect this.

Later, we will make sk_txrehash a part of the union for other
protocol families.

Note that we need to modify BPF selftest not to get/set
SO_TEREHASH for non-TCP sockets.

Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>
Reviewed-by: Willem de Bruijn <willemb@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Kuniyuki Iwashima and committed by
David S. Miller
ae4f2f59 38b95d58

+16
+5
net/core/sock.c
··· 1276 1276 return 0; 1277 1277 } 1278 1278 case SO_TXREHASH: 1279 + if (!sk_is_tcp(sk)) 1280 + return -EOPNOTSUPP; 1279 1281 if (val < -1 || val > 1) 1280 1282 return -EINVAL; 1281 1283 if ((u8)val == SOCK_TXREHASH_DEFAULT) ··· 2104 2102 break; 2105 2103 2106 2104 case SO_TXREHASH: 2105 + if (!sk_is_tcp(sk)) 2106 + return -EOPNOTSUPP; 2107 + 2107 2108 /* Paired with WRITE_ONCE() in sk_setsockopt() */ 2108 2109 v.val = READ_ONCE(sk->sk_txrehash); 2109 2110 break;
+11
tools/testing/selftests/bpf/progs/setget_sockopt.c
··· 83 83 struct sock *sk; 84 84 }; 85 85 86 + static bool sk_is_tcp(struct sock *sk) 87 + { 88 + return (sk->__sk_common.skc_family == AF_INET || 89 + sk->__sk_common.skc_family == AF_INET6) && 90 + sk->sk_type == SOCK_STREAM && 91 + sk->sk_protocol == IPPROTO_TCP; 92 + } 93 + 86 94 static int bpf_test_sockopt_flip(void *ctx, struct sock *sk, 87 95 const struct sockopt_test *t, 88 96 int level) ··· 98 90 int old, tmp, new, opt = t->opt; 99 91 100 92 opt = t->opt; 93 + 94 + if (opt == SO_TXREHASH && !sk_is_tcp(sk)) 95 + return 0; 101 96 102 97 if (bpf_getsockopt(ctx, level, opt, &old, sizeof(old))) 103 98 return 1;