Closed veremenko-y closed 6 months ago
This is the test code:
diff --git a/Applications/util/ps.c b/Applications/util/ps.c
index 6e50cafc9..48cb93256 100644
--- a/Applications/util/ps.c
+++ b/Applications/util/ps.c
@@ -473,6 +473,12 @@ int do_ps(void)
return 1;
}
ppid_slot[i] = ptab[i].p_tab.p_pptr - ptab[0].p_tab.p_pptr;
+ printf("ppid_slot[%d] = %d. Address difference 0x%08x. Misallignment: %d Ptab size: 0x%04x\n",
+ i,
+ ppid_slot[i],
+ (void*)ptab[i].p_tab.p_pptr - (void*)ptab[0].p_tab.p_pptr,
+ ((void*)ptab[i].p_tab.p_pptr - (void*)ptab[0].p_tab.p_pptr) % sizeof(ptab[i].p_tab),
+ sizeof(ptab[i].p_tab));
/* 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;
Ick.. I will take a look at fixing that somewhat more robustly Thanks for chasing it down
Ick.. I will take a look at fixing that somewhat more robustly Thanks for chasing it down
I figured you'd want to look at it yourself. Do you want me to close the PR or keep it open?
Fixes #1069
Okay, this turned out nastier than I thought. It is caused specifically by the
ps.c:475
So as it turns out it was broken before and after
struct p_tab
change, it just was breaking differently.Library/struct p_tab
actually has different size thanKernel/struct p_tab
. BecauseKernel/p_tab
is larger, subtraction does not result in a value divisible byLibrary/p_tab
, which I believe is UB.What actually breaks is line 341 where we try to get the process in the slot 14248...