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

Fix out of bounds read #507

Merged
merged 7 commits into from
Jul 31, 2023
Merged

Conversation

Boneyan
Copy link
Contributor

@Boneyan Boneyan commented Jul 17, 2023

PR fixing bug:

panic: runtime error: index out of range [9] with length 0

goroutine 2182 [running]:
github.com/insomniacslk/dhcp/dhcpv4/nclient4.ipv4.protocol(...)
	/go/src/.../vendor/github.com/insomniacslk/dhcp/dhcpv4/nclient4/ipv4.go:108
github.com/insomniacslk/dhcp/dhcpv4/nclient4.ipv4.transportProtocol(...)
	/go/src/.../vendor/github.com/insomniacslk/dhcp/dhcpv4/nclient4/ipv4.go:124
github.com/insomniacslk/dhcp/dhcpv4/nclient4.(*BroadcastRawUDPConn).ReadFrom(0x400048a0f0, {0x40005f2600, 0x5dc, 0x1?})
	/go/src/.../vendor/github.com/insomniacslk/dhcp/dhcpv4/nclient4/conn_unix.go:115 +0x370
github.com/insomniacslk/dhcp/dhcpv4/nclient4.(*Client).receiveLoop(0x40000163f0)
	/go/src/.../vendor/github.com/insomniacslk/dhcp/dhcpv4/nclient4/client.go:262 +0x90
created by github.com/insomniacslk/dhcp/dhcpv4/nclient4.new
	/go/src/.../vendor/github.com/insomniacslk/dhcp/dhcpv4/nclient4/client.go:223 +0x3a4

@pmazzini
Copy link
Collaborator

Please sign the commit: https://github.com/insomniacslk/dhcp/pull/507/checks?check_run_id=15096874830

Example:

  • In your local branch, run: git rebase HEAD~4 --signoff
  • Force push your changes to overwrite the branch: git push --force-with-lease origin fix-out-of-bounds-read

Signed-off-by: KonnovKM <[email protected]>
Signed-off-by: KonnovKM <[email protected]>
Signed-off-by: KonnovKM <[email protected]>
Signed-off-by: KonnovKM <[email protected]>
@pmazzini
Copy link
Collaborator

pmazzini commented Jul 20, 2023

Can you share some context on when you faced this out of bounds read? Didn't the packet have the full IP header?

@codecov
Copy link

codecov bot commented Jul 20, 2023

Codecov Report

Patch coverage: 35.00% and project coverage change: +72.77% 🎉

Comparison is base (5648422) 0.00% compared to head (5771e16) 72.77%.

Additional details and impacted files
@@             Coverage Diff             @@
##           master     #507       +/-   ##
===========================================
+ Coverage        0   72.77%   +72.77%     
===========================================
  Files           0       91       +91     
  Lines           0     5777     +5777     
===========================================
+ Hits            0     4204     +4204     
- Misses          0     1398     +1398     
- Partials        0      175      +175     
Files Changed Coverage Δ
dhcpv4/nclient4/conn_unix.go 63.51% <0.00%> (ø)
dhcpv4/nclient4/ipv4.go 87.40% <36.84%> (ø)

... and 89 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Boneyan
Copy link
Contributor Author

Boneyan commented Jul 25, 2023

App made dhcp requests in a mobile network and seems like received packet that caused panic. I think similar issue is mentioned in #468.

@pmazzini
Copy link
Collaborator

From https://github.com/insomniacslk/dhcp/blob/master/dhcpv4/nclient4/ipv4.go#L81

ipv4 represents an ipv4 header stored in a byte array.
Most of the methods of IPv4 access to the underlying slice without
checking the boundaries and could panic because of 'index out of range'.
Always call IsValid() to validate an instance of IPv4 before using other methods.

@pmazzini
Copy link
Collaborator

Maybe we should add the IsValid method:

https://github.com/google/gvisor/blob/master/pkg/tcpip/header/ipv4.go#L483

Signed-off-by: KonnovKM <[email protected]>
dhcpv4/nclient4/ipv4.go Outdated Show resolved Hide resolved
dhcpv4/nclient4/ipv4.go Outdated Show resolved Hide resolved
dhcpv4/nclient4/ipv4.go Outdated Show resolved Hide resolved
dhcpv4/nclient4/ipv4.go Outdated Show resolved Hide resolved
@Boneyan
Copy link
Contributor Author

Boneyan commented Jul 27, 2023

Seems like current version of PR doesn't work (it can't receive response packet after offer)

@pmazzini
Copy link
Collaborator

Seems like current version of PR doesn't work (it can't receive response packet after offer)

Do you know why?

@Boneyan
Copy link
Contributor Author

Boneyan commented Jul 27, 2023

I had such issue in old version of this PR when it was smth like

if headerLength < protocol {continue}  
//do udpheader check

and then I removed continue

if headerLength > protocol {
    //do udpheader check
}

and it started working. So it has something to do with continue

Signed-off-by: KonnovKM <[email protected]>
@Boneyan
Copy link
Contributor Author

Boneyan commented Jul 31, 2023

I ran more tests and this version is actually working, previous test was misconducted

@pmazzini pmazzini merged commit 0f9eb93 into insomniacslk:master Jul 31, 2023
9 checks passed
@pmazzini pmazzini mentioned this pull request Jul 31, 2023
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.

2 participants