LinuxÄÚºËÀ¶ÑÀЭÒéÕ»Îó²î£¨BleedingTooth£©Ê¹ÓÃÆÊÎöÓ븴ÏÖ

Ðû²¼Ê±¼ä 2021-04-16

Îó²î¸ÅÊö


2020Äê10Ô £¬¹È¸èÇå¾²Ñо¿Ö°Ô±Åû¶ÁËÈý¸öLinuxÄÚºËÀ¶ÑÀЭÒéÕ»Îó²î £¬¿Éµ¼ÖÂÔ¶³Ì´úÂëÖ´ÐÐ £¬±»³ÆΪBleedingTooth¡£ÕâÈý¸öÎó²îÖÐ £¬Ò»¸öÊǶÑÒç³ö £¬±àºÅΪCVE-2020-24490£»ÁíÒ»¸öÊÇÀàÐÍ»ìÏý £¬±àºÅΪCVE-2020-12351 £¬×îºóÒ»¸öÊÇÐÅϢй¶ £¬±àºÅΪCVE-2020-12352¡£¿ËÈÕ £¬¹È¸èÇå¾²Ñо¿Ö°Ô±ÓÖÅû¶ÁËBleedingToothÖÐCVE-2020-12351ºÍCVE-2020-12352×éºÏµÄÎó²îʹÓü°Ï¸½Ú £¬²¢ÔÚÀ¶ÑÀ4.0Ï £¬ÊµÏÖÁËÁãµã»÷Ô¶³Ì´úÂëÖ´ÐС£


Îó²îÆÊÎö


CVE-2020-12351


¸ÃÎó²î·ºÆðÔÚnet/bluetooth/l2cap_core.cÖС£l2cap_recv_frame()ÊÇÆÊÎöºÍ´¦Öóͷ£l2capЭÒéÊý¾Ý°üµÄº¯Êý¡£´úÂëʵÏÖÈçÏÂËùʾ£º


1.png


»ñȡͨµÀcidºÍl2capÊý¾Ý°ü³¤¶Èlen¡£´úÂëʵÏÖÈçÏÂËùʾ£º


2.png


ƾ֤²î±ðµÄͨµÀcid £¬½øÈë²î±ðµÄ×ÓÀú³Ì¾ÙÐд¦Öóͷ£ £¬½øÈël2cap_data_channel()º¯Êý¡£´úÂëʵÏÖÈçÏÂËùʾ£º


3.png


Ê×ÏÈ £¬Í¨¹ýcidÕÒµ½Í¨µÀchan£»ÈôÊÇûÓÐÕÒµ½ £¬ÅжÏcidÊÇ·ñΪL2CAP_CID_A2MP£»ÈôÊÇÊÇ £¬Å²ÓÃa2mp_channel_create()½¨ÉèÒ»¸öеÄͨµÀchan¡£a2mp_channel_create()º¯ÊýʵÏÖÈçÏÂËùʾ£º


4.png


ŲÓÃamp_mgr_create()½¨Éèmgr £¬ÔÚamp_mgr_create()º¯ÊýÖÐ £¬´úÂëʵÏÖÈçÏÂËùʾ£º


5.png


ŲÓÃa2mp_chan_open()½¨ÉèͨµÀchan £¬¸Ãº¯Êý½«³õʼ»¯Ò»²¿·ÖÊý¾Ý £¬´úÂëʵÏÖÈçÏÂËùʾ£º


6.png


È罫chan->mode³õʼ»¯ÎªL2CAP_MODE_ERTM¡£chan->data¸³ÖµÎªmgr £¬ÀàÐÍΪstruct amp_mgr¡£Àֳɽ¨Éèa2mpͨµÀ·µ»Øµ½l2cap_data_channel()ÖÐ £¬´úÂëʵÏÖÈçÏÂËùʾ£º


7.png


ƾ֤chan->modeµÄ²î±ð £¬½øÈë²î±ðµÄdata´¦Öóͷ£×ÓÀú³Ì £¬µ±modeΪL2CAP_MODE_ERTMºÍL2CAP_MODE_STREAMINGʱ £¬½øÈël2cap_data_rcv()º¯ÊýÖÐ £¬´úÂëʵÏÖÈçÏÂËùʾ£º


8.png


¸ÃifÌõ¼þÖÐ £¬»áŲÓÃsk_filter()º¯Êý £¬´Ëʱchan->dataΪ²ÎÊý¡£¶øsk_filter()º¯Êý½ç˵ÈçÏÂËùʾ£º


9.png


