-
Notifications
You must be signed in to change notification settings - Fork 224
sprot: fix panic on rx buffer overflow #2487
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
base: master
Are you sure you want to change the base?
Changes from all commits
93b5682
50846ad
6baeea1
aceb8cc
13671c4
a0efc88
780cfed
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -285,7 +285,7 @@ impl<S: SpiServer> Io<S> { | |
| hl::sleep_for(PART2_DELAY); | ||
| } | ||
|
|
||
| if total_size > RESPONSE_BUF_SIZE { | ||
| if total_size > rx_buf.len() { | ||
| return Err(SprotProtocolError::BadMessageLength.into()); | ||
| } | ||
|
|
||
|
|
@@ -321,13 +321,13 @@ impl<S: SpiServer> Io<S> { | |
| if !self.wait_rot_irq(false, TIMEOUT_QUICK) { | ||
| // Nope, it didn't complete. Pulse CSn. | ||
| ringbuf_entry!(Trace::UnexpectedRotIrq); | ||
| self.stats.csn_pulses += self.stats.csn_pulses.wrapping_add(1); | ||
| self.stats.csn_pulses = self.stats.csn_pulses.wrapping_add(1); | ||
|
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. take it or leave it: if we wanted to be able to use
Contributor
Author
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. Interesting. I see many uses of
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. Yeah, I think we may want to do an audit for this everywhere. The nice thing about |
||
| // One sample of an LPC55S28 reacting to CSn deasserted | ||
| // in about 54us. So, 10ms is plenty. | ||
| if self.do_pulse_cs(10_u64, 10_u64)?.rot_irq_end == 1 { | ||
| // Did not clear ROT_IRQ | ||
| ringbuf_entry!(Trace::PulseFailed); | ||
| self.stats.csn_pulse_failures += | ||
| self.stats.csn_pulse_failures = | ||
| self.stats.csn_pulse_failures.wrapping_add(1); | ||
| debug_set(&self.sys, false); // XXX | ||
| return Err(SprotProtocolError::RotIrqRemainsAsserted)?; | ||
|
|
||
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.
This seems fine, but also is also largely unnecessary. We statically size the buffers to always be able to handle a request or response.
I don't believe we've ever actually seen this issue in practice since #1523 merged.
The only reasons I can think of where this would matter are:
Both would be major problems in production. For (2) we can and should avoid it by just not resizing the buffers :). If we decide we must resize then we can do it over two releases depending upon direction:
All in all, this is fine as a defensive measure, but I find it largely unnecessary. IIRC the reason I did it the way I did was because without fault management at the time I figured it would be easier to spot this major issue (SP misbehavior) occurring from a crash then with an error response and retry. But I'm not sure that's actually true or valid. So I'm generally fine with just not crashing the RoT lol.
However, I don't think we should overload the same error code. This is not a FIFO overrun and it isn't really related to flow control. I'd call it something else like
RequestMsgTooLargeor something similar so that it stands out and helps us debug if this ever happens in the future. It would be a good sign to never see this distinct error code occur in practice.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.
I just pushed a commit that adds
IOError::RequestMsgTooLargeand converts it to the existingSprotProtocolError::BadMessageLengtherror when reporting to the SP. Do you think that's a good approach? I could add a newSprotProtocolErrorbut that would require updating the management-gateway-service repo, andBadMessageLengthseems like a pretty good fit even though it's mostly used for a slightly different case.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.
That seems perfect!