LinuxÄÚºËeBPF verifier½çÏßÅÌËã¹ýʧÎó²îÆÊÎöÓëʹÓã¨CVE-2021-31440£©
Ðû²¼Ê±¼ä 2021-05-31Îó²îÅä¾°
¿ËÈÕ£¬ZDI¹ÙÍøÅû¶һ¸öLinuxÄÚºËeBPF verifier½çÏßÅÌËã¹ýʧÎó²î£¬¸ÃÎó²îÔ´ÓÚeBPFÑéÖ¤Æ÷ÔÚLinuxÄÚºËÖÐûÓÐ׼ȷÅÌËã64λת32λ²Ù×÷µÄ¼Ä´æÆ÷½çÏߣ¬µ¼ÖÂÍâµØ¹¥»÷Õß¿ÉÒÔʹÓôËȱÏݾÙÐÐÄÚºËÐÅϢ鶻òÌØȨÌáÉý£¬¸ÃÎó²î±àºÅΪCVE-2021-31440¡£
Ó°Ïì¹æÄ£Óë·À»¤²½·¥
£¨1£©Ó°Ïì¹æÄ£Linux-5.7 ~ Linux- 5.11.15Ubuntu 20.10
£¨2£©·À»¤²½·¥
ʵʱ¸üÐÂÉý¼¶Äں˽«kernel.unprivileged_bpf_disabled.sysctlÉèÖÃΪ1£¬ÔÝʱÏÞÖÆͨË×Óû§È¨ÏÞ
Îó²îÔÀíÓëµ÷ÊÔÆÊÎö
£¨1£©Îó²îÔÀí
¸ÃÎó²îºÍCVE-2020-8835£¬CVE-2020-27194ÕâÁ½¸öÎó²îµÄÔÀíÀàËÆ£¬¾ùÊÇÔÚ32λºÍ64λ֮¼ä¾ÙÐÐת»»²Ù×÷ʱ£¬¹ýʧÅÌËãÁ˼ĴæÆ÷µÄÔ¼Êø½çÏߣ¬µ¼Ö¿ÉÒÔÈƹýÑéÖ¤Æ÷¼ì²éʵÏÖÔ½½ç¶Áд¡£È±ÏÝ´úÂë·ºÆðÔÚkernel/bpf/verifier.cµÄ__reg_combine_64_into_32()º¯ÊýÖУ¬¸Ãº¯ÊýÊÇÔÚcommit_id£º3f50f132d840ÖÐÒýÈëµÄ£¬¸Ã¹¦Ð§ÊµÏÖÁËÓÃ64λ¼Ä´æÆ÷ÉϵÄÒÑÖª¹æÄ£À´ÍƶϸüĴæÆ÷µÍ32λµÄ¹æÄ££¬¿ÉÊÇͬÑù·ºÆðÁËÀàËƵÄÅÌËã¹ýʧ£¬¸Ãº¯ÊýʵÏÖÈçÏ£º
ÐÐ1316£¬ÈôÊÇsmin_valueºÍsmax_value¶¼ÔÚ´ø·ûºÅµÄ32λÕûÊý¹æÄ£ÄÚ£¬Ôò½«ÏìÓ¦µØ¸üÐÂ32λµÄ´ø·ûºÅ¹æÄ£¾Þϸ£¬¹ØÓÚÓзûºÅ¹æÄ£À´Ëµ£¬ÕâÖÖ²Ù×÷ÊÇ׼ȷµÄ¡£½Ó×Å¿´£¬ÔÚÎÞ·ûºÅ¹æÄ£µÄÏìÓ¦Âß¼ÖУ¬¶Ôumin_valueºÍumax_value»®·ÖÔÚÐÐ1320ºÍÐÐ1322¾ÙÐÐÁ˼ì²é¡£ÕâÀïÂß¼²»×¼È·£¬ÀýÈçÉèÖÃdreg->umin_value=1£¬dreg->umax_value=1<<32£¬¼´0x100000000£¬µ±¾ÙÐÐÈçÉϲÙ×÷ºó£¬reg->u32_min_valueÉèÖÃΪ1£¬Õâ¸öÊÇ׼ȷµÄ£¬¿ÉÊÇreg->u32_max_valueÈ´Äð³ÉÁË0£¬¸ßλ±»½Ø¶Ï¡£Õâʱreg¼Ä´æÆ÷µÄµÍ32λ¹æÄ£ÒѾÔÓÂÒ¡£¹ØÓÚÑéÖ¤Æ÷À´ËµÊÇÔÓÂҵģ¬¿ÉÊÇÔËÐÐ̬ʱ£¬regµÄ¹æÄ£ÊÇÕý³£µÄ¡£×Åʵ¹ØÓÚÓзûºÅ½çÏßµÄÇéÐΣ¬ÒѾ¾ÙÐÐÁËÐ޸ġ£²¹¶¡commitΪ£ºb02709587ea3£¬Òªº¦²¹¶¡´úÂëÈçÏÂËùʾ£º
¶øδ¶ÔÎÞ·ûºÅ½çÏßµÄÇéÐξÙÐнâ¾ö¡£¸ÃÎó²î²¹¶¡ÖУ¬ÐÞ¸ÄΪͬʱ¶Ôumin_valueºÍumax_value¾ÙÐÐÁËÅжϣ¬ÈçÏÂËùʾ£º
£¨2£©µ÷ÊÔÆÊÎö
Ê×ÏȽ«BPF_REG_7¼Ä´æÆ÷ÉèÖÃΪ1<<32£¬¼´0x10000000£¬²¢Í¨¹ýÁ½¸öÒ»Á¬µÄNEGÖ¸ÁîʹÑéÖ¤Æ÷ÎÞ·¨¸ú×ټĴæÆ÷µÄ¹æÄ££¬Í¬Ê±¿ÉÒÔ°ü¹Ü¼Ä´æÆ÷µÄÖµÔÚÔËÐÐʱÎȹ̡£¿ÉÒÔͨ¹ýÈçÏÂBPFÖ¸ÁîʵÏÖ£º
Ö´Ðе½LSHÖ¸Áîʱ£¬ÈçÏÂËùʾ£º
´ËʱBPF_REG_7¼Ä´æÆ÷µÄ״̬ÈçÏÂËùʾ£º
Ö´ÐÐÍêLSHºó£¬´ËʱBPF_REG_7¼Ä´æÆ÷µÄ״̬ÈçÏÂͼËùʾ£º
¿ÉÊÇ´Ëʱumin_valueÒ²ÊÇ0x100000000£¬»¹Ð轫umin_valueÉèÖóÉ0x1£¬¿ÉÒÔͨ¹ýÈçÏÂeBPFÖ¸ÁîʵÏÖ£º
¶ÏµãÖÀÖкó£¬Å²ÓÃÕ»ÈçÏÂËùʾ£º
¶ÔBPF_JGEºÍBPF_JGTÖ¸Áî¾ÙÐд¦Öóͷ££¬ÕâÀï²»ÊÇ32λָÁî²Ù×÷£¬Ö´ÐÐÈçÏ´úÂ룺
ÈôÊÇR7 >= 0x1£¬ÔòÑéÖ¤Æ÷׼ȷ·ÖÖ§ÉÏ£¬true_reg->umin_valueÉèÖÃΪtrue_reg->umin_valueºÍtrue_uminÖ®¼äµÄ×î´óÖµ£¬ÕâÀïÉèÖóÉtrue_umin£¬Îª0x1¡£È»ºóŲÓÃ__reg_combine_64_into_32()º¯Êý¸üÐÂÒ»ÏÂtrue_regµÄ¹æÄ£¡£ÈçÏ´úÂëËùʾ£º
½øÈë¸Ãº¯Êýºó£¬Ê×ÏÈÅжÏÓзûºÅ¹æÄ£µÄÇéÐΣ¬ÈçÏ´úÂëËùʾ£º
ÕâÀïͬʱÅжÏÓзûºÅ¾Þϸֵ£¬Ð§¹û²»ÎªÕ棬²»½øÈëifÓï¾ä£¬Òò´Ë²»»áÐÞ¸Ä32λµÄÓзûºÅ¾Þϸֵ£¬´òÓ¡true_regµÄ״̬ÈçÏÂËùʾ£º
È»ºó×îÏÈÅжÏÎÞ·ûºÅ×îСֵµÄÇéÐΣ¬Ð§¹ûΪÕ棬ȻºóÐÞ¸Ä32λÎÞ·ûºÅ×îСֵ£¬ÈçÏ´úÂ룺
ÓÉÓÚÕâÀïÍÑÀë¾ÙÐÐÅжϣ¬¿ÉÒÔÀÖ³ÉÉèÖÃreg->u32_min_valueΪ0x1¡£½ÓÏÂÀ´ÅжÏÎÞ·ûºÅ×î´óÖµ£¬reg->umax_valueΪ0xffffffffffffffff£¬´óÓÚ0xffffffff¡£Òò´ËÌõ¼þ²»ÎªÕ棬²»ÐÞ¸Äreg->u32_max_value¡£×îºótrue_regµÄ״̬ÈçÏÂËùʾ£º
½«¼Ä´æÆ÷µÄumin_valueºÍu32_min_value¶¼ÉèÖÃΪ0x1¡£½ÓÏÂÀ´Í¨¹ýÈçÏÂeBPFÖ¸Áî×éºÏ½«u32_max_valueÒ²ÉèÖÃΪ0x1¡£ÈçÏÂËùʾ£º
¸ÃÖ¸ÁîΪW7<=0x1£¬W7Ϊ32λ¼Ä´æÆ÷¡£ÖÀÖÐÖ¹µãºó£¬Å²ÓÃÕ»ÈçÏÂËùʾ£º
ÈôÊÇW7<=0x1£¬½ÓÏÂÀ´ÉèÖÃ׼ȷ·Ö֧ϵÄtrue_reg->u32_max_value£¬ÈçÏÂͼËùʾ£º
ÐÐ7200£¬½«true_reg->u32_max_valueÉèÖÃΪtrue_umax£¬Îª0x1¡£´Ëʱtrue_regµÄ״̬ÈçÏÂËùʾ£º
È»ºóŲÓÃ__reg_combine_32_into_64()º¯Êý¸üÐÂtrue_regµÄ¹æÄ££¬ÈçÏÂËùʾ£º
¸üйæÄ£ºó£¬×îºótrue_regµÄ״̬ÈçÏÂËùʾ£º
´ËʱÔÚÑéÖ¤Æ÷µÄÊÓ½ÇÖУ¬R7¼Ä´æÆ÷µÄ32λ¹æÄ£ÊÇÀο¿Öµ£¬Îª³£Êý0x1¡£½ÓÏÂÀ´Í¨¹ýÈçÏÂeBPF×éºÏ½«R7±ä»»³É0£¬ÈçÏÂËùʾ£º
Ê×ÏÈͨ¹ýMOV32½«R7µÄ64λ¹æÄ£Ò²ÉèÖó£Êý0x1¡£Ö´ÐÐÍêMOV32Ö¸Áîºó£¬ÔÚÑéÖ¤Æ÷µÄÊÓ½ÇÏÂR7¼Ä´æÆ÷µÄ״̬ÈçÏÂËùʾ£º
¶øÔÚÔËÐÐʱ£¬R7µÄֵΪ1<<32£¬¼´0x100000000£¬µÍ32Ϊ0£¬¼´R7µÄ32λ¹æģΪ³£Êý0£¬È»ºóͨ¹ýMULºÍADDÁ½´Î²Ù×÷£¬½«R7¼Ä´æÆ÷µÄ״̬ת»»³ÉÔÚÑéÖ¤Æ÷µÄÊÓ½ÇÏÂΪ0x0£¬ÔÚÔËÐÐʱΪ0x1£¬×îÖÕ±ã¿ÉÒÔʵÏÖÔ½½ç¶Áд¡£
Îó²î¸´ÏÖ
ÔÚLinux-5.11.0Äں˰汾µÄÌض¨²âÊÔÇéÐÎÖоÙÐÐÎó²îʹÓòâÊÔ£¬ÀÖ³ÉÌáȨ¡£
²Î¿¼Á´½Ó
1.https://www.zerodayinitiative.com/blog/2021/5/26/cve-2021-31440-an-incorrect-bounds-calculation-in-the-linux-kernel-ebpf-verifier
2.https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=10bf4e83167cc68595b85fd73bb91e8f2c086e36
3.https://github.com/torvalds/linux/commit/b02709587ea3d699a608568ee8157d8db4fd8cae
4.https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2021-31440
ÓÅ·¢¹ú¼ÊÍøÕ¾¹ÙÍøÆð¾¢·ÀÓùʵÑéÊÒ£¨ADLab£©
ADLab½¨ÉèÓÚ1999Ä꣬ÊÇÖйúÇå¾²ÐÐÒµ×îÔ罨ÉèµÄ¹¥·ÀÊÖÒÕÑо¿ÊµÑéÊÒÖ®Ò»£¬Î¢ÈíMAPPÍýÏë½¹µã³ÉÔ±£¬¡°ºÚȸ¹¥»÷¡±¿´·¨Ê×ÍÆÕß¡£×èÖ¹ÏÖÔÚ£¬ADLabÒÑͨ¹ýCVEÀÛ¼ÆÐû²¼Çå¾²Îó²î½ü1100¸ö£¬Í¨¹ý CNVD/CNNVDÀÛ¼ÆÐû²¼Çå¾²Îó²î1000Óà¸ö£¬Ò»Á¬¼á³Ö¹ú¼ÊÍøÂçÇå¾²ÁìÓòÒ»Á÷Ë®×¼¡£ÊµÑéÊÒÑо¿Æ«Ïòº¸Ç²Ù×÷ϵͳÓëÓ¦ÓÃϵͳÇå¾²Ñо¿¡¢ÖÇÄÜÖÕ¶ËÇå¾²Ñо¿¡¢ÎïÁªÍøÖÇÄÜ×°±¸Çå¾²Ñо¿¡¢WebÇå¾²Ñо¿¡¢¹¤¿ØϵͳÇå¾²Ñо¿¡¢ÔÆÇå¾²Ñо¿¡£Ñо¿Ð§¹ûÓ¦ÓÃÓÚ²úÆ·½¹µãÊÖÒÕÑо¿¡¢¹ú¼ÒÖصã¿Æ¼¼ÏîÄ¿¹¥¹Ø¡¢×¨ÒµÇå¾²·þÎñµÈ¡£