fwdmachine: drop a packet when its callback raises - #5132
Open
KernelClint wants to merge 1 commit into
Open
Conversation
AI-Assisted: yes (GPT-5.6-Cyber)
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #5132 +/- ##
==========================================
+ Coverage 80.63% 80.73% +0.09%
==========================================
Files 390 390
Lines 96936 96935 -1
==========================================
+ Hits 78168 78264 +96
+ Misses 18768 18671 -97
🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ForwardMachinepasses each packet to a caller-supplied transformation callback, which signals whatshould happen by raising
FORWARD,FORWARD_REPLACE,DROP,ANSWERorREDIRECT_TO. Callersuse it to decide what crosses the machine.
scapy/fwdmachine.py:471-531also catches every other exception, logs it, and forwards the original packet. So a callback that
fails for a reason its author did not anticipate is treated as though it had said "forward".
That is reachable from the wire. Scapy's HTTP method detector
(
scapy/layers/http.py:624-635) does not recognise PATCH, so a PATCH request is returned as rawbytes; a callback that inspects
pkt.Methodthen raisesAttributeError, and the request it waswritten to block is sent upstream unchanged.
The change treats an unexpected failure as a drop:
except Exception as ex: self.vprint(self.ERROR, ctx, cs, "callback error: %s" % ex, None) - data = req + continueThe diagnostic is unchanged. Every documented outcome behaves exactly as before; only the
undocumented failure case changes, from allowed to denied.
The added regression drives a callback that raises on an unrecognised method and asserts nothing
reaches the far side. Without the source change it fails.
Performance was measured on one computer, before and after the fix: a forwarded request took
33.3 µs before and 33.7 µs after. Repeat runs of this test moved by about 9%, which is wide enough
that only a large change would show — this is not one.