init_heap에 대한 patch description

도영주 2013.08.27 16:00 조회 수 : 2145

http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=acd644bb4abb4d9f0ba6b9ec2b356263971ef9d0

 

x86 setup: guard the heap against invalid stack setups
If we use the bootloader-provided stack pointer, we might end up in a situation where the bootloader (incorrectly) pointed the stack in the middle of our heap. Catch this by simply comparing the computed heap end value to the stack pointer minus the defined stack size.
 
X86 setup : 잘못된 스택을 셋업을 막기 위한 힙 영역 방어
 
부트로더가 제공한 스택 포인터를 사용하는 경우, 우리 힙 영역의 중간에 부트로더가 (부적절하게) 지정한 스택이 생기는 현상이 발생할 수 있다. 이것은 계산된 힙 영역의 end 값을 스택 포인터에서 지정한 스택 크기를 뺀 값을 비교하여 이 버그를 잡았다.
 
original code
heap_end = (char *)(boot_params.hdr.heap_end_ptr + 0x200 -STACK_SIZE);
 
modified code
+       char *stack_end;
        if (boot_params.hdr.loadflags & CAN_USE_HEAP) {
+               asm("leal %P1(%%esp),%0"
+                   : "=r" (stack_end) : "i" (-STACK_SIZE));
+
+               heap_end = (char *)
+                       ((size_t)boot_params.hdr.heap_end_ptr + 0x200);
+               if (heap_end > stack_end)
+                       heap_end = stack_end;
 
 
XE Login