ÓÅ·¢¹ú¼ÊÍøÕ¾¹ÙÍøADLab£ºCPU¡°ÓÄÁ顱Îó²îÆÊÎöÓëÑéÖ¤

Ðû²¼Ê±¼ä 2018-01-08

1 Ç° ÑÔ

        ¿ËÈÕ£¬CPUµ×²ãÎó²îÇå¾²ÊÂÎñÒѾ­²¨¼°È«ÇòÏÕЩËùÓеÄÊÖ»ú¡¢µçÄÔ¡¢ÔÆÅÌËã²úÆ·¡£Õâ´ÎµÄÎó²î»®·ÖÆðÃûMeltdown(Íß½â)ºÍSpectre(ÓÄÁé)¡£ÕâÁ½¸öÎó²î¿ÉÄÜ»áÔì³ÉÊܱ£»¤µÄÃÜÂë¡¢Ãô¸ÐÐÅϢй¶¡£

        ÓÅ·¢¹ú¼ÊÍøÕ¾¹ÙÍøADLabÔÚÈý´ó²Ù×÷ϵͳ(windows¡¢macos¡¢linux)£¬Ñé֤װ±¸£¨°üÀ¨Ð¡ÎÒ˽¼Ǫ̀ʽµçÄÔ¡¢Ìõ¼Ç±¾¼°·þÎñÆ÷×°±¸£©ÉÏÍê³ÉÁË¡°ÓÄÁ顱Îó²îÑéÖ¤ÊÂÇé¡£

        ±¾ÎÄÖصã¶Ô¡°ÓÄÁ顱Îó²îµÄÎó²îµÄÔ­Àí¡¢Îó²îÑéÖ¤¡¢Î£º¦¼°·À»¤¾ÙÐÐÏÈÈÝ¡£

