EtchedPixels / FUZIX

FuzixOS: Because Small Is Beautiful
Other
2.19k stars 275 forks source link

rpipico: memory corruption #1069

Closed veremenko-y closed 5 months ago

veremenko-y commented 6 months ago

I get memory exceptions on rpipico. I bisected it to 7fd6add4cc5a16beaf7bac9bf2826b2c4515f21b, but still investigating the cause.

Not all commands break, but to guarantee an exception ps -al seems to work. I experienced it with ed as well, but don't have solid way to reproduce it.

It's not problem with the utility itself, I get the same behavior if I run ps version made prior to p_tab change.

EtchedPixels commented 5 months ago

I am thinking something like

--- a/Applications/util/ps.c
+++ b/Applications/util/ps.c
@@ -472,7 +472,9 @@ int do_ps(void)
                        close(pfd);
                        return 1;
                }
-               ppid_slot[i] = ptab[i].p_tab.p_pptr - ptab[0].p_tab.p_pptr;
+               /* Work out which slot is referenced from the node size as our own ptab struct
+                  may not exactly size match the kernel */
+               ppid_slot[i] = ((uint8_t *)ptab[i].p_tab.p_pptr - (uint8_t *)ptab[0].p_tab.p_pptr) / nodesize;
                /* Learn our tty internal reference as we go */
                if (ptab[i].p_tab.p_status && ptab[i].p_tab.p_pid == pid)
                        tty = ptab[i].p_tab.p_tty;

might be more robust ?

veremenko-y commented 5 months ago

That would do definitely do. No sneaky UB. We could also assert if % nodesize is not 0.