LinuxÄÚºËTCPЭÒé¶à¸öSACK¹¦Ð§¾Ü¾ø·þÎñÎó²îÆÊÎö

Ðû²¼Ê±¼ä 2019-06-21
Îó²îÅä¾°


2019Äê6ÔÂ18ÈÕ £¬RedhatÐû²¼Ç徲ͨ¸æ £¬LinuxÄÚºËTCP/IPЭÒéÕ»±£´æ3¸öÇå¾²Îó²î£¨CVE-2019-11477/CVE-2019-11478/CVE-2019-11479£© £¬ÕâЩÎó²îÓë×î´ó·Ö¶Î´óÐ ¡£¨MSS£©ºÍTCPÑ¡ÔñÐÔÈ·ÈÏ£¨SACK£©¹¦Ð§Ïà¹Ø £¬ÔÊÐíÔ¶³Ì¹¥»÷Õß¾ÙÐоܾø·þÎñ¹¥»÷ ¡£


Òªº¦¿´·¨



Êý¾Ý°üÖØ´«È·ÈÏ»úÖÆ


TCPÊý¾Ý°ü´«ÊäÀú³ÌÖÐ £¬À´×Ô»¬¶¯´°¿ÚµÄÊý¾Ý°üɥʧ¿ÉÄܶÔTCPÍÌÍÂÁ¿±¬·¢Ó°Ïì ¡£TCPʹÓÃÀÛ»ýÈ·ÈÏ£¨ACK£©¼Æ»®½â¾ö¸ÃÎÊÌâ £¬ÆäÖв»ÎüÊÕ²»ÔÚ»¬¶¯´°¿Ú×ó±ßÑصÄÎüÊնΠ£¬Õâ»áÇ¿ÖÆ·¢ËÍ·½ÆÚ´ýÍù·µÊ±¼äÒÔÕÒ³öÿ¸öɥʧµÄÊý¾Ý°ü £¬»òÕß²»ÐëÒªµØÖØд«ÊäÒÑ׼ȷÎüÊյĶÎ £¬´Ó¶ø½µµÍÕûÌåÍÌÍÂÁ¿ ¡£


Ñ¡ÔñÐÔÈ·ÈÏ£¨SACK£©ÊÇÒ»ÖÖÔÚ¶à¸öÑïÆúµÄ¶ÎµÄÇéÐÎϽâ¾ö´ËÐÐΪµÄÕ½ÂÔ ¡£Í¨¹ýÑ¡ÔñÐÔÈ·ÈÏ £¬Êý¾ÝÎüÊÕ·½¿ÉÒÔÏò·¢ËÍ·½Í¨ÖªÒÑÀֳɵִïµÄËùÓжÎ £¬Òò´Ë·¢ËÍ·½Ö»ÐèÖØд«ÊäÏÖʵɥʧµÄ¶Î ¡£ÏêϸѡÔñÐÔÈ·ÈÏÀú³Ì £¬ÈçÏÂͼËùʾ ¡£


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


×î´ó·Ö¶Î´óÐ ¡£¨Maximum Segment Size£©


MSS£¨Maximum Segment Size £¬×î´ó±¨ÎĶδóÐ ¡£©µÄ¿´·¨ÊÇÖ¸TCP²ãËùÄܹ»ÎüÊÕµÄ×î´ó·Ö¶Î¾Þϸ £¬¸ÃÖµÖ»°üÀ¨TCP¶ÎµÄÊý¾Ý²¿·Ö £¬²»°üÀ¨Option²¿·Ö ¡£ÁíÍâ £¬ÔÚTCPÊײ¿ÓÐÒ»¸öMSSÑ¡Ïî £¬ÔÚÈý´ÎÎÕÊÖÀú³ÌÖÐ £¬TCP·¢ËͶËʹÓøÃÑ¡Ïî¸æË߶Է½×Ô¼ºËùÄܽÓÊܵÄ×î´ó·Ö¶Î¾Þϸ ¡£


TSO£¨TCP Segmentation Offload£©


TSOÊÇÒ»ÖÖʹÓÃÍø¿¨À´¶Ô´óÊý¾Ý°ü¾ÙÐÐ×Ô¶¯·Ö¶Î £¬½µµÍCPU¸ºÔصÄÊÖÒÕ ¡£ÆäÖ÷ÒªÊÇÑӳٷֶΠ¡£


GSO(Generic Segmentation Offload)