µÚÒ»¸ö²ÎÊýÀàÐÍΪstruct sock £¬¶øchan->dataÀàÐÍΪstruct amp_mgr £¬±¬·¢ÀàÐÍ»ìÏý¡£


CVE-2020-12352


¸ÃÎó²îÊÇ·ºÆðÔÚa2mpЭÒéÖÐ £¬Îó²î´úÂëλÓÚnet/bluetooth/a2mp.c £¬¶à¸öº¯ÊýʹÓÃδ³õʼ»¯µÄ½á¹¹Ìå £¬½«Êý¾Ý·µ»Øµ½Óû§²ã £¬µ¼ÖÂÐÅϢй¶ £¬¿Éй¶ÄÚºËÕ»ÉϵÄÄÚ´æÊý¾Ý¡£Îó²îÔ­Àí½ÏΪ¼òÆÓ £¬ÒÔa2mp_getinfo_req()º¯ÊýΪÀý £¬¸Ãº¯ÊýÊÇÏìÓ¦getinfoÇëÇóʱŲÓõÄ £¬´úÂëʵÏÖÈçÏÂËùʾ£º


10.png


ÐÐ304 £¬Í¨¹ýreq->id»ñÈ¡hdev £¬ÈôÊDz»±£´æhdev»òhdev->type²»ÊÇHCI_AMP £¬½øÈëifÓï¾äÖÐ £¬½ç˵struct a2mp_info_rspÀàÐ굀 rsp £¬¸Ã½á¹¹Ìå½ç˵ÈçÏÂËùʾ£º


11.png


ÆäֻʹÓÃÁËrsp.idºÍrsp.status £¬ÆäËûµÄÊý¾ÝÓòδʹÓÃҲδ³õʼ»¯ £¬¿ÉÒÔй¶16×Ö½ÚÊý¾Ý £¬È»ºóŲÓÃa2mp_send()º¯Êý½«ÏìÓ¦°ü·¢Ë͵½Óû§²ã £¬Ð¹Â¶ÄÚ´æÊý¾Ý¡£


CVE-2020-24490


¸ÃÎó²îÖ»ÄÜÔÚbluetooth 5.0Ï´¥·¢ £¬ÔÚbluetooth 5.0֮ǰ £¬HCI¾ÙÐй㲥µÄ×î´óÊý¾Ý³¤¶ÈΪ0x1F £¬0x20-0xFF±£´æ¡£ÈçÏÂËùʾ£º


12.png


ÔÚbluetooth 5.0ÖÐ £¬¸Ãlength×î´óÀ©Õ¹µ½229×Ö½Ú¡£ÈçÏÂËùʾ£º


13.png


¸ÃÎó²î´úÂëλÓÚnet/bluetooth/hci_event.cÖÐ £¬ÔÚ´¦Öóͷ£HCI_LE_Extended_Advertising_ReportÊÂÎñÖÐ £¬Î´ÅжϹ㲥Êý¾Ý³¤¶È×î´óÖµ £¬ºóÐø¿½±´¹ã²¥Dataµ¼ÖÂÒç³ö¡£Å²ÓÃÀú³ÌÈçÏÂËùʾ£º


14.png


process_adv_report()º¯Êý´¦Öóͷ£¹ã²¥Êý¾Ý £¬½«¹ã²¥Êý¾Ý¿½±´µ½·¢Ã÷µÄ×°±¸ÖÐ £¬´úÂëʵÏÖÈçÏÂËùʾ£º


15.png


ŲÓÃstore_pending_adv_report()º¯Êý £¬¸Ãº¯ÊýʵÏֹ㲥Êý¾Ý¿½±´ £¬´úÂëʵÏÖÈçÏÂËùʾ£º


16.png


ÆäÖÐ £¬discovery_state½á¹¹Ìå½ç˵ÈçÏÂËùʾ£º


17.png


last_adv_dataÊý¾Ý¾ÞϸΪHCI_MAX_AD_LENGTH £¬¹²31×Ö½Ú £¬µ±Ö´ÐÐmemcpyʱ±¬·¢Òç³ö¡£


ʹÓÃÆÊÎöÓ븴ÏÖ


¿ØÖÆ´úÂëÖ´ÐÐÁ÷³Ì


Ç°ÎÄÆÊÎöµ½CVE-2020-12351ÀàÐÍ»ìÏýÊÇÔÚsk_filter()º¯ÊýÖб¬·¢µÄ £¬sk_filter()º¯ÊýŲÓÃsk_filter_trim_cap()º¯Êý £¬¸Ãº¯Êý´úÂëʵÏÖÈçÏ£º


