ipv4: restrict IPOPT_SSRR and IPOPT_LSRR options
Subsystems (3)
PATCH 1/1 ipv4: restrict IPOPT_SSRR and IPOPT_LSRR options
This patch restricts setting Loose Source and Record Route (LSRR) and Strict Source and Record Route (SSRR) IP options to users with CAP_NET_RAW capability.
This prevents unprivileged applications from forcing packets to route through attacker-controlled nodes to leak TCP ISN and possibly other protocol information.
While LSRR and SSRR are commonly filtered in many network environments, they may still be supported and forwarded along some network paths.
RFC 7126 (Recommendations on Filtering of IPv4 Packets Containing IPv4 Options) recommend to drop these options in 4.3 and 4.4.
--- net/ipv4/ip_options.c | 4 ++++ 1 file changed, 4 insertions(+)
net/ipv4/ip_options.c +4 -0
@@ -283,6 +283,10 @@ int __ip_options_compile(struct net *net,switch (*optptr) {case IPOPT_SSRR :case IPOPT_LSRR : +if (!skb && !ns_capable (net->user_ns,CAP_NET_RAW )) { + pp_ptr = optptr; + goto error; + }if (optlen <3 ) { pp_ptr = optptr +1 ; goto error;
Signature · 1 line
2.54.0.1013.g208068f2d8-goog
Ido Schimmel
maintainerQuoted 27 lines · Eric Dumazet
This patch restricts setting Loose Source and Record Route (LSRR) and Strict Source and Record Route (SSRR) IP options to users with
CAP_NET_RAWcapability.This prevents unprivileged applications from forcing packets to route through attacker-controlled nodes to leak TCP ISN and possibly other protocol information.
While LSRR and SSRR are commonly filtered in many network environments, they may still be supported and forwarded along some network paths.
RFC 7126 (Recommendations on Filtering of IPv4 Packets Containing IPv4 Options) recommend to drop these options in 4.3 and 4.4.
Fixes 1da177e4c3f4 ("Linux-2.6.12-rc2")Reported-by Tamir Shahar <[email protected]>Reported-by Amit Klein <[email protected]>Signed-off-by Eric Dumazet <[email protected]>--- net/ipv4/ip_options.c | 4 ++++ 1 file changed, 4 insertions(+)net/ipv4/ip_options.c +0
-0
net/ipv4/ip_options.c int __ip_options_compile(struct net *net, · line 289
Quoted 7 lines
net/ipv4/ip_options.c +4
-0@@ -283,6 +283,10 @@ int __ip_options_compile(struct net *net,switch (*optptr) {case IPOPT_SSRR :case IPOPT_LSRR : +if (!skb && !ns_capable (net->user_ns,CAP_NET_RAW )) { + pp_ptr = optptr; + goto error; + }
This might be a problem for netfilter which calls __ip_options_compile() without an skb from ipv4_find_option().
AFAICT, user space can include IP options either using the IP_OPTIONS socket options or using the IP_RETOPTS cmsg, but the latter is not applicable to TCP.
If we put the check in do_ip_setsockopt(), we create a weird situation for non-TCP sockets: They can't set these IP options using IP_OPTIONS, but can set them via the IP_RETOPTS cmsg.
So maybe we should just put the check in ip_options_get() which is called from both paths? Something like:
net/ipv4/ip_options.c +4 -0
@@ -530,6 +530,10 @@ int ip_options_get(struct net *net, struct ip_options_rcu **optp,kfree (opt);return -EINVAL ; } +if (opt->opt.srr && !ns_capable (net->user_ns,CAP_NET_RAW )) { +kfree (opt); +return -EPERM ; + }kfree (*optp); *optp = opt;return 0 ;
Quoted 56 lines · Ido Schimmel
Quoted 27 lines · Eric Dumazet
This patch restricts setting Loose Source and Record Route (LSRR) and Strict Source and Record Route (SSRR) IP options to users with
CAP_NET_RAWcapability.This prevents unprivileged applications from forcing packets to route through attacker-controlled nodes to leak TCP ISN and possibly other protocol information.
While LSRR and SSRR are commonly filtered in many network environments, they may still be supported and forwarded along some network paths.
RFC 7126 (Recommendations on Filtering of IPv4 Packets Containing IPv4 Options) recommend to drop these options in 4.3 and 4.4.
Fixes 1da177e4c3f4 ("Linux-2.6.12-rc2")Reported-by Tamir Shahar <[email protected]>Reported-by Amit Klein <[email protected]>Signed-off-by Eric Dumazet <[email protected]>--- net/ipv4/ip_options.c | 4 ++++ 1 file changed, 4 insertions(+)net/ipv4/ip_options.c +0
-0net/ipv4/ip_options.c int __ip_options_compile(struct net *net, · line 289
Quoted 7 lines
net/ipv4/ip_options.c +4
-0@@ -283,6 +283,10 @@ int __ip_options_compile(struct net *net,switch (*optptr) {case IPOPT_SSRR :case IPOPT_LSRR : +if (!skb && !ns_capable (net->user_ns,CAP_NET_RAW )) { + pp_ptr = optptr; + goto error; + }This might be a problem for netfilter which calls
__ip_options_compile()without an skb fromipv4_find_option().AFAICT, user space can include IP options either using the
IP_OPTIONSsocket options or using theIP_RETOPTScmsg, but the latter is not applicable to TCP.If we put the check in
do_ip_setsockopt(), we create a weird situation for non-TCP sockets: They can't set these IP options usingIP_OPTIONS, but can set them via theIP_RETOPTScmsg.So maybe we should just put the check in
ip_options_get()which is called from both paths? Something like:net/ipv4/ip_options.c +0
-0
net/ipv4/ip_options.c int ip_options_get(struct net *net, struct ip_options_rcu **optp, · line 539
Quoted 10 lines
net/ipv4/ip_options.c +4
-0@@ -530,6 +530,10 @@ int ip_options_get(struct net *net, struct ip_options_rcu **optp,kfree (opt);return -EINVAL ; } +if (opt->opt.srr && !ns_capable (net->user_ns,CAP_NET_RAW )) { +kfree (opt); +return -EPERM ; + }kfree (*optp); *optp = opt;return 0 ;
SGTM, thanks a lot Ido, will send a V2 with your suggestion.