Could this code damage my processor?

前端 未结 7 692
有刺的猬
有刺的猬 2021-02-05 18:50

A friend sent me that code and alleges that it could damage the processor. Is that true?

void damage_processor() {
    while (true) {
        // Assembly code th         


        
相关标签:
7条回答
  • 2021-02-05 19:39

    I heard rumor of a bug in the Pentium I that when given a certain nonsensical series of instructions in a tight loop would burn up a single flip-flop so fast the thermal protection couldn't protect it.

    What I found reference for once was really old CPUs could be cooked by doing this in real mode:

    halt:
        jmp short halt
    

    The correct code was

    halt:
        nop
        jmp short halt
    
    0 讨论(0)
  • 2021-02-05 19:44

    From userspace code? No. It'll cause a privilege exception and the kernel will terminate your program. From kernel code? I doubt it; you will be throwing exceptions, and you'd have to manually set up the fault handler to return to the code in question to keep doing it. There's also a decent chance you'll cause a triple fault if part of the CR3 move succeeds, since that controls the page table address and you'll probably get faults on instruction fetch, handler fetch, and then the double fault handler fetch. The CPU should just shut down if that happens.

    Check the Intel or AMD manuals for Systems programming, they'll tell you which exceptions will be thrown when writing invalid bits to the control registers.

    0 讨论(0)
  • 2021-02-05 19:46

    Sorry, the code doesn't run on an ARM processor.

    In many processors, instructions that set the status word or affect the processor are restricted to "supervisor" mode. Good operating systems run User code in a "protected" mode that does not have the same capabilities as "supervisor" mode. Executing privileged instructions on modern processors in User mode generates exceptions.

    You and your friend could always look up the instructions in an assembly language reference manual and verify the operation.

    0 讨论(0)
  • 2021-02-05 19:51

    Maybe if you let it run for about 20 years.

    0 讨论(0)
  • 2021-02-05 19:54

    Maybe this code causes your processor/system to lock up but there is no chance that it damages it permanently.

    Imagine if this were true: it would immediately be used by viruses/trojans to attack computers or hide their activity after detection.

    Even in the case that any code could damage a processor, the processor manufacturer could issue a so called microcode-update which is something like a soft-fix for the processor. Such microcode-updates are provided by operating systems and/or BIOS (and processor manufacturers) and are loaded into the processor before such code could be executed.

    To sum it up: No, your friend is wrong, assuming we're talking about x86/x64 platforms.

    0 讨论(0)
  • 2021-02-05 19:54

    The code in question is unlikely to do much except reboot the machine. In my experience, an x86 CPU could be bricked by executing software code.

    0 讨论(0)
提交回复
热议问题