Commit graph

1994 commits

Author SHA1 Message Date
bunnie
86d9fd1aad don't die if the stream hangs up on the server 2022-08-06 00:36:04 +08:00
bunnie
205f0a3be3 increase threshold for retiring closes
when not in heavy loopback mode, this occurs more rarely and
probably for more legitimate reasons.
2022-08-06 00:35:18 +08:00
bunnie
bd8afc6de7 clean up debug spew for merge to main 2022-08-05 15:50:11 +08:00
bunnie
cc03383891 commit the final net test state 2022-08-05 15:17:07 +08:00
bunnie
6f86aee991 give loopback its own rx buffer
instead of sharing the wifi buffer loopback has its own buffer.
this eliminates a race condition that happens whenever an Rx
happens to happen on the wifi interface while there's loopback
traffic in progress.

also, i see a lot of opportunities to optimize the net stack now
that i have tweaked this path; it might be interesting to break
the receive interrupt out directly into the COM crate instead
of passing it through LLIO then NET then COM and having COM
drain the RX buffer immediately into a local "infinite" sized
queue.

The llio->net->com loop exists because the interrupt handler
for all the i/o is shared within one hardware block, but maybe
i can create an additional interrupt responder for the com
interface just to optimize things a bit in a future SOC update.

Alternatively, I could move all the interrupts into COM and not
have them resident in LLIO. This would optimize for COM latency
at the expence of I2C latency, but that's probably OK because
I2C is much less latency sensitive (i2c and com interrupt, as
mentioned above, share the same hardware block for external
pin-based interrupts).
2022-08-05 15:12:57 +08:00
bunnie
2658dd4b71 add peek handler, heuristic to close sockets that are stuck
- Peek now has a handler for reads that can't be met immediately
- add a count to the number of times a close socket has been polled,
if it exceeds a threshold close the socket anyways. This is a compromise
between trying to figure out how to implement a fully non-blocking TcpClose,
and having an interlocked one that cleans up state but ends up blocking
the case where you have, in the same thread, a sender and receiver
(which is ironically somehow legal and does not cause deadlock,
because the TcpClose in Unix is not blocking on internal state
being cleared up).
2022-08-05 05:07:44 +08:00
bunnie
495ca1e2b7 fix timeouts, peek
- timeouts were being overwritten before they were read
- peek now behaves according to what the test bench expects
2022-08-05 05:05:41 +08:00
bunnie
32e78039b7 xous-side of 0-port listener binding
0 is a "valid" port and it means OS please give me a port.
This implements a method where a random port is chosen until
you find one that's not occupied.
2022-08-05 05:04:35 +08:00
bunnie
1cf0479528 remove heuristic from read loop, now that read works. 2022-08-05 05:04:03 +08:00
bunnie
89cba7250e commit the latest test state
a lot of tests are now passing, but still some work to do
on the clone routines.
2022-08-05 05:03:10 +08:00
bunnie
24a0848a43 add nonblocking flag to opcode map 2022-08-05 05:02:39 +08:00
bunnie
ec55f6de6d reduce the wait time on boot to PDDB mount
improves user experience, doesn't seem to impact startup
2022-08-05 04:56:37 +08:00
bunnie
20c2e979c8 add more tests, make print outputs a bit clearer 2022-08-04 21:11:55 +08:00
bunnie
8a797764c1 (possibly dubious) fix on 'unattended' Stream close
If a Stream is opened and a process isn't constantly polling it,
it'll never close if the remote side goes away -- you'll just
end up hanging in a FIN-WAIT-2 condition.

Add some logic to detect this and close out streams automatically
where the remote has hung up.