2 Îó²îÔ­Àí

        ÓÉÓÚ¸ßËÙCPUºÍµÍËÙÄÚ´æÖ®¼äµÄI/OÆ¿¾±£¬ÏÖ´ú´¦Öóͷ£Æ÷»áʹÓÃÁ÷Ë®ÏßÊÖÒÕÌá¸ßÐÔÄÜ£¬Í¨¹ýÕ¹ÍûÏÂÒ»²½ÒªÖ´ÐеÄÖ¸Áî²¢ÌáÇ°°ÑÕâЩָÁî·ÅÔÚÁ÷Ë®ÏßÉÏ£¬ÒÔÌá¸ßËÙÂÊ¡£¿ÉÊÇÈôÊdzÌÐòÓзÖÖ§ÌøתµÄ»°£¬ÕâЩÁ÷Ë®ÏßÉϵÄԤȡµÄÖ¸ÁËùÓÐ×÷·Ï, CPUÐèÒªÇå¿ÕËùÓеÄÖ¸Áî, È»ºó¼ÓÔØÖÀÖеصãµÄÖ¸ÁÔÙ½«ºóÐøÖ¸Áî¼ÓÔØÔËÐС£

        ÈôÊdzÌÐòÓÐ10¸ö·ÖÖ§µÄ»°£¬ÄÇôÁ÷Ë®ÏßÉÏԤȡµÄÖ¸ÁîÖ»Óкܵ͵ĸÅÂÊ£¨1/10£©»áÖÀÖС£Òò´ËCPUÐèÒªÒ»ÖÖÕ¹ÍûÊÖÒÕÀ´Ìá¸ßÁ÷Ë®ÏßԤȡָÁîµÄÖÀÖÐÂÊ£¬ÕâÒ»ÊÖÒÕ±»³ÆΪCPU·ÖÖ§Õ¹ÍûÊÖÒÕ¡£

        CPU·ÖÖ§Õ¹ÍûÊÖÒÕÓÉCPU¶ÔÀúÊ·Ö¸ÁîµÄÖ´ÐÐÇéÐξÙÐж¯Ì¬ÆÊÎöºÍѧϰ£¬²¢¾ÙÐÐÕ¹Íû¡£ÔÚ¸ßÐÔÄÜÅÌËã»úÖУ¬CPU·ÖÖ§Õ¹ÍûµÄÀֳɸÅÂÊÔÚ95%~98%Ö®¼ä£¬Õâ´ó´óÌá¸ßÁËÅÌËã»úµÄÔËËãÐÔÄÜ¡£Intel¹«Ë¾ÔÚ1995Äê±¼ÌÚϵÁÐCPUÆð¾ÍÒѾ­½ÓÄÉCPUÁ÷Ë®Ïß¼°·ÖÖ§Õ¹ÍûÊÖÒÕ£¬ÏÖÔÚÖ÷Á÷µÄ¸ßÐÔÄÜCPU¶¼½ÓÄÉÕâЩÊÖÒÕ¡£

        ÈôÊÇCPU·ÖÖ§Õ¹ÍûµÄÖ´Ðз¾¶²»×¼È·£¬ØʺóÔÚÁ÷Ë®ÏßÉÏÎóÅв¢Ô¤È¡µÄÖ¸Áî×îÖÕ²¢²»»áÏÖʵִÐУ¬¿ÉÊÇΪÁËÌá¸ßÐÔÄܵÄÐèÒª£¬Á÷Ë®ÏßÖ´Ðп¢Êºó²¢Ã»ÓжÔËùÓÐÔ¤ÅÐÖ´ÐеÄÏÖ³¡×öÍêÈ«»Ø¹ö£¬TLB»ò»º´æ״̬²¢Ã»Óб»»Ø¹ö£¬Õâ¾ÍÒýÈëÁËÇå¾²ÎÊÌâ¡£

        ÔÚÅÌËã»úϵͳÖлº´æÊÇCPUÔÚÖ´ÐгÌÐòÔËÐÐʱ¹²ÏíµÄÇøÓò£¬¹¥»÷Õßͨ¹ýÅÔ·¹¥»÷(Side Channel Attack)µÄ·½·¨»ñÈ¡µ½»º´æµÄÄÚÈÝ¡£

        ÈôÊǹ¥»÷ÕßÄÜ´¥·¢Ê¹ÓÃÖ´ÐÐÈ¥»á¼ûÖ¸¶¨µÄÃô¸ÐÊý¾ÝÇøÓòµÄ»°£¬¾Í¿ÉÄܶÁÈ¡µ½Ô­±¾ÊÇÆäËüÓû§»ò¸ü¸ßÌØȨµÄÃô¸ÐÊý¾Ý¡£

        ¸ü½øÒ»²½µÄCPU·ÖÖ§Õ¹ÍûµÄÀú³ÌÊÇ¿ÉÒÔ±»Í¨Ë×ȨÏ޵ĶñÒâ³ÌÐòÓ°ÏìµÄ£¬¹¥»÷Õß¿ÉÒԽṹ³öÀàËÆROP£¨Return-oriented Programming£©¹¥»÷µÄÂß¼­È¥Ó°ÏìCPUµÄ·ÖÖ§Õ¹ÍûÀú³Ì¡£ 

        ʹÓøÃÎó²î¿ÉÒÔÓÐÒÔÏÂÈýÖÖ¹¥»÷³¡¾°£º 

        CVE-2017-5753(ÈƹýÄÚ´æ¸ôÀë½çÏß¼ì²é)£ºÍ¨¹ý¶ñÒâ´úÂëÎÛȾ·ÖÖ§Õ¹Íû£¬À´ÈƹýÄں˻òÐéÄâ»úµÄÄڴ湤¾ß½çÏß¼ì²â¡£ºÃ±Èͨ¹ý½á¹¹µÄ¶ñÒâ´úÂëÀ´´¥·¢ÓÐÔ½½çµÄÊý¾Ýϱ꣬Ôì³ÉÄÚ´æÔ½½ç»á¼û£¬ÓÉÓÚÕâ¸ö»á¼û²Ù×÷ÊÇÓÉCPU×Ô¼ºÍê³ÉµÄ£¬Äں˻òÐéÄâ»úµÄ·À»¤ÎÞ·¨Æðµ½×÷Óá£

        CVE-2017-5715(·Ö֧ĿµÄ×¢Èë)£º ÎÛȾ·ÖÖ§Õ¹Íû¡£ÔÚ´óÐÍÈí¼þϵͳÈçä¯ÀÀÆ÷µÈÈí¼þ£¬¸ß¶ÈÁýͳģ×ӵĴúÂëÖÐÍùÍù´øÓмä½Óº¯ÊýÖ¸ÕëŲÓõÄÇéÐΣ¬CPUÔÚ´¦Öóͷ£Ê±ÐèÒª¾ÙÐÐÐëÒªµÄº¯ÊýÖ¸Õë»á¼û£¬ÎªÁËÌá¸ßI/OÐÔÄÜ£¬CPU»á¾ÙÐзÖÖ§Õ¹Íû£¬ÕâÑùµÄ»°¹¥»÷Õß¿ÉÒÔͨ¹ýÀàËƵÄROPµÄ·½·¨À´¾ÙÐÐÐÅϢй¶º¯ÊýÖ¸Õ룬´Ó¶øÈƹýµØµãËæ»ú»¯µÄ·À»¤¡£

        ¡°¶ñÒâÊý¾Ý¼ÓÔØ¡±£ºÔÚ²¿·ÖCPUÉÏ£¬ÎªÁËÌá¸ßÐÔÄÜ£¬²¢²»ÊÇÿ´Î¶¼¶ÔÖ¸Áî×÷ȨÏÞ¼ì²éµÄ£¬¼ì²éµÄÌõ¼þ±£´æÒ»¶¨µÄȱÏÝ£¬Ê¹µÃ¶ñÒâµÄÊý¾Ý¿ÉÒÔ±»¼ÓÔص½Êܱ£»¤µÄÇøÓò¡£

3 Îó²îÑéÖ¤

        ¹È¸è¹«Ë¾Project ZeroÇå¾²ÍŶӿËÈÕ¹ûÕæÁËÓÄÁéÎó²îµÄPOC(¿´·¨ÑéÖ¤³ÌÐò)£¬²Î¿¼Á´½Ó£ºhttps://googleprojectzero.blogspot.com/2018/01/reading-privileged-memory-with-side.html¡£

        POCÑÝʾÁ˽«Ò»¶ÎÉñÃØÎÄ×Ö"The Magic Words are Squeamish Ossifrage." ·ÅÔÚÄÚ´æÖУ¬²¢Í¨¹ýÎó²îʹÓÃÅÔ·ÆÊÎöµÄ·½·¨´Ó»º´æÖÐÍƲâ³öÁ˸öÎÎÄ×ÖµÄÄÚÈÝ¡£

        POCµÄ¹¥»÷Ö÷Òª·ÖÈý¸ö°ì·¨£¬»®·ÖÊÇ´¥·¢CPU¾ÙÐзÖÖ§Õ¹Íû£¬Ó°ÏìCPUµÄ·ÖÖ§Õ¹ÍûÎóÅУ¬Ì½²â»º´æÊý¾Ý»ñÈ¡Ãô¸ÐÊý¾Ý¡£

        ¹¥»÷Ö÷ÒªÓÉreadMemoryByteº¯ÊýÍê³É¡£readMemoryByteº¯ÊýÊ×Ïȶà´ÎŲÓÃvictim_functionÕâÑù»á´¥·¢CPU·ÖÖ§Õ¹ÍûÊÖÒÕ£¬CPU·ÖÖ§Õ¹ÍûÊÖÒÕÒÔΪÕë¶Ôx²ÎÊýµÄµØµã»á¼û£¬ÔÚÏÂÒ»´ÎŲÓÃʱ¿ÉÄÜÊÇÓÐÓõÄÖµ£¬ÒÔÊÇCPU»áÌáÇ°½«array1[x]µÄÖµ×¼±¸ÔÚ»º´æÖС£

        È»ºó£¬readMemoryByteº¯ÊýÏòvictim_function´«ÈëÒ»¸öÔ½½ç¹æÄ£µÄxÖµ²ÎÊý£¬Õâʱ¼äCPU·ÖÖ§Õ¹ÍûÊÖÒÕ½«»á±¬·¢ÎóÅУ¬È»ºó³ÌÐòͨ¹ý»á¼ûarray2[array1[x] * 512]Õâ¶ÎµØµã¹æÄ£µÄÄÚÈÝ£¬½«array1[x]µÄÄÚÈÝ×ß©ÔÚ»º´æÖС£

        ×îºó£¬ÎÒÃÇ¿ÉÒÔʹÓüòÆӵĻº´æˢлººÍ´æÊý¾Ý̽²âÊÖÒÕ£¬ÍƲâarray2Êý×é¼ÓÔØÔÚ»º´æcache lineÖеÄÖµ£¬´Ó¶ø¶ÁÈ¡ÉñÃØÎÄ×ÖµÄÄÚÈÝ¡£ÔÚPOCÖУ¬½ÓÄÉÁËÅÌËãÄÚ´æ»á¼ûÖ¸ÁîµÄÖ´ÐÐʱ¼äÀ´²âÊÔÊÇ·ñÖÀÖлº´æ£¨ÈôÊÇÖÀÖлº´æ£¬ÔòÖ¸ÁîÖ´ÐÐʱ¼ä»á½ÏÁ¿¶Ì£©£¬´Ó¶øÅжÏÊÇ·ñÀֳɶÁÈ¡µ½ÉñÃØÎÄ×Ö¡£

        ÔÚPOCÖÐÉñÃØÎÄ×Ö×î³õ²¢Ã»ÓзºÆðÔÚ»º´æÀ¿ÉÊǹ¥»÷Àú³ÌµÄµÚÒ»Âֵĵü´ú¾Í°ÑÄ¿µÄµØµã×ß©ÔÚ»º´æÖУ¬ÒÔÊǹ¥»÷Àú³Ì¿ÉÒÔ±»¶à´ÎŲÓ㬴Ӷø¶ÁÈ¡µ½ÉñÃØÎÄ×ÖµÄËùÓÐÄÚÈÝ¡£

3.1 Ñé֤Ч¹û

        ÎÒÃÇ»®·ÖÔÚÈý̨ÅÌËã»úÉ϶ÔÎó²î¾ÙÐÐÁËÑéÖ¤£¬ÕâÈý̨ÅÌËã»úµÄCPU»®·ÖÊÇIntelµÄi5-3317U¡¢i5-7360U¡¢i7-4790K´¦Öóͷ£Æ÷£¬²Ù×÷ϵͳ»®·ÖÊÇMac¡¢linux¡¢windows¡£

3.1.1 ʵÑé1

        ²Ù×÷ϵͳ£ºMACOSX Yosemite °æ±¾10.10.5

        ´¦Öóͷ£Æ÷Ãû³Æ£º  Intel Core i5-3317U 1.7 G*2

ÓÅ·¢¹ú¼Ê¡¤ËæÓŶø¶¯Ò»´¥¼´·¢

3.1.2  ʵÑé2

        ²âÊÔÇéÐΣº   ubuntu 16.04 LTS  

        Äں˰汾 4.10.0-42 64λ  

        ´¦Öóͷ£Æ÷Ðͺţºintel core i5-7360U cpu 2.30GHZ*4

ÓÅ·¢¹ú¼Ê¡¤ËæÓŶø¶¯Ò»´¥¼´·¢

3.1.3 ʵÑé3

          ²Ù×÷ϵͳ£ºwin10

          CPUÐͺţºintel core i7-4790K cpu 4.00GHZ*4

ÓÅ·¢¹ú¼Ê¡¤ËæÓŶø¶¯Ò»´¥¼´·¢

4 ÓÄÁéÎó²îµÄÓ°ÏìºÍΣº¦

        ÓÄÁéÎó²îÓ°Ïìµ½ÏÕЩËùÓеIJÙ×÷ϵͳ¼°ÅÌËã»ú×°±¸¡£

        ÓÉÓÚÓÄÁéÎó²îÒòÓÉÓÚCPU·ÖÖ§Õ¹ÍûÊÖÒÕµÄȱÏÝ£¬¸ÃÊÖÒÕÔÚ1995ÄêÆð¾ÍÒ»Ö±ÊǸßÐÔÄÜCPU±êÅäµÄÊÖÒÕ¡£ÏÖÔÚÖ÷Á÷Çå¾²ÊÖÒÕËù½ÓÄɵÄÀú³Ì¸ôÀ룬Óû§¿Õ¼äºÍÄں˵صã¸ôÀ룬¶à×⻧µÄÐéÄâ¸ôÀë·À»¤ÊÖÒÕ¼°É³Ïä¸ôÀëÊÖÒÕÔÚÕâÒ»Îó²îÏÂËùÓÐʧЧ¡£

        ÓÄÁéÎó²î¶Ô¶à×⻧ϵÄÔÆ·þÎñϵͳӰÏì½ÏÁ¿´ó£¬¹¥»÷ÕßÔÚÔÆƽ̨ͨ¹ýÍâµØµÄͨË׵Ļá¼ûȨÏ޾ͿÉÒÔ¶ÁÈ¡ÔÆƽ̨µÄÃô¸ÐÐÅÏ¢£¬Îª½øÒ»²½»ñµÃ¸ü¸ßµÄȨÏ޺ͻñµÃÉñÃØÊý¾ÝÌṩÁË¿ÉÄÜ¡£

        ¸ÃÎó²îµÄΣº¦»¹ÔÚÓÚ¹¥»÷Õß¿ÉÒÔͨ¹ý¸ÃÎó²îÔ¶³ÌÌᳫ¹¥»÷£¬µ±Ä¿µÄ×°±¸»á¼ûÔ¶³Ì·þÎñÆ÷µÄÍøҳʱ£¬¹¥»÷Õß¿ÉÒÔͨ¹ý¶ñÒâjs½ÅÔ­À´»ñµÃÄ¿µÄÉè±¹ØÁ¬ÄÃô¸ÐÐÅÏ¢£¬ÈçÉúÑÄÔÚÄÚ´æÖеÄÃÜÂëCookieµÈ¡£  

        ÓÄÁéÎó²îÊÜÓ°ÏìµÄ´¦Öóͷ£Æ÷²»µ«°üÀ¨intel£¬¸ßͨ£¬AMD,ARMµÈ³§¼Ò,ϱíΪÒÑÖªµÄÊÜÓ°ÏìµÄintel´¦Öóͷ£Æ÷ÁÐ±í£¨Êý¾ÝÀ´×Ôintel¹ÙÍø£©£º

  • Intel? Core? i3 processor (45nm and 32nm)
  • Intel? Core? i5 processor (45nm and 32nm)
  • Intel? Core? i7 processor (45nm and 32nm)
  • Intel? Core? M processor family (45nm and 32nm)
  • 2nd generation Intel? Core? processors
  • 3rd generation Intel? Core? processors
  • 4th generation Intel? Core? processors
  • 5th generation Intel? Core? processors
  • 6th generation Intel? Core? processors
  • 7th generation Intel? Core? processors
  • 8th generation Intel? Core? processors
  • Intel? Core? X-series Processor Family for Intel? X99 platforms
  • Intel? Core? X-series Processor Family for Intel? X299 platforms
  • Intel? Xeon? processor 3400 series
  • Intel? Xeon? processor 3600 series
  • Intel? Xeon? processor 5500 series
  • Intel? Xeon? processor 5600 series
  • Intel? Xeon? processor 6500 series
  • Intel? Xeon? processor 7500 series
  • Intel? Xeon? Processor E3 Family
  • Intel? Xeon? Processor E3 v2 Family
  • Intel? Xeon? Processor E3 v3 Family
  • Intel? Xeon? Processor E3 v4 Family
  • Intel? Xeon? Processor E3 v5 Family
  • Intel? Xeon? Processor E3 v6 Family
  • Intel? Xeon? Processor E5 Family
  • Intel? Xeon? Processor E5 v2 Family
  • Intel? Xeon? Processor E5 v3 Family
  • Intel? Xeon? Processor E5 v4 Family
  • Intel? Xeon? Processor E7 Family
  • Intel? Xeon? Processor E7 v2 Family
  • Intel? Xeon? Processor E7 v3 Family
  • Intel? Xeon? Processor E7 v4 Family
  • Intel? Xeon? Processor Scalable Family
  • Intel? Xeon Phi? Processor 3200, 5200, 7200 Series
  • Intel? Atom? Processor C Series
  • Intel? Atom? Processor E Series
  • Intel? Atom? Processor A Series
  • Intel? Atom? Processor x3 Series
  • Intel? Atom? Processor Z Series
  • Intel? Celeron? Processor J Series
  • Intel? Celeron? Processor N Series
  • Intel? Pentium? Processor J Series
  • Intel? Pentium? Processor N Series
  • 5 Îó²îµÄ·À»¤

    1.Ãô¸ÐÊý¾Ý»á¼ûºÍÔËË㾡¿ÉÄÜÔÚ×ÔÁ¦µÄÇ徲оƬÉÏÔËÐУ¬Ê¹µÃͨË×ȨÏÞµÄÖ´ÐÐÇéÐκ͸ßȨÏÞµÄÖ´ÐÐÇéÐÎÔÚÎïÀíÉϸôÀ룬´Ó¶ø×èÖ¹Ãô¸ÐÐÅÏ¢×ß©¡£

    2.ʵʱÉý¼¶²¹¶¡£¬ÌØÊâÊǹ«ÓÐÔÆƽ̨¡£ÓÉÓÚÔÆ·þÎñϵͳµÄÖØ´ó¡¢ÖØ´ó£¬ÔÆ·þÎñ³§¼ÒÓ¦¾¡ÔçµØ¾ÙÐÐÎó²îÐÞ²¹£¬×èÖ¹Òªº¦Êý¾ÝºÍÒþ˽µÄй¶¡¢ÉÏ°¶Æ¾Ö¤±»ÇÔÈ¡µ¼ÖÂÁ¬Ëø¹¥»÷µÈ´ÎÉúÔÖÄÑ¡£

    3.ÏÖÔÚ»ùÓÚÈí¼þ²¹¶¡Ö»ÊÇ×öÁËÔÝʱ¸ôÀ룬ÈçTLB¸ôÀëµÈ£¬¿ÉÊÇδÀ´½«»áÓÐһЩÈƹýÊÖÒջ᷺Æð£¬Ìæ»»Ó²¼þ²ÅÊdz¹µ×ÐÞ¸´Õâ¸öÎÊÌâµÄÒªº¦¡£

    4.ÔÚÈíÓ²¼þÉè¼Æ·½Ã棬¿ª·¢ÕßÐèҪ˼Á¿ÐÔÄܺÍÇå¾²ÐÔÖ®¼äÈ¡µÃƽºâ¡£