GSOÊÇЭÒéÕ»ÊÇ·ñÍƳٷֶÎ £¬ÔÚ·¢Ë͵½Íø¿¨Ö®Ç°ÅжÏÍø¿¨ÊÇ·ñÖ§³ÖTSO £¬ÈôÊÇÍø¿¨Ö§³ÖTSOÔòÈÃÍø¿¨·Ö¶Î £¬²»È»Ð­ÒéÕ»·ÖÍê¶ÎÔÙ½»¸øÇý¶¯ ¡£ÈôÊÇTSO¿ªÆô £¬GSO»á×Ô¶¯¿ªÆô ¡£


Îó²îÔ­Àí


CVE-2019-11477


ƾ֤²¹¶¡¿ÉÖª £¬¸ÃÎó²îÊÇÓÉÒ»¸ö16bitÎÞ·ûºÅÊýÒç³öµ¼ÖµÄ £¬¸ÃÎÞ·ûºÅÊý±£´æÈçϽṹÌåÖÐ ¡£


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


¸Ãtcp_skb_cb½á¹¹Ìå´æ·Å×ÅTCPÿ¸öÊý¾Ý°üµÄ¿ØÖÆÐÅÏ¢ £¬Æ¾Ö¤×¢ÊÍ¿ÉÖª £¬tcp_gso_segs/sizeÖ»ÓÃÓÚдÐÐÁÐÀú³ÌÖÐ ¡£


LinuxÄÚºËTCP/IPЭÒéջʵÏÖÖÐ £¬Ã¿¸öÊý¾Ý»º³åÇøÊÇÓÉÒ»¸ösk_buff½á¹¹ÌåͳһÖÎÀíµÄ ¡£ÔÚÒ»¸öÍêÕûµÄÊý¾Ý»º³åÇøÖÐskb_endºóÃæ½ôËæ×ÅÒ»¸öskb_shared_info½á¹¹ÌåÊý¾Ý £¬skb_shared_info½á¹¹ÌåÈçÏÂËùʾ£º


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


½á¹¹Ìå×îºóÒ»¸ö³ÉÔ±ÊÇfrags[MAX_SKB_FRAGS]Êý¾Ý ¡£MAX_SKB_FRAGSÉùÃ÷ÈçÏÂËùʾ£º

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


PAGE_SIZEΪ4KBÇéÐÎÏ£¨¼´Ò»¸öÄÚ´æÒ³ÃæΪ4KB´óÐ ¡£© £¬MAX_SKB_FRAGSȡֵΪ65536/4096 + 1¼´17 £¬Òò´ËÒ»¸öskbÖÐ×î¶àÈÝÄÉ17¸öÊý¾Ý·ÖƬ ¡£¹ØÓÚx86ϵͳ £¬Ã¿¸öÊý¾Ý·ÖƬ×î¶à¿ÉÒԼͼ32KBÊý¾ÝµÄ¾Þϸ ¡£
Êý¾Ý·ÖƬskb_frag_struct½á¹¹ÌåÈçÏÂËùʾ£º


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


ÔÚÕû¸öЭÒéÕ»²Ù×÷Àú³ÌÖÐ £¬Êý¾Ý°ü¼ÈÒª¾ÙÐÐIP±»·ÖƬµÄ £¬ÓÖÒª¾ÙÐÐTCP·Ö¶Î ¡£´«ÊäÊý¾Ýʱ £¬Ð­ÒéÕ»»áƾ֤GSOÖµ £¬MSSÖµÒÔ¼°»¬¶¯´°¿ÚÈýÕßÖ®¼äµÄ¾Þϸ¹ØϵÅжÏÊÇ·ñ¾ÙÐзÖƬ ¡£²¢Í¨¹ýtcp_set_skb_tso_segs()º¯ÊýÉèÖÃGSO £¬ÏêϸʵÏÖÈçÏÂͼËùʾ£º


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


ÈôÊÇskb->len´óÓÚmss_now £¬ÐÐ1207 £¬½«tcp_gso_segsÉèÖÃΪskb->len/mss_now ¡£ÐÐ1208 £¬½«tcp_gso_sizeÉèÖÃΪmss_now ¡£


ÈôÊÇÆôÓÃÁËSACK £¬ÔÚ±¬·¢¶ª°üºó £¬ÎüÊն˻᷵»ØSACK¿é £¬SACK¿éÖмͼ×Åɥʧ°üµÄÐòÁбàºÅ ¡£·¢ËͶ˻áÆÊÎöSACK¿éÖмͼµÄɥʧ°üÐòÁбàºÅ £¬²¢ÖØд«Êä £¬²¢ÇÒÔÚÒ»¸ö»¬¶¯´°¿ÚÖпÉÄÜ°üÀ¨¶à¸öSACK¿é £¬SACK¿éÖÐÒ²¿ÉÄÜ°üÀ¨¶à¸öskbÐÐÁÐ ¡£ÔÚTCPÖØ´«Êý¾Ý°üÀú³ÌÖÐ £¬¿ÉÒÔ½«¶à¸öskbÐÐÁкϲ¢µ½Ò»¸öskbÐÐÁÐÖоÙÐÐÖØ´« ¡£