18.png


¸Ãº¯ÊýµÚÒ»¸ö²ÎÊýΪsk £¬²ÎÊýÀàÐÍΪsock½á¹¹Ìå £¬Õⲿ·Ö´úÂëÖжÔskºÍskbµÄ¼ì²éÈÝÒ×Èƹý¡£½ÓÏÂÀ´Òªº¦´úÂëÈçÏÂËùʾ£º


19.png


ÐÐ113 £¬¶Ôsk->sk_filter¾ÙÐнâÒýÓà £¬ÈôÊÇÀֳɻñÈ¡filterÖ¸Õë £¬½øÈëÐÐ115¡£ÐÐ119 £¬Å²ÓÃbpf_prog_run_save_cb()º¯Êý £¬²ÎÊý»®·ÖΪfilter->progºÍskb £¬¸Ãº¯Êý´úÂëʵÏÖÈçÏÂËùʾ£º


20.png


È»ºó £¬ÐÐ676 £¬Å²ÓÃ__bpf_prog_run_save_cb()º¯Êý £¬¸Ãº¯ÊýʵÏÖ´úÂëÈçÏ£º


21.png


½Ó×Å £¬ÐÐ662 £¬Å²ÓÃBPF_PROG_RUN(prog,skb) £¬¸Ãº¯Êý½ç˵Ϊһ¸öºê £¬ÊµÏÖ´úÂëÈçÏÂËùʾ£º


22.png


Ò»ÆðŲÓÃÏÂÀ´ £¬×îÖÕ»áŲÓõ½ºì¿òÖеĴúÂë £¬¼ò»¯Ò»ÏÂŲÓÃÀú³ÌΪ£º

sk->sk_filter->prog->bpf_func(skb, sk->sk_filter->prog->insnsi)¡£Òò´Ë £¬Ö»Òª¿ØÖÆsk->sk_filter¾Í¿ÉÒÔ¿ØÖÆÖ´ÐÐÁ÷³Ì¡£


¶ÑÅçռλ


º¯Êýsk_filter()µÄµÚÒ»¸ö²ÎÊýÀàÐÍΪstruct sock £¬¶øÏÖʵ´«ÈëµÄ²ÎÊýÀàÐÍΪstruct amp_mgr £¬¿ÉÒÔ½ÓÄɶÑÅç128¾ÞϸµÄÄÚ´æ¿é¾ÙÐÐռλ £¬Î±Ôìamp_mgr ¹¤¾ß¡£ÕâÀïÓиöÎÊÌâ £¬sk->sk_filterÔÚsockÖеÄÆ«ÒÆΪ0x110 £¬¶øamp_mgr½á¹¹Ìå¾ÞϸΪ0x70 £¬Æ«ÒÆÒѾ­Áè¼ÝÁ˹æÄ£¡£Òª½â¾öÕâ¸öÎÊÌâ £¬ÕâÀï¿ÉÒÔ½ÓÄÉÈçÏÂÇÉÃîµÄ¶ÑÅç½á¹¹£º


23.png


½á¹¹Ìåamp_mgrÔÚkmalloc-128ÀàÐ͵ÄslubÖб»·ÖÅÉ £¬´ÓµÚÈý¸ö¿é×îÏÈ £¬amp_mgr½á¹¹ÌåÆ«ÒÆ0x10´¦ £¬¿ÉÒÔ±»Î±Ôì³Ésk_filter £¬±ã¿ÉÒÔÖª×ãsk¶Ôsk_filterÓòµÄ½âÒýÓà £¬²¢ÇÒ¿É¿Ø¡£


½á¹¹ÔغÉ


ͨ¹ý¶ÑÅçռλ¿ØÖÆ´úÂëÖ´ÐÐÁ÷³Ìºó £¬½ÓÏÂÀ´¾ÍÊǽṹ¹¥»÷ÔغÉ¡£¿ÉÒÔ½ÓÄɶÑÅç1024¾ÞϸµÄÄÚ´æ¿éȥαÔìl2cap_chan¹¤¾ß £¬ÓÉÓڽṹÌå¾ÞϸΪ792 £¬ÕýºÃÂäÔÚkmalloc-1024 slub¿éÖÐ £¬²¢ÇÒa2mpͨµÀÒ²ÊôÓÚl2capͨµÀÖÐ £¬ÊÍ·Åa2mpͨµÀʱ £¬l2capͨµÀÒ²½«±»ÊÍ·Å £¬²Ù¿ØÆðÀ´½ÏΪÎÞа £¬×îÖսṹÈçÏÂËùʾ£º