I'm not actually sure this is what you're *supposed* to do, but,
lacking a formal specification, all I can do is try to get
this thing to pass the test bench. And pass it does.
2022-08-04 21:10:17 +08:00
bunnie
80f78a0f5d tweak debug noise down 2022-08-04 21:09:49 +08:00
bunnie
9f3bef04cc tweak debug noise down 2022-08-04 21:09:24 +08:00
bunnie
6045c75cf0 refactor TcpClose; fix RxWait
TcpClose should not immediately remove the socket. It
has to wait until the FIN comes. Add a fin waiter state.
Also rewrite to use "retain". Woo. I'm starting to get
the hang of Rust closures. Only took a couple years.

RxWait gets stuck in CLOSE_WAIT state. It's a state where
you "could" transmit, but you can't receive anymore.
In this case respond with a 0-length receive? That seems
to be what leads to the right behavior. I would have thought
you'd want to respond with a timeout error but that doesn't
match what's in the test bench.
2022-08-04 05:03:08 +08:00
bunnie
5d2d7ac40f add tooling for the loopback interface
- add 127.0.0.1 to the list of IPs listened to by smoltcp
- add some static Atomic types to store the IP and MAC address
so we can process packets in other areas to detect the loopback
state
- add a routine to extract the loopback packets when they happen
- bunch of debug visibility tweaks
2022-08-03 03:34:29 +08:00
bunnie
2094b803be loopback interface
loopback packets are intercepted on the way to the COM and
re-injected directly into the Rx queue, along with a message
sent back to the main loop to pump the Rx buffer to extract the
loopback packet.
2022-08-03 03:33:15 +08:00
bunnie
f282cce900 add a loopback re-queue function to the com
the caller also needs to schedule the rx function explicitly,
not handled by these functions.
2022-08-03 03:32:27 +08:00
bunnie
7606d244e8 tweak debug output levels 2022-08-03 03:21:43 +08:00
bunnie
473c95a74c strip out the test flag 2022-08-02 16:49:50 +08:00
bunnie
536d90034c add a manually-triggered test suite for the net crate
requires the feature "nettest" to be present in shellchat.
this commit has it turned on, it'll be stripped out before
we push to main.
2022-08-02 16:46:36 +08:00
bunnie
ca30657370 attempt to integrate the std net test suite.
newsflash: it doesn't work. still handy to have the test code around
as reference.
2022-08-02 16:45:56 +08:00
bunnie
7541d39fd6 add a static variable to contain our IPV4 address
this is used to do address binding checking from library calls,
so we can reject binding to address that are not our actual IP
address.
2022-08-02 16:45:17 +08:00
bunnie
f2193d64b1 filter disallowed bindings for the TcpListener 2022-08-02 16:44:37 +08:00
bunnie
81d5718f05 fix "localhost" resolution by string name 2022-08-02 16:42:35 +08:00
bunnie
3118ebddc9 add error code printout on dictlist failure 2022-08-02 02:52:20 +08:00
bunnie
2b4ce52a10 fix some regressions on empty key listings 2022-08-02 02:52:04 +08:00
bunnie
3d992cedf4 fix an import error + reduce log noise on a normal path 2022-08-02 01:38:07 +08:00
bunnie
0d61cbb838 improve debug output 2022-08-02 01:37:45 +08:00
bunnie
13b366345c clean up/optimize the key listing routine
provides some marginal improvement on the vault UX
2022-08-01 23:12:26 +08:00
bunnie
513fe519a7 profiling should not be enabled, somehow that slipped through 2022-08-01 16:12:38 +08:00
bunnie
826aa43f20 Merge branch 'pddb-flamegraph' into main 2022-08-01 15:46:57 +08:00
bunnie
5be62e372d chore: move AES-GCM-SIV off of branch to 0.11.1 official
this patch moves us off the branch we had to hop on for cipher
API compatibility to the one that's officially published by
RustCrypto. This closes #168.
2022-08-01 15:44:16 +08:00
bunnie
7d62ca85b8 some preliminary schwags at making flamegraphs
turns out, they're pretty useless. I mean, for debugging actual
running code. it tells us basically what we know already which is
99.99% of the time is spent waiting on inter-thread messaging
in hosted mode.
2022-08-01 01:32:19 +08:00
bunnie
e469736278 stagger the flush timing a little bit
noticed it's hitting exactly when NTP updates because it also
happens on a 24-hour schedule, staggering a bit to try and keep
everything from hitting exactly at the same time once a day.
2022-07-29 15:00:44 +08:00
bunnie
2c815375a1 add sync to write function in pddb commands 2022-07-29 00:25:01 +08:00
bunnie
46c53d9612 add telemetry for better PDDB CI 2022-07-28 18:46:56 +08:00
bunnie
3a4f5d07e8 refer to Xous Book in PDDB readme 2022-07-28 16:00:30 +08:00
bunnie
ac1f746566 add fscb/spaceupdate journal flushing & periodic flush
- fix journal number bug in basis root record
- fix conflict PTE resolution to also consider basis root record,
which has a different encryption form.
2022-07-28 04:54:35 +08:00
bunnie
deecd3651d sync PDDB before churning or flushing 2022-07-28 04:47:32 +08:00
bunnie
e943b35512 fix key wrapping in hosted mode
this will require you to regenerate your hosted mode PDDB
image, no migration was written for this mode.
2022-07-26 03:24:37 +08:00
bunnie
ec5cc29ccd hotfix for incorrect AES-KWP implementation
The crate we originally grabbed for AES-KWP seems to be non-compliant
(or I'm an idiot and I can't figure out how to call it in a way
that is compliant).

