Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[filters] Prevent a filter from sending local reply and continue #14416

Merged
merged 14 commits into from
Dec 21, 2020

Conversation

asraa
Copy link
Contributor

@asraa asraa commented Dec 15, 2020

Signed-off-by: Asra Ali asraa@google.com

Commit Message: Prevent filter iteration on headers after sending a local reply and returning FilterHeadersStatus::Continue.
Additional Description:
Before, the test hits this crash:

[ RUN      ] Protocols/ProtocolIntegrationTest.ContinueAfterLocalReply/IPv4_Http2Downstream_Http2Upstream
[2020-12-14 16:51:35.110][29][critical][backtrace] [bazel-out/k8-opt/bin/source/server/_virtual_includes/backtrace_lib/server/backtrace.h:104] Caught Segmentation fault, suspect faulting address 0x0
[2020-12-14 16:51:35.110][29][critical][backtrace] [bazel-out/k8-opt/bin/source/server/_virtual_includes/backtrace_lib/server/backtrace.h:91] Backtrace (use tools/stack_decode.py to get line numbers):
[2020-12-14 16:51:35.110][29][critical][backtrace] [bazel-out/k8-opt/bin/source/server/_virtual_includes/backtrace_lib/server/backtrace.h:92] Envoy version: 0/1.17.0-dev/test/RELEASE/BoringSSL
[2020-12-14 16:51:35.111][29][critical][backtrace] [bazel-out/k8-opt/bin/source/server/_virtual_includes/backtrace_lib/server/backtrace.h:96] #0: __restore_rt [0x7fc14cdc68a0]
[2020-12-14 16:51:35.115][29][critical][backtrace] [bazel-out/k8-opt/bin/source/server/_virtual_includes/backtrace_lib/server/backtrace.h:96] #1: Envoy::ConnectionPool::ConnPoolImplBase::attachStreamToClient() [0xc378d6]
[2020-12-14 16:51:35.120][29][critical][backtrace] [bazel-out/k8-opt/bin/source/server/_virtual_includes/backtrace_lib/server/backtrace.h:96] #2: Envoy::ConnectionPool::ConnPoolImplBase::onUpstreamReady() [0xc3824d]
[2020-12-14 16:51:35.124][29][critical][backtrace] [bazel-out/k8-opt/bin/source/server/_virtual_includes/backtrace_lib/server/backtrace.h:96] #3: Envoy::ConnectionPool::ConnPoolImplBase::onConnectionEvent() [0xc39118]
[2020-12-14 16:51:35.128][29][critical][backtrace] [bazel-out/k8-opt/bin/source/server/_virtual_includes/backtrace_lib/server/backtrace.h:96] #4: Envoy::Network::ConnectionImplBase::raiseConnectionEvent() [0x10eda1b]
[2020-12-14 16:51:35.132][29][critical][backtrace] [bazel-out/k8-opt/bin/source/server/_virtual_includes/backtrace_lib/server/backtrace.h:96] #5: Envoy::Network::ConnectionImpl::raiseEvent() [0x10e4889]
[2020-12-14 16:51:35.136][29][critical][backtrace] [bazel-out/k8-opt/bin/source/server/_virtual_includes/backtrace_lib/server/backtrace.h:96] #6: Envoy::Network::ConnectionImpl::onWriteReady() [0x10e744e]
[2020-12-14 16:51:35.140][29][critical][backtrace] [bazel-out/k8-opt/bin/source/server/_virtual_includes/backtrace_lib/server/backtrace.h:96] #7: Envoy::Network::ConnectionImpl::onFileEvent() [0x10e64e9]
[2020-12-14 16:51:35.144][29][critical][backtrace] [bazel-out/k8-opt/bin/source/server/_virtual_includes/backtrace_lib/server/backtrace.h:96] #8: std::__1::__function::__func<>::operator()() [0x10d0971]
[2020-12-14 16:51:35.148][29][critical][backtrace] [bazel-out/k8-opt/bin/source/server/_virtual_includes/backtrace_lib/server/backtrace.h:96] #9: Envoy::Event::FileEventImpl::assignEvents()::$_1::__invoke() [0x10d174c]
[2020-12-14 16:51:35.152][29][critical][backtrace] [bazel-out/k8-opt/bin/source/server/_virtual_includes/backtrace_lib/server/backtrace.h:96] #10: event_process_active_single_queue [0x17c33f8]
[2020-12-14 16:51:35.156][29][critical][backtrace] [bazel-out/k8-opt/bin/source/server/_virtual_includes/backtrace_lib/server/backtrace.h:96] #11: event_base_loop [0x17c1dce]
[2020-12-14 16:51:35.160][29][critical][backtrace] [bazel-out/k8-opt/bin/source/server/_virtual_includes/backtrace_lib/server/backtrace.h:96] #12: Envoy::Server::WorkerImpl::threadRoutine() [0xac9688]
[2020-12-14 16:51:35.164][29][critical][backtrace] [bazel-out/k8-opt/bin/source/server/_virtual_includes/backtrace_lib/server/backtrace.h:96] #13: Envoy::Thread::ThreadImplPosix::ThreadImplPosix()::{lambda()#1}::__invoke() [0x17bb2a3]
[2020-12-14 16:51:35.164][29][critical][backtrace] [bazel-out/k8-opt/bin/source/server/_virtual_includes/backtrace_lib/server/backtrace.h:96] #14: start_thread [0x7fc14cdbb6db]

The downside here is iteration_state_ isn't modified to stop iteration. I don't think this matters since it's changed to StopSingleIteration in maybeContinueDecoding right after.

Risk Level: Low/medium in case this changes expected filter iteration?
Testing: Added test that shows message logs and behavior passes.
Fixes part of #13737