tcp_shift_skb_data()º¯ÊýʵÏÖÕâ¸ö¹¦Ð§ ¡£ÊµÑ齫¿çÔ½¶à¸öskbµÄSACK¿éÕÛµþΪһ¸öskb ¡£Òªº¦´úÂëÈçÏ£º


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


skb_shift()ºÍtcp_shifted_skb()Á½¸öº¯ÊýÖ÷ҪʵÏָù¦Ð§ ¡£ÖØ´«Àú³ÌÖжà¸öskbÐÐÁкϲ¢µ½Ò»¸öskbÐÐÁÐÖÐ £¬ÈôÊÇÌî³ä17¸ö·ÖƬµ½×î´óÈÝÁ¿ £¬ 17*32*1024/8=69632 £¬ÒѾ­´óÓÚ65535 £¬µ¼ÖÂÎÞ·ûºÅÕûÊýÒç³ö ¡£


ÔÚskb_shift ()º¯ÊýÖÐ £¬tcp_gso_segsÒç³öºó £¬½øÈëtcp_shifted_skb()º¯Êýºó £¬ÈçÏÂËùʾ£º


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


ÐÐ1299 £¬ÅжÏtcp_gso_segsºÍpcountµÄ¾Þϸ £¬ÈôÊÇtcp_gas_segsСÓÚpcount £¬BUG_ON¶ÏÑÔ´¥·¢µ¼ÖÂÄÚºËÍ߽⠡£


ƾ֤²¹¶¡¿ÉÖª £¬skb_shift()±»tcp_skb_shift()È¡´ú £¬Ö»ÊǼÓÁËÁ½¸öÅжÏ £¬ÈçÏÂËùʾ£º

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


²¹¶¡Öл®·ÖÅжÏÁËskb->len+shift_len²»¿É´óÓÚ65535*8×Ö½ÚºÍtcp_skb_pcount(to) + pcount²»¿É´óÓÚ65535 ¡£µÚÒ»¸öÅжÏ £¬skb->lenÊÇÌåÏÖsk_buff½á¹¹ÌåÖÐÌåÏÖpayload³¤¶È £¬shift_lenÌåÏÖÒªºÏ²¢µ½skbÖеÄpayload ¡£


CVE-2019-11478


¸ÃÎó²îÒ²ÊÇÕûÊýÒç³ö £¬ÔÚÊý¾Ý°üÖØд«ÊäÀú³ÌÖÐ £¬½«´«ÊäÐÐÁзֶÎΪ¶à¸öϸСµÄskbs £¬ÅòÕÍskbÖÐдÐÐÁÐÄڴ汬·¢Òç³ö ¡£ÔÚ´¦Öóͷ£SACK¿éÖаüÀ¨µÄskb²¢½«ÆäºÏ²¢ºó £¬Æ¾Ö¤GSOÅжϾÙÐÐÊÇ·ñ·ÖƬ £¬ÈôÊÇÐèÒª £¬Å²ÓÃtcp_fragement()º¯Êý¾ÙÐзÖƬ ¡£Æ¾Ö¤²¹¶¡¿ÉÖª£º


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


²¹¶¡ÔÚtcp_fragment()º¯ÊýÖмÓÈëÁË×îС¿Õ¼äÅжÏ ¡£SkÊÇsock½á¹¹ÌåÀàÐÍ £¬Ã¿Ò»¸ötcpÁ´½Ó¶ÔÓ¦Ò»¸ö ¡£ÒÔÊÇËùÓÐÒª·¢Ë͵ÄskbÊý¾Ý¾Þϸ¶¼ÒªÀÛ¼Óµ½sk->sk_wmem_queuedÖÐ £¬sk->sk_wmem_queuedÌåÏÖΪ¸ÃÌ×½Ó×ÖTCPдÐÐÁлº³åÇø¾Þϸ ¡£Í¨³£ÔÚʹÓÃʱ¼äÐèÒªÅжϸÃÖµÊÇ·ñ¹»Óà ¡£ÈçÏÂËùʾ£º


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


