-
Notifications
You must be signed in to change notification settings - Fork 36
face: validate NDNLPv2 fragmentation fields before reassembly #216
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
Open
Harsh23Kashyap
wants to merge
1
commit into
named-data:main
Choose a base branch
from
Harsh23Kashyap:fix/ndnlp-reassembly-fragcount
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+85
−0
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| package face | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/named-data/ndnd/fw/defn" | ||
| enc "github.com/named-data/ndnd/std/encoding" | ||
| "github.com/named-data/ndnd/std/types/optional" | ||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| // A single fragment with an attacker-controlled FragCount must not cause | ||
| // an unbounded reassembly buffer allocation. | ||
| func TestReassembleFragCountBound(t *testing.T) { | ||
| l := &NDNLPLinkService{} | ||
| frame := &defn.FwLpPacket{Fragment: enc.Wire{[]byte{0x01}}} | ||
|
|
||
| // 1<<22 fragment slots would allocate a ~96MB slice for one tiny fragment | ||
| frag := l.reassemble(frame, 1, 0, 1<<22) | ||
| assert.Nil(t, frag) | ||
| for i := range l.reassemblyBuffers { | ||
| assert.Nilf(t, l.reassemblyBuffers[i].buffer, | ||
| "buffer %d allocated %d fragment slots for an oversized FragCount", | ||
| i, len(l.reassemblyBuffers[i].buffer)) | ||
| } | ||
| } | ||
|
|
||
| // A frame with FragIndex greater than its Sequence must be dropped before | ||
| // baseSequence is computed (uint64 underflow) and no state may be allocated. | ||
| func TestReassemblyFragIndexExceedsSequence(t *testing.T) { | ||
| l := &NDNLPLinkService{options: MakeNDNLPLinkServiceOptions()} | ||
| lp := &defn.FwLpPacket{ | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a valid LpPacket that could be accepted and assembled.
|
||
| Fragment: enc.Wire{[]byte{0x01}}, | ||
| Sequence: optional.Some(uint64(0)), | ||
| FragIndex: optional.Some(uint64(1)), | ||
| FragCount: optional.Some(uint64(2)), | ||
| } | ||
| pkt := defn.FwPacket{LpPacket: lp} | ||
| frameWire := pkt.Encode() | ||
| require.NotNil(t, frameWire) | ||
|
|
||
| l.handleIncomingFrame(frameWire.Join()) | ||
| for i := range l.reassemblyBuffers { | ||
| assert.Nilf(t, l.reassemblyBuffers[i].buffer, | ||
| "buffer %d allocated (sequence %d) for an invalid FragIndex/Sequence pair", | ||
| i, l.reassemblyBuffers[i].sequence) | ||
| } | ||
| } | ||
|
|
||
| // A legitimate fragmented packet must still reassemble: fragments arrive in | ||
| // order, the completed wire is returned, and the buffer is freed. | ||
| func TestReassembleValidSequence(t *testing.T) { | ||
| l := &NDNLPLinkService{} | ||
| f0 := &defn.FwLpPacket{Fragment: enc.Wire{[]byte{0x01}}} | ||
| f1 := &defn.FwLpPacket{Fragment: enc.Wire{[]byte{0x02}}} | ||
|
|
||
| assert.Nil(t, l.reassemble(f0, 100, 0, 2)) // incomplete | ||
| full := l.reassemble(f1, 100, 1, 2) | ||
| require.NotNil(t, full) | ||
| assert.Equal(t, enc.Wire{[]byte{0x01}, []byte{0x02}}, full) | ||
|
|
||
| // buffer freed after completion | ||
| for i := range l.reassemblyBuffers { | ||
| assert.Nil(t, l.reassemblyBuffers[i].buffer) | ||
| } | ||
| } | ||
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given your bound is 8800, there needs to be a test case with 8800 fragments.