Changeset e13daa5d in mainline


Ignore:
Timestamp:
2008-03-19T21:13:49Z (16 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
047aa46
Parents:
20b8bf3
Message:

Fortify ia32 and amd64 kernels against mallicious uspace applications that set
DF prior to entering the kernel. For AMD64 syscalls, we don't use the CLD
instruction, but make use of the SFMASK MSR instead. Simics works fine with
it, but QEMU seems to have a problem.

Location:
kernel/arch
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • kernel/arch/amd64/include/cpu.h

    r20b8bf3 re13daa5d  
    3636#define KERN_amd64_CPU_H_
    3737
    38 #define RFLAGS_IF       (1 << 9)
    39 #define RFLAGS_RF       (1 << 16)
     38#define RFLAGS_IF       (1 << 9)
     39#define RFLAGS_DF       (1 << 10)
     40#define RFLAGS_RF       (1 << 16)
    4041
    4142#define EFER_MSR_NUM    0xc0000080
  • kernel/arch/amd64/src/asm_utils.S

    r20b8bf3 re13daa5d  
    249249
    250250        save_all_gpr
     251        cld
    251252
    252253        movq $(\i), %rdi        # %rdi - first parameter
  • kernel/arch/amd64/src/boot/boot.S

    r20b8bf3 re13daa5d  
    5555
    5656multiboot_image_start:
     57        cld
    5758        movl $START_STACK, %esp                 # initialize stack pointer
    5859        lgdtl bootstrap_gdtr                    # initialize Global Descriptor Table register
     
    127128        mov $VESA_INIT_SEGMENT << 4, %edi
    128129        mov $e_vesa_init - vesa_init, %ecx
    129         cld
    130130        rep movsb
    131131
     
    283283        movq $AP_BOOT_OFFSET, %rdi
    284284        movq $_hardcoded_unmapped_size, %rcx
    285         cld
    286285        rep movsb
    287286       
     
    557556       
    558557        movw $0x0c00, %ax                               # black background, light red foreground
    559         cld
    560558       
    561559        ploop:
  • kernel/arch/amd64/src/syscall.c

    r20b8bf3 re13daa5d  
    6363        /* Mask RFLAGS on syscall
    6464         * - disable interrupts, until we exchange the stack register
    65          *   (mask the IE bit)
     65         *   (mask the IF bit)
     66         * - clear DF so that the string instructions operate in
     67         *   the right direction
    6668         */
    67         write_msr(AMD_MSR_SFMASK, 0x200);
     69        write_msr(AMD_MSR_SFMASK, RFLAGS_IF | RFLAGS_DF);
    6870}
    6971
  • kernel/arch/ia32/src/asm.S

    r20b8bf3 re13daa5d  
    174174        movw %ax, %es
    175175       
     176        cld
    176177        sti
    177178        # syscall_handler(edx, ecx, ebx, esi, edi, ebp, eax)
     
    234235        movw %ax, %es
    235236
     237        cld
     238
    236239        pushl %esp          # *istate
    237240        pushl $(\i)         # intnum
  • kernel/arch/ia32/src/boot/boot.S

    r20b8bf3 re13daa5d  
    5151       
    5252multiboot_image_start:
     53        cld
    5354        movl $START_STACK, %esp                 # initialize stack pointer
    5455        lgdt KA2PA(bootstrap_gdtr)              # initialize Global Descriptor Table register
     
    8687        mov $VESA_INIT_SEGMENT << 4, %edi
    8788        mov $e_vesa_init - vesa_init, %ecx
    88         cld
    8989        rep movsb
    9090
     
    207207        movl $AP_BOOT_OFFSET, %edi
    208208        movl $_hardcoded_unmapped_size, %ecx
    209         cld
    210209        rep movsb
    211210       
     
    280279       
    281280        movw $0x0c00, %ax                                               # black background, light red foreground
    282         cld
    283281       
    284282        ploop:
Note: See TracChangeset for help on using the changeset viewer.