ƾ֤עÊÍ¿ÉÖª £¬ÅжÏ×îÐÂÅŶÓskb°üËùÐèµÄ×îС¿Éд¿Õ¼ä ¡£²¹¶¡ÖÐ £¬ÅжÏÊ£Óà·¢ËÍ»º´æΪ´óÓÚ¼´ÊÇÄ¿½ñ·¢ËÍÐÐÁÐÕ¼ÓÿռäµÄÒ»°ë £¬¼´ÉÐÓÐ1/3ÒÔÉϵĿÕÓà¿Õ¼äʱ £¬²¢ÇÒСÓÚsk->sk_sndbuf·¢ËÍÉÏÏ޲ſÉÒÔÕý³£·¢ËÍ £¬²»È»¾ÍÅжÏTCPдÐÐÁÐÌ«´ó ¡£


CVE-2019-11479


¸ÃÎó²îÓÉÓÚÌ«¹ýÏûºÄ×ÊÔ´µ¼Ö¾ܾø·þÎñ ¡£ÈôÊǶñÒâÊý¾Ý°ü½«MSSÑ¡ÏîÉèÖóɽÏСֵ £¬Õ⽫ÆÈʹЭÒéÕ»ÆƷѺÜÊǸߵÄÍøÂç»òCPU×ÊÔ´·¢ËÍÊý¾Ý°ü¿ªÏú ¡£LinuxÄÚºËÖн«MSS_NOWÓ²±àÂëΪ48 ¡£Æ¾Ö¤²¹¶¡¿ÉÖª£º

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


¾ÙÐÐÁËmax×î´óÖµÅжÏ £¬¶ø²»ÔÙÊÇÀο¿Ó²±àÂë ¡£ÕâÀïµÄsysctl_tcp_min_snd_mss±»ÉèÖÃΪ65535 £¬ÈçÏÂËùʾ£º


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


×èÖ¹Á˹¥»÷ÕßʹÓü«Ð¡MSSÖµ ¡£


Ó°Ïì°æ±¾¼°²¹¶¡ÐÞ¸´


ʵʱ¸üÐÂ×îв¹¶¡»ò½ûÓÃSACKºÍ¹ýÂ˼«Ð¡MSSµÄÊý¾Ý°ü ¡£


CVE-2019-11477

Ó°Ïì°æ±¾£º

  • Linux 2.6.29 ~ 4.19.13£¨stable kernel releases 4.4.182,  4.9.182, 4.14.127, 4.19.52, 5.1.11³ýÍ⣩

  • RHEL 8 (kernel, kernel-rt) £¬RHEL 7 (kernel, kernel-rt) £¬RHEL 6

½ûÓÃsack£º

  • sudo sysctl -w net.ipv4.tcp_sack=0

²¹¶ ¡£º

  • https://git.kernel.org/pub/scm/linux/kernel/git/davem/net.git/commit/?id=3b4929f65b0d8249f19a50245cd88ed1a2f78cff

CVE-2019-11478

Ó°Ïì°æ±¾£º

  • Linux 2.6.29 ~ 4.19.13£¨stable kernel releases 4.4.182,  4.9.182, 4.14.127, 4.19.52, 5.1.11³ýÍ⣩

  • RHEL 8 (kernel, kernel-rt) £¬RHEL 7 (kernel, kernel-rt) £¬RHEL 6 £¬RHEL 5

½ûÓÃsack£º

  • sudo sysctl -w net.ipv4.tcp_sack=0

²¹¶ ¡£º

  • https://git.kernel.org/pub/scm/linux/kernel/git/davem/net.git/commit/?id=f070ef2ac66716357066b683fb0baf55f8191a2e

CVE-2019-11479

Ó°Ïì°æ±¾£º

  • Linux 2.6.29 ~ 4.19.13£¨stable kernel releases 4.4.182,  4.9.182, 4.14.127, 4.19.52, 5.1.11³ýÍ⣩

  • RHEL 8 (kernel, kernel-rt) £¬RHEL 7 (kernel, kernel-rt) £¬RHEL 6 £¬RHEL 5

¹ýÂËÏÂÁ

  • sudo iptables -A INPUT -p tcp -m tcpmss --mss 1:500 -j DROP

¹Ø±Õtcp_mtu_probing£º

  • sysctl net.ipv4.tcp_mtu_probing

²¹¶ ¡£º

  • https://git.kernel.org/pub/scm/linux/kernel/git/davem/net.git/commit/?id=5f3e2bf008c2221478101ee72f5cb4654b9fc363

  • https://git.kernel.org/pub/scm/linux/kernel/git/davem/net.git/commit/?id=967c05aee439e6e5d7d805e195b3a20ef5c433d6