See https://github.com/jedisct1/rust-aes-keywrap/issues/9

Turns out that `aes_kw` *is* compliant, but unfortunately, it didn't
exist back when the PDDB was being written. The PDDB started in October
2021, and `aes_kw` was pushed in Jan 2022. *just* barely missed it.

Anyways, caught this error while trying to implement some CI for
backups. Hurray for testing!

This patch removes the encryption path using the incorrect version
of the algorithm, but leaves the decryption path in place. The
system will try to decrypt initially with the correct version,
but if that fails, it will fall back and try the incorrect version.
If that succeeds, it returns an error code with the correct key and
an updated wrapped key, which the caller can store so that future
calls do not fail. Thus, we have a seamless migration from the
incorrect version to the correct version.

Have verified that the aes_kw version *does* work with the CI
script, insofar as it has been written (we just got to that point
and got stuck). So, full speed ahead. Users shouldn't notice this
change.

Also, fwiw, I did take a look at the "incorrect" implementation,
and it doesn't look obviously insecure. Printing out the various
rounds of the wrapping function looks like the first couple rounds
match, but it diverges somewhere probably due to an off-by-one
in a counter or something like that. I didn't chase it out -- just
wanted to make sure that nothing looked like a huge data compromise.

Good news is this comes right on the heels of v0.9.9 release, so
this will be pushed as a hotfix right away.
2022-07-25 02:56:20 +08:00
bunnie
c0bd7f7f8a add note about faulty keywrap implementation 2022-07-25 01:22:04 +08:00
bunnie
edfbc1e4f0 update some text on the USB command to be more accurate 2022-07-23 17:32:13 +08:00
bunnie
14dacd9941 handle WFXerror case more gracefully 2022-07-20 21:07:52 +08:00
bunnie
b5f45ec9ec improve the wording of the menu option to setup passwords 2022-07-19 23:59:50 +08:00
bunnie
6f10061653 reset "don't ask again" flag for password creation during factory test
this facility is necessary in case a worker accidentally picks
the wrong setting, disabling the feature for the device. When
the factory test completes, a call is made to reset the parameter.

This was a slightly complicated affair because the the don't ask
flag is contained within the rootkeys enclave itself, and we can't
just give access to rootkeys willy-nilly. So the flag is passed
through the PDDB and then to the rootkeys enclave. It's not harmful
to have it reset by an unauthorized actor; the pop-up will not
happen if passwords are, in fact, already set.
2022-07-19 23:57:25 +08:00
bunnie
e40a109f6c add UX flow dedicated to the 'churn' operation 2022-07-19 16:57:47 +08:00