Signed-off-by: Asra Ali <asraa@google.com>
Signed-off-by: Asra Ali <asraa@google.com>
@alyssawilk alyssawilk self-assigned this Dec 15, 2020
@alyssawilk
Copy link
Contributor

Thanks for the fix! mind checking out CI and pinging back when it's sorted?

Signed-off-by: Asra Ali <asraa@google.com>
Signed-off-by: Asra Ali <asraa@google.com>
Signed-off-by: Asra Ali <asraa@google.com>
alyssawilk
alyssawilk previously approved these changes Dec 16, 2020
source/common/http/filter_manager.cc Outdated Show resolved Hide resolved
test/integration/protocol_integration_test.cc Show resolved Hide resolved
@asraa
Copy link
Contributor Author

asraa commented Dec 16, 2020

Just to double check, oauth2 filter sends a local reply and then sends StopAllIterationAndBuffer (the test failure). Is it possible that people can send a local reply and then continue header iteration?

The most minimal constraint would be changing the condition to "don't return continue after local reply" rather than "must return stopiteration after local reply"

@alyssawilk
Copy link
Contributor

I wonder if it's an attempt to drain the connection so it can be reused (for HTTP/1.1 etc.)?
cc @rgs1 @derekargueta @snowp

Signed-off-by: Asra Ali <asraa@google.com>
@rgs1
Copy link
Member

rgs1 commented Dec 16, 2020

Just to double check, oauth2 filter sends a local reply and then sends StopAllIterationAndBuffer (the test failure). Is it possible that people can send a local reply and then continue header iteration?

The most minimal constraint would be changing the condition to "don't return continue after local reply" rather than "must return stopiteration after local reply"

Thanks for this fix! I somehow forgot to follow-up with a fix here when we first bumped into this internally... this should be StopIteration. Our internal copy of this filter -- and similar filters -- have already being fixed... And that made the crash go away.

@rgs1
Copy link
Member

rgs1 commented Dec 16, 2020

I wonder if it's an attempt to drain the connection so it can be reused (for HTTP/1.1 etc.)?
cc @rgs1 @derekargueta @snowp

Which part? The Stop and Buffer as opposed to full Stop? Or continuing header iteration post local reply...? Afaik this was just a bug/omission on our side, not something to reset the connection state...

@alyssawilk
Copy link
Contributor

Ah cool. If it's just broken I'd be inclined to restore your last push and fix oath upstream too, WDYT?

This reverts commit b47f26c.

Signed-off-by: Asra Ali <asraa@google.com>
Signed-off-by: Asra Ali <asraa@google.com>
rgs1
rgs1 previously approved these changes Dec 16, 2020
Copy link
Member

@rgs1 rgs1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oauth bits look good.. Thank you!

This reverts commit 2df4777.

Signed-off-by: Asra Ali <asraa@google.com>
This reverts commit a7b95d2.

Signed-off-by: Asra Ali <asraa@google.com>
@asraa
Copy link
Contributor Author

asraa commented Dec 17, 2020

Sorry about the back and forth! All set with just preventing continue after a direct response. No changes to oauth2 (which maybe can be a TODO)

alyssawilk
alyssawilk previously approved these changes Dec 17, 2020
rgs1 pushed a commit to rgs1/envoy that referenced this pull request Dec 17, 2020
Related to envoyproxy#14416.

Signed-off-by: Raul Gutierrez Segales <rgs@pinterest.com>
@mattklein123 mattklein123 self-assigned this Dec 18, 2020
…cal-reply

Signed-off-by: Asra Ali <asraa@google.com>
@asraa
Copy link
Contributor Author

asraa commented Dec 21, 2020

Not sure if the wait is to update filter_manager to restrict back to stopiteration after local reply (rather than just "not continue"). Tests pass with @rgs1's Oauth PR merged.

If it wasn't let me know!

Signed-off-by: Asra Ali <asraa@google.com>
Signed-off-by: Asra Ali <asraa@google.com>
Signed-off-by: Asra Ali <asraa@google.com>
Copy link
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@mattklein123 mattklein123 merged commit 4ba2827 into envoyproxy:master Dec 21, 2020
mpuncel added a commit to mpuncel/envoy that referenced this pull request Dec 22, 2020
* master: (30 commits)
  Deflaked: Guarddog_impl_test (envoyproxy#14475)
  [fuzz] add fuzz tests for hpack encoding and decoding (envoyproxy#13315)
  [filters] Prevent a filter from sending local reply and continue (envoyproxy#14416)
  oauth2: improving coverage (envoyproxy#14479)
  owners: Change dio email address (envoyproxy#14498)
  macos build: Fix ninja install (envoyproxy#14495)
  http: use OptRef helper to reduce some boilerplate (envoyproxy#14361)
  doc: update test/integration/README.md (envoyproxy#14485)
  server: wait workers to start before draining parent. (envoyproxy#14319)
  api: relax inline_string length limitation in DataSource (envoyproxy#14461)
  oauth: properly stop filter chain when a response was sent (envoyproxy#14476)
  listener: deprecate use_proxy_proto (envoyproxy#14406)
  deps: update cel and remove a patch (envoyproxy#14473)
  preconnect: rename: (envoyproxy#14474)
  coverage: ratcheting limits (envoyproxy#14472)
  grpc mux: fix sending node again after stream is reset (envoyproxy#14080)
  [test] Replace printers_include with printers_lib. (envoyproxy#14442)
  tcp: nodelay in the new pool (envoyproxy#14453)
  test: replace mock_methodn macros with mock_method (envoyproxy#14450)
  tcp: extending tcp integration test (envoyproxy#14451)
  ...

Signed-off-by: Michael Puncel <mpuncel@squareup.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants