AndroidÀ¶ÑÀ×Óϵͳ¡°BlueFrag¡±Îó²îÆÊÎö£¨CVE-2020-0022£©
Ðû²¼Ê±¼ä 2020-02-13Ò»¡¢Îó²îÅä¾°
2020Äê2Ô£¬AndroidÇ徲ͨ¸æÖÐÅû¶²¢ÐÞ¸´ÁËÒ»¸öÑÏÖØÎó²î£¬Îó²î±àºÅΪCVE-2020-0022£¬ÓÖ³ÆBlueFrag£¬¿ÉÓ°ÏìAndroidÀ¶ÑÀ×Óϵͳ¡£¸ÃÎó²îÊÇÒ»¸öÔ¶³Ì´úÂëÖ´ÐÐÎó²î£¬·ºÆðÔÚBluedroidÀ¶ÑÀÐÒéÕ»µÄHCI²ã£¬µ±ÎÞÏßÄ£¿é´¦ÓÚÔ˶¯×´Ì¬Ê±£¬¹¥»÷Õß¿ÉÒÔʹÓÃÀ¶ÑÀÊØ»¤³ÌÐòÌáÉýȨÏÞ½ø¶øÔÚ×°±¸ÉÏÖ´ÐдúÂë¡£¸ÃÎó²îÓ°ÏìAndroid Oreo£¨8.0ºÍ8.1£©¡¢Pie£¨9£©£¬µ«ÎÞ·¨ÔÚAndroid 10ÉϾÙÐÐʹÓ㬽öÄÜ´¥·¢DoS¹¥»÷¡£
¶þ¡¢ÐÒé¼ò½é
2.1 HCI
HCI ²ãλÓÚÀ¶ÑÀÐÒéÕ»¸ß²ãÐæź͵ͲãÐÒéÖ®¼ä£¬ÌṩÁ˶Իù´ø¿ØÖÆÆ÷ºÍÁ´Â·ÖÎÀíÆ÷µÄÏÂÁîÒÔ¼°»á¼ûÀ¶ÑÀÓ²¼þµÄͳһ½Ó¿ÚÒªÁ죬Æä½Ó¿ÚÊÊÓÃÓÚBR/EDR¿ØÖÆÆ÷¡¢BR/EDR/LE¿ØÖÆÆ÷¡¢LE¿ØÖÆÆ÷¡¢AMP¿ØÖÆÆ÷£¬Óëµ×²ãµÄ½á¹¹¹ØϵÈçÏÂͼ£º
Ö÷»úϵͳÉϵÄHCIÇý¶¯³ÌÐòºÍ¿ØÖÆÆ÷ÖеÄHCI²ãÖ®¼ä»á±£´æÖÐÐIJ㣬 ÕâЩÖÐÐIJ㼴ÊÇÖ÷»ú¿ØÖÆÆ÷´«Êä²ã£¬ÕâЩ´«Êä²ãÊÇ͸Ã÷µÄ£¬Ö»ÐèÍê³É´«ÊäÊý¾ÝµÄʹÃü£¬²»±ØÇåÎúÊý¾ÝµÄÏêϸÃûÌá£Á½¸öÀ¶ÑÀ×°±¸µã¶ÔµãHCI²ãµÄ½»»¥Àú³ÌÈçÏÂͼËùʾ£º
2.1.1 HCI°üÃûÌÃ
HCIͨ¹ý°üµÄ·½·¨À´´«ËÍÊý¾Ý¡¢ÏÂÁîºÍÊÂÎñµÄ£¬ËùÓÐÔÚÖ÷»úºÍÖ÷»ú¿ØÖÆÆ÷Ö®¼äµÄͨѶ¶¼ÒÔ°üµÄÐÎʽ¾ÙÐС£°üÀ¨Ã¿¸öÏÂÁîµÄ·µ»Ø²ÎÊý¶¼Í¨¹ýÌض¨µÄÊÂÎñ°üÀ´´«Êä¡£HCIÓÐÊý¾Ý¡¢ÏÂÁîºÍÊÂÎñÈýÖÖÀàÐ͵İü¡£ÏÂÁî°üCOMMAND£¨0x01£©Ö»ÄÜ´ÓÖ÷»ú·¢ÍùÖ÷»ú¿ØÖÆÆ÷£¬ÆäÖÐÊý¾Ý°üÊÇË«ÏòµÄ£¬·ÖΪÁ½ÀࣺACL£¨0x02£©¡¢SCO£¨0x03£©£¬¶øÊÂÎñ°üEVENT£¨0x04£©Ê¼ÖÕÊÇÖ÷»ú¿ØÖÆÆ÷·¢ÏòÖ÷»úµÄ¡£Ö÷»ú·¢³öµÄ´ó´ó¶¼ÏÂÁî°ü¶¼»á´¥·¢Ö÷»ú¿ØÖÆÆ÷±¬·¢ÏìÓ¦µÄÊÂÎñ°ü×÷ΪÏìÓ¦£¬ÔÚ´«ÊäÀú³ÌÖлáÓÐÒ»¸ö¾ä±ú£¬ÓÃÓÚʶ±ðÖ÷»úÖ®¼äµÄÂ߼ͨµÀºÍ¿ØÖÆÆ÷£¬¹²ÓÐÈýÖÖÀàÐ͵ľä±ú£ºÅþÁ¬¾ä±ú¡¢Âß¼Á´Â·¾ä±úºÍÎïÀíÁ´Â·¾ä±ú¡£
ƾ֤ÐèÒª£¬ÕâÀïÖ»ÏÈÈÝACLÊý¾Ý°üÃûÌã¬ACL Êý¾ÝÓÃÓÚÖ÷»úºÍ¿ØÖÆÆ÷Ö®¼äµÄ·Çͬ²½Êý¾Ý½»Á÷£¬Èç²¥·ÅÒôÀÖÊý¾ÝµÄÊý¾Ý°ü£¬ÃûÌÃÈçÏÂͼ£º
ÿ¸ö×ֶεÄ˵Ã÷ÈçÏÂËùʾ£º
×ֶΠ|
˵Ã÷ |
Handle |
Connection_HandleÓÃÓÚÔÚÖ÷¿ØÖÆÆ÷ÉÏ´«ÊäÊý¾Ý°ü»ò¶Î¡£ |
PB Flag |
°ü½çÏߺÍ˳Ӧ¹æÄ£¡£ |
BC Flag |
¹ã²¥±ê¼Ç¡£ |
Data Total Length |
ÒÔ°Ëλλ×éΪµ¥Î»µÄÊý¾Ý³¤¶È£¬°üÀ¨¸ß²ãÐÒédata¡£ |
ÆäÖУ¬PB FlagµÄÐÎòÈçÏ£º
ÉèÖÃΪ 00'b µÄʱ¼ä£¬´ú±í Host -> Contoller µÄ L2CAP µÄÊ×°ü¡£ÉèÖÃΪ 01¡¯b µÄʱ¼ä£¬´ú±í Host -> Contoller »òÕß Contoller -> Host µÄ L2CAP µÄÐø°ü£¨ÖÐÐĵģ©¡£ÉèÖÃΪ 10'b µÄʱ¼ä£¬´ú±í Contoller -> Host µÄ L2CAP µÄÊ×°ü¡£
2.1.2 ·Ö¶Î£¨Fragmentation£©ºÍÖØ×飨Reassembly £©
·Ö¶ÎÊǽ«PDUÆÊÎö³É½ÏСµÄ²¿·Ö£¬ÒÔ±ã´ÓL2CAPת´ïµ½½ÏµÍ²ã¡£ÖØ×éÊÇƾ֤´Óϲãת´ïÀ´µÄƬ¶ÏÖØ×éPDUµÄÀú³Ì¡£·Ö¶ÎºÍÖØ×é¿ÉÒÔÓ¦ÓÃÓÚÈκÎL2CAP PDU¡£
2.2 L2CAPÊý¾Ý°üÃûÌÃ
L2CAPÊÇ»ùÓÚ·Ö×éµÄ£¬µ«Ò²×ñÕÕÐŵÀ´«ÊäµÄͨѶģ×Ó¡£L2CAPÖ§³ÖµÄÐŵÀÓÐÁ½ÖÖ£ºÃæÏòÅþÁ¬µÄÐŵÀºÍÃæÏòÎÞÅþÁ¬µÄÐŵÀ¡£ÔÚÃæÏòÅþÁ¬µÄÐŵÀÖУ¬L2CAPÊý¾Ý°üµÄÃûÌÃÈçÏÂͼËùʾ¡£
Êý¾Ý°üÖÐÿ¸ö×ֶεÄ˵Ã÷ÈçÏÂËùʾ£º
×ֶΠ|
˵Ã÷ |
Length |
2×Ö½Ú£¬ÌåÏÖÐÅÏ¢ÓÐÓøºÔصľÞϸ£¬²»°üÀ¨³¤¶ÈL2CAPÍ·¡£ |
Channel ID£¨CID£© |
2×Ö½Ú£¬ÓÃÓÚ±êʶĿµÄÐŵÀµÄÖնˡ£Í¨µÀIDµÄ¹æÄ£ÓëÕýÔÚ·¢ËÍÊý¾Ý°üµÄ×°±¸Ïà¹Ø¡£ |
Information£¨Payload£© |
ÐÅÏ¢¸ºÔØ¡£³¤¶ÈΪ0µ½65535×Ö½Ú¡£ |
Èý¡¢Îó²îÔÀíÆÊÎö
CVE-2020-0022Îó²îλÓÚHCI²ã£¬Îó²î²¹¶¡´úÂëλÓÚhci/src/packet_fragmenter.cc£¨ÒÔ8.1.0_r33ΪÀý£©ÖеÄreassemble_and_dispatch()º¯ÊýÖУ¬¸Ãº¯ÊýÊÇÓÃÓÚÊý¾Ý°ü·ÖƬµÄÖØ×é¡£¹ØÓÚ¹ý³¤µÄACLÊý¾Ý°üÐèÒª¾ÙÐаüµÄÖØ×飬Ö÷ÒªÊÇƾ֤ACL°üÖеÄPB Flag±ê¼Çλ¾ÙÐÐÖØ×飬ÈôÊÇÄ¿½ñÊÇÆðʼ²¿·Ö²¢ÇÒÊDz»ÍêÕûµÄ£¬ÔòÌìÉúÒ»¸ö²¿·Ö°ü£¨partial_packet£©·Åµ½mapÀµÈÏ´ÎÊÕµ½ËüµÄºóÐø²¿·Ö¾ÙÐÐÆ´×°£¬Æ´×°Íê±Ïºó¾Í·Ö·¢³öÈ¥¡£ÏêϸÆÊÎöreassemble_and_dispatch()º¯ÊýÈçÏ£º
Ê×ÏÈ£¬´¦Öóͷ£µÚÒ»¸öpacket£¬´úÂë127Ðе½129ÐУ¬»®·Ö¶ÁÈ¡handle¡¢acl_lengthºÍl2cap_length¡£handleΪ±¾´ÎÁ´Â·µÄConnection_Handle¡£Æ¾Ö¤Ç°ÎÄÊý¾Ý°üÃûÌõÄÏÈÈÝ£¬acl_lengthΪData Total Length£¬¸ÃdataÊý¾ÝÓòÖдæ·Å×ÅL2CAPÊý¾Ý°ü·ÖƬ£¨Ò²¿ÉÄÜÊÇÒ»¸öÍêÕûµÄL2CAPÊý¾Ý°ü£©¡£È»ºó£¬Ö±½Ó¶ÁÈ¡dataÖÐL2CAP Length£¬¸Ãl2cap_lengthÊÇÒ»¸öÍêÕûµÄL2CAPÊý¾Ý°üÖÐpayloadµÄ³¤¶È¡£ÐÐ131£¬Ð£Ñépacket°ü³¤¶ÈÊÇ·ñÕý³£¡£ÐÐ133£¬Í¨¹ýhandle»ñÈ¡boundary_flag£¬¼´ÊÇPB Flag¡£
ÐÐ136£¬ÅжÏboundary_flagÊÇ·ñΪ2£¬¶þ½øÖÆÌåÏÖΪ10¡¯b£¬¼´ÅжÏÄ¿½ñpacketÊÇ·ñΪ Contoller -> Host µÄ L2CAP µÄÊ×°ü£¬ÈôÊÇÊÇ£¬½øÈëifÓï¾ä¡£ÐÐ137µ½ÐÐ147£¬ÅжÏÄ¿½ñpacketÊÇ·ñÒѾ±»´¦Öóͷ££¬°ü¹Ü±¾´Î´¦Öóͷ£µÄpacket¶¼ÊÇ×îеġ£ÐÐ149µ½ÐÐ154£¬ÅжÏL2CAPÊý¾Ý°ü³¤¶ÈÊÇ·ñÕý³££¬²»Õý³£Ö±½Ó±¨´í·µ»Ø¡£
½ÓÏÂÀ´£¬ÐÐ156µ½ÐÐ157£¬ÅÌËãfull_length£¬ÆäÖаüÀ¨Ò»¸öÍêÕûµÄL2CAPÊý¾Ý°üÖеÄpayloadµÄ³¤¶È£¬Ò»¸öL2CAPÍ·²¿³¤¶ÈºÍÒ»¸öHCIÍ·²¿³¤¶È¡£ÐÐ161µ½ÐÐ168£¬ÅжÏfull_lengthÊÇ·ñÁè¼ÝBT_DEFAULT_BUFFER_SIZE£¬ÈôÊÇÁè¼ÝÖ±½Ó±¨´í·µ»Ø¡£ÐÐ170µ½ÐÐ178£¬ÅжÏÄ¿½ñÍ·°üpacketÊÇ·ñÉÐÓÐÐø°ü£¬ÈôÊÇûÓÐÐø°üÖ±½ÓŲÓÃcallbacks->reassembled´¦Öóͷ£Ä¿½ñpacket²¢·µ»Ø¡£
ÈôÊÇÄ¿½ñÍ·°üpacketºóÃæÉÐÓÐÐø°ü£¬ÄǾÍ×îÏÈÖØзÖÅÉÒ»¿éеÄÄÚ´æÓÃÓÚpacketÖÐÊý¾Ý°üÖØ×é¡£ÐÐ180µ½184£¬·ÖÅɲ¢ÉèÖÃpartial_packet£¬½«partial_packet->lenÉèÖÃΪfull_length£¬½«partial_packet->offsetÉèÖÃΪpacket->len¼´Ä¿½ñÍ·°üpacket->dataµÄ³¤¶È¡£ÐÐ186£¬Å²ÓÃmemcpy£¬½«Í·°üpacketÖÐHCIÊý¾Ý°üÕûÌ忽±´µ½partial_packetÖС£ÐÐ189µ½ÐÐ191£¬ÏÈÕÒµ½HCIÊý¾Ý°üÍ·²¿£¬²¢Ìø¹ýhandle£¬¸üÐÂacl_lengthΪһ¸öÍêÕûµÄL2CAPÊý¾Ý°ü³¤¶È¡£ÐÐ193£¬½«partial_packet´æ·Åµ½ÈÝÆ÷ÖС£ÐÐ196£¬ÊÍ·ÅÄ¿½ñÍ·°üpacket£¬ÌåÏÖÒѾ´¦Öóͷ£ÍêµÚÒ»¸öpacket£¬²»ÔÙÐèÒªËüÁË¡£ÐÐ197£¬elseÓï¾ä×îÏÈ´¦Öóͷ£ºóÐøpacket£¬¼´boundary_flag²»¼´ÊÇ2µÄpacket¡£
ÐÐ198µ½ÐÐ205£¬Ê×ÏÈͨ¹ýhandleÅжÏÄ¿½ñºóÐøpacketÊÇ·ñÊôÓÚ±¾´ÎÁ´Â·µÄ£¬ÈôÊDz»ÊôÓÚ£¬Ö±½Ó·µ»Ø¡£ÐÐ206£¬»ñÈ¡Ç°Ò»ÂÖÌìÉúµÄpartial_packet¡£ÐÐ208£¬½«Ä¿½ñºóÐøpacket->offset¸³ÖµÎªHCI_ACL_PREAMBLE_SIZE¼´4×Ö½Ú£¬´Ëʱpacket->offsetÖ¸ÏòHCI°üÖеÄdataÓò£¬ÄÚÀï´æ·Å×ÅL2CAPÊý¾Ý°ü·ÖƬ¡£ÐÐ209ºÍÐÐ210£¬ÅÌËãprojected_offset£¬projected_offsetΪpartial_packet->offsetÓë±¾´ÎL2CAPÊý¾Ý°ü·ÖƬµÄ³¤¶ÈÖ®ºÍ¡£
ÐÐ211ºÍÐÐ219£¬ÅжÏprojected_offsetÊÇ·ñ´óÓÚpartial_packet->len,¼´ÅжÏprojected_offsetÊÇ·ñ´óÓÚfull_length¡£ÈôÊÇ´óÓÚ£¬ÔòÐÞ¸Äpacket->lenΪpartial_packet->len¼õÈ¥partial_packet->offset£¬¼´packet->lenΪpartial_packetÊ£Óà¿Õ¼äµÄ³¤¶È¡£È»ºó£¬½«projected_offsetÉèÖÃΪpartial_packet->len¡£ÏêϸÊý¾Ý°üÖØ×éÈçÏÂͼËùʾ£º
ÐÞÕýºÃÏÖʵҪ¿½±´µÄ³¤¶Èºó£¬ÐÐ221£¬Å²ÓÃmemcpy¾ÙÐп½±´£¬Îó²îµãµ½ÁË,µÚÒ»¸ö²ÎÊýΪpartial_packet->data + partial_packet->offset,Ä¿µÄµØµãÊÇ׼ȷµÄ£¬µÚ¶þ¸ö²ÎÊýΪpacket->data + packet->offset£¬Ô´µØµãÒ²ÊÇ׼ȷµÄ£¬µÚÈý¸ö²ÎÊýÊÇÒª¿½±´µÄ³¤¶ÈlenΪpacket->len - packet->offset£¬Õâ¸öÖµÊÇÓÐÎÊÌâµÄ£¬·ÖÁ½ÖÖÇéÐΡ£µÚÒ»ÖÖÇéÐÎÊÇprojected_offsetСÓÚpartial_packet->len£¬packet->len - packet->offsetΪL2CAPÊý¾Ý°üƬ¶Ï×ܳ¤¶È£¬²¢ÇÒÊǸöÕýÊý¡£µÚ¶þÖÖÊÇÐÐ211µÄÇéÐΣ¬packet->lenÒѾ±»ÐÞÕý¹ý£¬²»ÐèÒªÔÙÒ»´Îpacket->len - packet->offsetµÄ²Ù×÷£¬ÈôÊÇpartial_packetÊ£Óà¿Õ¼ä³¤¶ÈСÓÚ4×Ö½Ú£¬ÄÇpacket->len - packet->offset ÊÇСÓÚÁãµÄ£¬ÊÇÒ»¸ö¸ºÊý¡£ÓÉÓÚmemcpy()º¯ÊýµÚÈý¸ö²ÎÊýÀàÐÍÊÇÒ»¸öÎÞ·ûºÅÕûÐÍÀàÐÍ£¬Òò´ËÕûÊýÒç³öµ¼Ö¶ÑÒç³ö¡£Îó²î²¹¶¡ÈçÏ£º
¿ÉÒÔ¿´µ½£¬²¹¶¡´úÂëÖн«packet->len¼ÓÉÏÁËÒ»¸öpacket->offset£¬ÓÃÓÚºóÃæµÖÏû¼õpacket->offsetµÄ²Ù×÷¡£
ËÄ¡¢Ó°Ïì°æ±¾
Android Oreo£¨8.0ºÍ8.1£©
Android Pie£¨9£©
Android 10
Îå¡¢Çå¾²½¨Òé
¾¡¿ì¸üÐÂ×îеÄAndroidÇå¾²²¹¶¡
½öÔÚ¾ø¶ÔÐëҪʱÆôÓÃÀ¶ÑÀ
¼á³ÖÀ¶ÑÀ×°±¸²»¿É·¢Ã÷
²Î¿¼ÐÅÏ¢£º
1.https://insinuator.net/2020/02/critical-bluetooth-vulnerability-in-android-cve-2020-0022/
2.https://akhozo.blogspot.com/2020/02/critical-android-bluetooth-flaw-cve.html?spref=tw
3.https://android.googlesource.com/platform/system/bt/+/3cb7149d8fed2d7d77ceaa95bf845224c4db3baf%5E%21/#F0
4.https://source.android.com/security/bulletin/2020-02-01.html
5.http://androidxref.com/8.1.0_r33/xref/system/bt/hci/src/packet_fragmenter.cc
6.Bluetooth_Core_v4.2À¶ÑÀ¹Ù·½Îĵµ