summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--pkg/abi/linux/netfilter.go52
-rw-r--r--pkg/sentry/socket/netfilter/netfilter.go26
-rw-r--r--pkg/tcpip/iptables/tcp_matcher.go122
3 files changed, 0 insertions, 200 deletions
diff --git a/pkg/abi/linux/netfilter.go b/pkg/abi/linux/netfilter.go
index fb4588272..f0e544f9c 100644
--- a/pkg/abi/linux/netfilter.go
+++ b/pkg/abi/linux/netfilter.go
@@ -341,58 +341,6 @@ func goString(cstring []byte) string {
return string(cstring)
}
-// XTTCP holds data for matching TCP packets. It corresponds to struct xt_tcp
-// in include/uapi/linux/netfilter/xt_tcpudp.h.
-type XTTCP struct {
- // SourcePortStart specifies the inclusive start of the range of source
- // ports to which the matcher applies.
- SourcePortStart uint16
-
- // SourcePortEnd specifies the inclusive end of the range of source ports
- // to which the matcher applies.
- SourcePortEnd uint16
-
- // DestinationPortStart specifies the start of the destination port
- // range to which the matcher applies.
- DestinationPortStart uint16
-
- // DestinationPortEnd specifies the start of the destination port
- // range to which the matcher applies.
- DestinationPortEnd uint16
-
- // Option specifies that a particular TCP option must be set.
- Option uint8
-
- // FlagMask masks the FlagCompare byte when comparing to the TCP flag
- // fields.
- FlagMask uint8
-
- // FlagCompare is binary and-ed with the TCP flag fields.
- FlagCompare uint8
-
- // InverseFlags flips the meaning of certain fields. See the
- // TX_TCP_INV_* flags.
- InverseFlags uint8
-}
-
-// SizeOfXTTCP is the size of an XTTCP.
-const SizeOfXTTCP = 12
-
-// Flags in XTTCP.InverseFlags. Corresponding constants are in
-// include/uapi/linux/netfilter/xt_tcpudp.h.
-const (
- // Invert the meaning of SourcePortStart/End.
- XT_TCP_INV_SRCPT = 0x01
- // Invert the meaning of DestinationPortStart/End.
- XT_TCP_INV_DSTPT = 0x02
- // Invert the meaning of FlagCompare.
- XT_TCP_INV_FLAGS = 0x04
- // Invert the meaning of Option.
- XT_TCP_INV_OPTION = 0x08
- // Enable all flags.
- XT_TCP_INV_MASK = 0x0F
-)
-
// XTUDP holds data for matching UDP packets. It corresponds to struct xt_udp
// in include/uapi/linux/netfilter/xt_tcpudp.h.
type XTUDP struct {
diff --git a/pkg/sentry/socket/netfilter/netfilter.go b/pkg/sentry/socket/netfilter/netfilter.go
index 45296b339..f8ed1acbc 100644
--- a/pkg/sentry/socket/netfilter/netfilter.go
+++ b/pkg/sentry/socket/netfilter/netfilter.go
@@ -131,7 +131,6 @@ func FillDefaultIPTables(stack *stack.Stack) {
stack.SetIPTables(ipt)
}
-// TODO: Return proto.
// convertNetstackToBinary converts the iptables as stored in netstack to the
// format expected by the iptables tool. Linux stores each table as a binary
// blob that can only be traversed by parsing a bit, reading some offsets,
@@ -456,31 +455,6 @@ func parseMatchers(filter iptables.IPHeaderFilter, optVal []byte) ([]iptables.Ma
var matcher iptables.Matcher
var err error
switch match.Name.String() {
- case "tcp":
- if len(buf) < linux.SizeOfXTTCP {
- log.Warningf("netfilter: optVal has insufficient size for TCP match: %d", len(optVal))
- return nil, syserr.ErrInvalidArgument
- }
- var matchData linux.XTTCP
- // For alignment reasons, the match's total size may exceed what's
- // strictly necessary to hold matchData.
- binary.Unmarshal(buf[:linux.SizeOfXTUDP], usermem.ByteOrder, &matchData)
- log.Infof("parseMatchers: parsed XTTCP: %+v", matchData)
- matcher, err = iptables.NewTCPMatcher(filter, iptables.TCPMatcherData{
- SourcePortStart: matchData.SourcePortStart,
- SourcePortEnd: matchData.SourcePortEnd,
- DestinationPortStart: matchData.DestinationPortStart,
- DestinationPortEnd: matchData.DestinationPortEnd,
- Option: matchData.Option,
- FlagMask: matchData.FlagMask,
- FlagCompare: matchData.FlagCompare,
- InverseFlags: matchData.InverseFlags,
- })
- if err != nil {
- log.Warningf("netfilter: failed to create TCP matcher: %v", err)
- return nil, syserr.ErrInvalidArgument
- }
-
case "udp":
if len(buf) < linux.SizeOfXTUDP {
log.Warningf("netfilter: optVal has insufficient size for UDP match: %d", len(optVal))
diff --git a/pkg/tcpip/iptables/tcp_matcher.go b/pkg/tcpip/iptables/tcp_matcher.go
deleted file mode 100644
index 6acbd6eb9..000000000
--- a/pkg/tcpip/iptables/tcp_matcher.go
+++ /dev/null
@@ -1,122 +0,0 @@
-// Copyright 2020 The gVisor Authors.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package iptables
-
-import (
- "fmt"
-
- "gvisor.dev/gvisor/pkg/log"
- "gvisor.dev/gvisor/pkg/tcpip"
- "gvisor.dev/gvisor/pkg/tcpip/header"
-)
-
-type TCPMatcher struct {
- data TCPMatcherData
-
- // tablename string
- // unsigned int matchsize;
- // unsigned int usersize;
- // #ifdef CONFIG_COMPAT
- // unsigned int compatsize;
- // #endif
- // unsigned int hooks;
- // unsigned short proto;
- // unsigned short family;
-}
-
-// TODO: Delete?
-// MatchCheckEntryParams
-
-type TCPMatcherData struct {
- // Filter IPHeaderFilter
-
- SourcePortStart uint16
- SourcePortEnd uint16
- DestinationPortStart uint16
- DestinationPortEnd uint16
- Option uint8
- FlagMask uint8
- FlagCompare uint8
- InverseFlags uint8
-}
-
-func NewTCPMatcher(filter IPHeaderFilter, data TCPMatcherData) (Matcher, error) {
- // TODO: We currently only support source port and destination port.
- log.Infof("Adding rule with TCPMatcherData: %+v", data)
-
- if data.Option != 0 ||
- data.FlagMask != 0 ||
- data.FlagCompare != 0 ||
- data.InverseFlags != 0 {
- return nil, fmt.Errorf("unsupported TCP matcher flags set")
- }
-
- if filter.Protocol != header.TCPProtocolNumber {
- log.Warningf("TCP matching is only valid for protocol %d.", header.TCPProtocolNumber)
- }
-
- return &TCPMatcher{data: data}, nil
-}
-
-// TODO: Check xt_tcpudp.c. Need to check for same things (e.g. fragments).
-func (tm *TCPMatcher) Match(hook Hook, pkt tcpip.PacketBuffer, interfaceName string) (bool, bool) {
- netHeader := header.IPv4(pkt.NetworkHeader)
-
- // TODO: Do we check proto here or elsewhere? I think elsewhere (check
- // codesearch).
- if netHeader.TransportProtocol() != header.TCPProtocolNumber {
- return false, false
- }
-
- // We dont't match fragments.
- if frag := netHeader.FragmentOffset(); frag != 0 {
- if frag == 1 {
- log.Warningf("Dropping TCP packet: malicious packet with fragment with fragment offest of 1.")
- return false, true
- }
- return false, false
- }
-
- // Now we need the transport header. However, this may not have been set
- // yet.
- // TODO
- var tcpHeader header.TCP
- if pkt.TransportHeader != nil {
- tcpHeader = header.TCP(pkt.TransportHeader)
- } else {
- // The TCP header hasn't been parsed yet. We have to do it here.
- if len(pkt.Data.First()) < header.TCPMinimumSize {
- // There's no valid TCP header here, so we hotdrop the
- // packet.
- // TODO: Stats.
- log.Warningf("Dropping TCP packet: size to small.")
- return false, true
- }
- tcpHeader = header.TCP(pkt.Data.First())
- }
-
- // Check whether the source and destination ports are within the
- // matching range.
- sourcePort := tcpHeader.SourcePort()
- destinationPort := tcpHeader.DestinationPort()
- if sourcePort < tm.data.SourcePortStart || tm.data.SourcePortEnd < sourcePort {
- return false, false
- }
- if destinationPort < tm.data.DestinationPortStart || tm.data.DestinationPortEnd < destinationPort {
- return false, false
- }
-
- return true, false
-}