summaryrefslogtreecommitdiff
path: root/net
diff options
context:
space:
mode:
Diffstat (limited to 'net')
-rw-r--r--net/core/filter.c55
-rw-r--r--net/ipv6/af_inet6.c1
-rw-r--r--net/ipv6/ipv6_sockglue.c4
3 files changed, 27 insertions, 33 deletions
diff --git a/net/core/filter.c b/net/core/filter.c
index 33275460fe66..ee768bb5b5ab 100644
--- a/net/core/filter.c
+++ b/net/core/filter.c
@@ -5191,8 +5191,9 @@ static int sol_ip_sockopt(struct sock *sk, int optname,
KERNEL_SOCKPTR(optval), *optlen);
}
-static int sol_ipv6_setsockopt(struct sock *sk, int optname,
- char *optval, int optlen)
+static int sol_ipv6_sockopt(struct sock *sk, int optname,
+ char *optval, int *optlen,
+ bool getopt)
{
if (sk->sk_family != AF_INET6)
return -EINVAL;
@@ -5200,15 +5201,20 @@ static int sol_ipv6_setsockopt(struct sock *sk, int optname,
switch (optname) {
case IPV6_TCLASS:
case IPV6_AUTOFLOWLABEL:
- if (optlen != sizeof(int))
+ if (*optlen != sizeof(int))
return -EINVAL;
break;
default:
return -EINVAL;
}
+ if (getopt)
+ return ipv6_bpf_stub->ipv6_getsockopt(sk, SOL_IPV6, optname,
+ KERNEL_SOCKPTR(optval),
+ KERNEL_SOCKPTR(optlen));
+
return ipv6_bpf_stub->ipv6_setsockopt(sk, SOL_IPV6, optname,
- KERNEL_SOCKPTR(optval), optlen);
+ KERNEL_SOCKPTR(optval), *optlen);
}
static int __bpf_setsockopt(struct sock *sk, int level, int optname,
@@ -5222,7 +5228,7 @@ static int __bpf_setsockopt(struct sock *sk, int level, int optname,
else if (IS_ENABLED(CONFIG_INET) && level == SOL_IP)
return sol_ip_sockopt(sk, optname, optval, &optlen, false);
else if (IS_ENABLED(CONFIG_IPV6) && level == SOL_IPV6)
- return sol_ipv6_setsockopt(sk, optname, optval, optlen);
+ return sol_ipv6_sockopt(sk, optname, optval, &optlen, false);
else if (IS_ENABLED(CONFIG_INET) && level == SOL_TCP)
return sol_tcp_sockopt(sk, optname, optval, &optlen, false);
@@ -5240,43 +5246,30 @@ static int _bpf_setsockopt(struct sock *sk, int level, int optname,
static int __bpf_getsockopt(struct sock *sk, int level, int optname,
char *optval, int optlen)
{
- int err = 0, saved_optlen = optlen;
+ int err, saved_optlen = optlen;
- if (!sk_fullsock(sk))
- goto err_clear;
+ if (!sk_fullsock(sk)) {
+ err = -EINVAL;
+ goto done;
+ }
- if (level == SOL_SOCKET) {
+ if (level == SOL_SOCKET)
err = sol_socket_sockopt(sk, optname, optval, &optlen, true);
- } else if (IS_ENABLED(CONFIG_INET) && level == SOL_TCP) {
+ else if (IS_ENABLED(CONFIG_INET) && level == SOL_TCP)
err = sol_tcp_sockopt(sk, optname, optval, &optlen, true);
- } else if (IS_ENABLED(CONFIG_INET) && level == SOL_IP) {
+ else if (IS_ENABLED(CONFIG_INET) && level == SOL_IP)
err = sol_ip_sockopt(sk, optname, optval, &optlen, true);
- } else if (IS_ENABLED(CONFIG_IPV6) && level == SOL_IPV6) {
- struct ipv6_pinfo *np = inet6_sk(sk);
-
- if (optlen != sizeof(int) || sk->sk_family != AF_INET6)
- goto err_clear;
-
- /* Only some options are supported */
- switch (optname) {
- case IPV6_TCLASS:
- *((int *)optval) = (int)np->tclass;
- break;
- default:
- goto err_clear;
- }
- } else {
- goto err_clear;
- }
+ else if (IS_ENABLED(CONFIG_IPV6) && level == SOL_IPV6)
+ err = sol_ipv6_sockopt(sk, optname, optval, &optlen, true);
+ else
+ err = -EINVAL;
+done:
if (err)
optlen = 0;
if (optlen < saved_optlen)
memset(optval + optlen, 0, saved_optlen - optlen);
return err;
-err_clear:
- memset(optval, 0, optlen);
- return -EINVAL;
}
static int _bpf_getsockopt(struct sock *sk, int level, int optname,
diff --git a/net/ipv6/af_inet6.c b/net/ipv6/af_inet6.c
index cadc97852787..19732b5dce23 100644
--- a/net/ipv6/af_inet6.c
+++ b/net/ipv6/af_inet6.c
@@ -1058,6 +1058,7 @@ static const struct ipv6_bpf_stub ipv6_bpf_stub_impl = {
.inet6_bind = __inet6_bind,
.udp6_lib_lookup = __udp6_lib_lookup,
.ipv6_setsockopt = do_ipv6_setsockopt,
+ .ipv6_getsockopt = do_ipv6_getsockopt,
};
static int __init inet6_init(void)
diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
index d9887e3a6077..1193f5a5247d 100644
--- a/net/ipv6/ipv6_sockglue.c
+++ b/net/ipv6/ipv6_sockglue.c
@@ -1131,8 +1131,8 @@ static int compat_ipv6_get_msfilter(struct sock *sk, sockptr_t optval,
return 0;
}
-static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
- sockptr_t optval, sockptr_t optlen)
+int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
+ sockptr_t optval, sockptr_t optlen)
{
struct ipv6_pinfo *np = inet6_sk(sk);
int len;