Browse Source

security: resolve incorrect type conversions (#21251)

* security: resolve incorrect type conversions

* add changelog

* fix more incorrect type conversions
pull/21260/merge
Deniz Onur Duzgun 6 months ago committed by GitHub
parent
commit
68a7648d14
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 3
      .changelog/21251.txt
  2. 4
      agent/consul/leader_registrator_v2.go
  3. 3
      agent/xds/proxystateconverter/endpoints.go
  4. 3
      agent/xds/proxystateconverter/listeners.go
  5. 3
      agent/xds/response/response.go
  6. 6
      agent/xds/testing.go
  7. 7
      api/api.go

3
.changelog/21251.txt

@ -0,0 +1,3 @@
```release-note:bug
core: Fix multiple incorrect type conversion for potential overflows
```

4
agent/consul/leader_registrator_v2.go

@ -175,6 +175,10 @@ func (r V2ConsulRegistrator) createWorkloadFromMember(member serf.Member, parts
workloadMeta["grpc_tls_port"] = strconv.Itoa(parts.ExternalGRPCTLSPort) workloadMeta["grpc_tls_port"] = strconv.Itoa(parts.ExternalGRPCTLSPort)
} }
if parts.Port < 0 || parts.Port > 65535 {
return nil, fmt.Errorf("invalid port: %d", parts.Port)
}
workload := &pbcatalog.Workload{ workload := &pbcatalog.Workload{
Addresses: []*pbcatalog.WorkloadAddress{ Addresses: []*pbcatalog.WorkloadAddress{
{Host: member.Addr.String(), Ports: []string{consulPortNameServer}}, {Host: member.Addr.String(), Ports: []string{consulPortNameServer}},

3
agent/xds/proxystateconverter/endpoints.go

@ -301,6 +301,7 @@ func (s *Converter) filterSubsetEndpoints(subset *structs.ServiceResolverSubset,
// used in clusters.go // used in clusters.go
func makeHostPortEndpoint(host string, port int) *pbproxystate.Endpoint { func makeHostPortEndpoint(host string, port int) *pbproxystate.Endpoint {
if port >= 0 && port <= 65535 {
return &pbproxystate.Endpoint{ return &pbproxystate.Endpoint{
Address: &pbproxystate.Endpoint_HostPort{ Address: &pbproxystate.Endpoint_HostPort{
HostPort: &pbproxystate.HostPortAddress{ HostPort: &pbproxystate.HostPortAddress{
@ -310,6 +311,8 @@ func makeHostPortEndpoint(host string, port int) *pbproxystate.Endpoint {
}, },
} }
} }
return nil
}
func makeUnixSocketEndpoint(path string) *pbproxystate.Endpoint { func makeUnixSocketEndpoint(path string) *pbproxystate.Endpoint {
return &pbproxystate.Endpoint{ return &pbproxystate.Endpoint{

3
agent/xds/proxystateconverter/listeners.go

@ -764,6 +764,7 @@ func makeListenerWithDefault(opts makeListenerOpts) *pbproxystate.Listener {
// // Since access logging is non-essential for routing, warn and move on // // Since access logging is non-essential for routing, warn and move on
// opts.logger.Warn("error generating access log xds", err) // opts.logger.Warn("error generating access log xds", err)
//} //}
if opts.port >= 0 && opts.port <= 65535 {
return &pbproxystate.Listener{ return &pbproxystate.Listener{
Name: fmt.Sprintf("%s:%s:%d", opts.name, opts.addr, opts.port), Name: fmt.Sprintf("%s:%s:%d", opts.name, opts.addr, opts.port),
//AccessLog: accessLog, //AccessLog: accessLog,
@ -776,6 +777,8 @@ func makeListenerWithDefault(opts makeListenerOpts) *pbproxystate.Listener {
Direction: opts.direction, Direction: opts.direction,
} }
} }
return nil
}
func makePipeListener(opts makeListenerOpts) *pbproxystate.Listener { func makePipeListener(opts makeListenerOpts) *pbproxystate.Listener {
// TODO(proxystate): Access logs will be added in the future. It will be added to top level IR, and used by xds code generation. // TODO(proxystate): Access logs will be added in the future. It will be added to top level IR, and used by xds code generation.

3
agent/xds/response/response.go

@ -53,6 +53,7 @@ func MakePipeAddress(path string, mode uint32) *envoy_core_v3.Address {
} }
func MakeAddress(ip string, port int) *envoy_core_v3.Address { func MakeAddress(ip string, port int) *envoy_core_v3.Address {
if port >= 0 && port <= 65535 {
return &envoy_core_v3.Address{ return &envoy_core_v3.Address{
Address: &envoy_core_v3.Address_SocketAddress{ Address: &envoy_core_v3.Address_SocketAddress{
SocketAddress: &envoy_core_v3.SocketAddress{ SocketAddress: &envoy_core_v3.SocketAddress{
@ -64,6 +65,8 @@ func MakeAddress(ip string, port int) *envoy_core_v3.Address {
}, },
} }
} }
return nil
}
func MakeUint32Value(n int) *wrapperspb.UInt32Value { func MakeUint32Value(n int) *wrapperspb.UInt32Value {
return &wrapperspb.UInt32Value{Value: uint32(n)} return &wrapperspb.UInt32Value{Value: uint32(n)}

6
agent/xds/testing.go

@ -125,15 +125,15 @@ func stringToEnvoyVersion(vs string) (*envoy_type_v3.SemanticVersion, bool) {
return nil, false return nil, false
} }
major, err := strconv.Atoi(parts[0]) major, err := strconv.ParseUint(parts[0], 10, 32)
if err != nil { if err != nil {
return nil, false return nil, false
} }
minor, err := strconv.Atoi(parts[1]) minor, err := strconv.ParseUint(parts[1], 10, 32)
if err != nil { if err != nil {
return nil, false return nil, false
} }
patch, err := strconv.Atoi(parts[2]) patch, err := strconv.ParseUint(parts[2], 10, 32)
if err != nil { if err != nil {
return nil, false return nil, false
} }

7
api/api.go

@ -10,6 +10,7 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"io" "io"
"math"
"net" "net"
"net/http" "net/http"
"net/url" "net/url"
@ -1181,6 +1182,9 @@ func parseQueryMeta(resp *http.Response, q *QueryMeta) error {
if err != nil { if err != nil {
return fmt.Errorf("Failed to parse X-Consul-LastContact: %v", err) return fmt.Errorf("Failed to parse X-Consul-LastContact: %v", err)
} }
if last > math.MaxInt64 {
return fmt.Errorf("X-Consul-LastContact Header value is out of range: %d", last)
}
q.LastContact = time.Duration(last) * time.Millisecond q.LastContact = time.Duration(last) * time.Millisecond
// Parse the X-Consul-KnownLeader // Parse the X-Consul-KnownLeader
@ -1222,6 +1226,9 @@ func parseQueryMeta(resp *http.Response, q *QueryMeta) error {
if err != nil { if err != nil {
return fmt.Errorf("Failed to parse Age Header: %v", err) return fmt.Errorf("Failed to parse Age Header: %v", err)
} }
if age > math.MaxInt64 {
return fmt.Errorf("Age Header value is out of range: %d", last)
}
q.CacheAge = time.Duration(age) * time.Second q.CacheAge = time.Duration(age) * time.Second
} }

Loading…
Cancel
Save