24.png


й¶l2cap_chan¹¤¾ßµØµã


ͨ¹ý¶ÑÅç½á¹¹ºÍ½¨ÉèÊÍ·Ål2cap_chanͨµÀµÈһϵÁвÙ×÷ºó £¬¿ÉÄܱ£´æÒ»¸öÖ¸Ïòkmalloc-1024ÄÚ´æ¿éµØµãµÄl2cap_chan¹¤¾ß £¬¿ÉÒÔͨ¹ýCVE-2020-12352Îó²îй¶һ¸öÄÚºËÕ»ÉÏÃæµÄÄں˵صã £¬ÈçÏÂͼÖкì¿òËùʾ£º


25.png


ͨ¹ý¸ÃÄڵصصã¼õÈ¥Ò»¸ö0x110Æ«ÒƱã¿ÉÒÔÕÒµ½Ò»¸öl2cap_chan¹¤¾ßµØµã £¬¿ÉÒÔͨ¹ýamp_mgr½á¹¹ÌåÄÚ´æµØµã¼ì²éÒ»ÏÂÊÇ·ñ׼ȷ £¬ÓÉÓÚamp_mgr½á¹¹ÌåÆ«ÒÆ0x18´¦Îªl2cap_chanÖ¸Õë £¬ÈçÏÂͼÖкì¿òËùʾ£º


26.png


ÀÖ³Éй¶l2cap_chan¹¤¾ßµØµãºó £¬È»ºóÈ¥Ìî³äamp_mgr½á¹¹ÌåÆ«ÒÆ0x10´¦µÄÊý¾ÝÓò¡£


¸´ÏÖ²âÊÔ


ÎÒÃÇÔÚubuntu 5.4.0-26-genericϵͳϸ´ÏÖ²âÊÔÎó²îʹÓà £¬Ö´ÐÐÀú³ÌÈçÏ£º


27.png


Àֳɷ´µ¯root¼¶shell £¬ÈçÏÂËùʾ£º


28.png


²Î¿¼Á´½Ó£º

[1]https://google.github.io/security-research/pocs/linux/bleedingtooth/writeup

[2]https://github.com/google/security-research/security/advisories/GHSA-ccx2-w2r4-x649

[3]https://github.com/google/security-research/security/advisories/GHSA-7mh3-gq28-gfrq

[4]https://github.com/google/security-research/security/advisories/GHSA-h637-c88j-47wq


ÓÅ·¢¹ú¼ÊÍøÕ¾¹ÙÍøÆð¾¢·ÀÓùʵÑéÊÒ£¨ADLab£©


ADLab½¨ÉèÓÚ1999Äê £¬ÊÇÖйúÇå¾²ÐÐÒµ×îÔ罨ÉèµÄ¹¥·ÀÊÖÒÕÑо¿ÊµÑéÊÒÖ®Ò» £¬Î¢ÈíMAPPÍýÏë½¹µã³ÉÔ± £¬¡°ºÚȸ¹¥»÷¡±¿´·¨Ê×ÍÆÕß¡£×èÖ¹ÏÖÔÚ £¬ADLabÒÑͨ¹ýCVEÀÛ¼ÆÐû²¼Çå¾²Îó²î½ü1100¸ö £¬Í¨¹ý CNVD/CNNVDÀÛ¼ÆÐû²¼Çå¾²Îó²î1000Óà¸ö £¬Ò»Á¬¼á³Ö¹ú¼ÊÍøÂçÇå¾²ÁìÓòÒ»Á÷Ë®×¼¡£ÊµÑéÊÒÑо¿Æ«Ïòº­¸Ç²Ù×÷ϵͳÓëÓ¦ÓÃϵͳÇå¾²Ñо¿¡¢ÖÇÄÜÖÕ¶ËÇå¾²Ñо¿¡¢ÎïÁªÍøÖÇÄÜ×°±¸Çå¾²Ñо¿¡¢WebÇå¾²Ñо¿¡¢¹¤¿ØϵͳÇå¾²Ñо¿¡¢ÔÆÇå¾²Ñо¿¡£Ñо¿Ð§¹ûÓ¦ÓÃÓÚ²úÆ·½¹µãÊÖÒÕÑо¿¡¢¹ú¼ÒÖصã¿Æ¼¼ÏîÄ¿¹¥¹Ø¡¢×¨ÒµÇå¾²·þÎñµÈ¡£


adlab.jpg