ClickHouse¶à¸ö©¶´ÔÀí·ÖÎö
Ðû²¼Ê±¼ä 2022-03-21Ò»¡¢Â©¶´¸ÅÊö
ClickHouseÊǶíÂÞ˹yandex¹«Ë¾ÓÚ2016Ä꿪ԴµÄÔÆÊý¾Ý¿â¹ÜÀíϵͳ£¬ClickHouse¹ã·ºÓ¦ÓÃÓÚÔÆƽ̨µÄ´óÊý¾Ý·ÖÎöÓ¦ÓÃÖУ¬ÆäÓû§°üÂÞuber¡¢ebay¡¢µÂÒâÖ¾ÒøÐС¢°¢Àï°Í°Í¡¢ÌÚѶµÈ¡£
©¶´Ó°ÏìÁËClickHouse 21.10.2.15°æ±¾Ö®Ç°µÄËùÓа汾¡£¾ßÌ婶´ÃèÊöÈçϱíËùʾ£º
¶þ¡¢´¦Öý¨Òé
2021Äê10ÔÂ18ÈÕÐû²¼µÄClickHouse 21.10.2.15°æ±¾ÐÞ¸´ÁËÉÏÊöµÄ7¸ö©¶´£¬Ç뾡¿ìÉý¼¶µ½ClickHouse 21.10.2.15¼°ÒÔºóµÄ°æ±¾¡£
https://github.com/ClickHouse/ClickHouse/releases/
»º½â´ëÊ©£º
Èý¡¢Â©¶´·ÖÎö
ÕâЩ©¶´¶¼´æÔÚClickHouse Server´¦ÖÃѹËõÊý¾ÝµÄÇëÇó´¦Öùý³ÌÖУ¬ClickHouse ServerÖ§³Ö¶ÔÓû§ÇëÇóµÄ¸½´øÊý¾Ý½øÐÐѹËõ¡£Óû§¿ÉÒÔÔÚÌᳫWEBÇëÇóʱ£¬½«decompress±êÖ¾ÉèΪ1¼´¿É£¬¾ÙÀýÈçÏ£º
²éѯµÄ¸½´øÊý¾Ý(query.bin)¿ÉÒÔ°´ÏÂÃæµÄ½á¹¹½øÐÐ×éÖ¯£º
ClickHouseÖ§³Ö¶àÖÖѹËõ¸ñʽ£¬°üÂÞLZ4¡¢Gorilla¡¢DeltaµÈ¶àÖÖѹËõËã·¨¡£ClickHouse Serverƾ¾ÝÇëÇóÖи½´øÊý¾ÝµÄѹËõËã·¨±êʶ£¬µ÷ÓòîÒìµÄ½âѹËã·¨À´¶ÔÊý¾Ý½øÐнâѹ¡£
3.1 LZ4Ëã·¨½éÉÜ
LZ4ѹËõËã·¨ÊÇLZË㷨ϵÁÐÖеÄÒ»ÖÖ£¬Ò²ÊÇÄ¿Ç°×ÛºÏЧÂÊ×î¿ìµÄѹËõËã·¨Ö®Ò»¡£
Ò»¸öLZ4ѹËõ¿éÓɶà¸öLZ4ÐòÁÐ×é³É£¬LZ4ÐòÁÐÓÉÒÔÏÂÊý¾Ý×é³É£¬ÈçÏÂͼËùʾ£º
Token¾ÞϸΪ1×Ö½Ú£¬¸ß4¸öbitsΪ²»ÐÐѹËõÊý¾Ý(literal£©µÄ³¤¶È(literallength)£¬¶øµÍ4¸öbitsΪ¿ÉÒÔѹËõÊý¾Ý(match)³¤¶È(match length)¡£Èç¹ûliterallengthµÄֵΪ0£¬ÔòÌåÏÖºóÐøÊý¾ÝÀïûÓÐliteral¡£ÓÉÓÚliteral lengthÖ»ÓÐ4±ÈÌØÀ´ÌåÏÖ£¬ËüµÄ×î´óֵΪ15¡£µ±literalÊý¾ÝµÄ¾Þϸ´óÓÚ¼´ÊÇ15ʱ£¬ÐèÒªÔÚToken×ֶκóÌí¼Ó¸ñÍâµÄ×Ö½ÚÀ´ÌåÏÖliteralµÄ³¤¶È£¨Literal length+£©¡£
MatchÖ¸Öظ´Ï¿ÉÒÔѹËõµÄ²¿ÃÅ¡£
src/Compression/LZ4_decompress_faster.cppµÄdecompressImplº¯ÊýÔÚ¿½±´LZ4ÐòÁÐÊý¾ÝµÄliteralʱ£¬Ã»ÓÐÅжϸ´ÖƵÄÊý¾ÝÊÇ·ñÁè¼ÝÄ¿±ê»º³åÇøµÄÏÞÖÆ¡£µ±ÐèÒª¸´ÖƵÄÊý¾ÝÁè¼ÝÄ¿±ê»º´æµÄ¾Þϸʱ£¬»áµ¼Ö¶ÑÒç³ö¡£
ÈçÉÏͼ´úÂëËùʾ£¬ipÊÇÖ¸ÏòѹËõ»º³åÇøµÄÖ¸Õë¡£opÊÇÖ¸Ïò·ÖÅäµÄÄ¿±ê»º³åÇøµÄÖ¸Õ룬¸ÃÄ¿±ê»º³åÇøµÄ¾ÞϸΪ±¨Í·Öиø¶¨µÄ½âѹ¾Þϸ¡£copy_endÊÇÖ¸Ïò¸´ÖÆÇøÓòÄ©¶ËµÄÖ¸Õë¡£
¹¥»÷Õß¿ÉÒԽṹ¶ñÒâµÄLZ4ÐòÁÐÊý¾Ý£¬ÆäÖÐliteraµÄ³¤¶È(length±äÁ¿)´óÓÚdest_size£¬½«µ¼Ö¶ÑÒç³ö¡£
3.4 CVE-2021-43305©¶´ÔÀí
3.5 CVE-2021-42388¼°CVE-2021-42387©¶´ÔÀí
©¶´´æÔÚsrc/Compression/LZ4_decompress_faster.cppµÄdecompressImplº¯ÊýÖУ¬¸Ãº¯ÊýÖ±½Ó´ÓLZ4ѹËõÊý¾ÝÖжÁÈ¡16λÎÞ·ûºÅÆ«ÒÆÁ¿£¨offset¹¥»÷Õß¿ÉÒÔ¿ØÖÆ£©,¸ÃÆ«ÒÆÁ¿ÓÃÓÚ¼ÆËãwildCopy²Ù×÷µÄÔ´Êý¾ÝµØÖ·¡£µ±offsetµÄֵΪ´óÓÚcopy_amountʱ(Èçoffset = 0xffff£©£¬½«µ¼Ö·¨Ê½½«opµØַ֮ǰµÄÊý¾Ý¿½±´µ½opÖ¸ÏòµÄµØÖ·ÖУ¬´Ó¶øµ¼ÖÂÔ½½ç¶Á¡£
CVE-2021-42387ÊÇCVE-2021-42388µÄÒ»¸öÀàËÆ©¶´£¬ÕâÀï¾Í²»ÔÙ½éÉÜ¡£
ClickHouseÖ§³ÖµÄDoubleDelta±à½âÂëÆ÷¡¢Delta±à½âÂëÆ÷¡¢Gorilla±à½âÂëÆ÷Öж¼´æÔÚ±»Áã³ýµÄ©¶´¡£ËüÃÇ»ùÓÚ½«Ñ¹Ëõ»º³åÇøµÄµÚÒ»¸ö×Ö½ÚÉèÖÃΪÁã¡£½âѹ´úÂë¶ÁȡѹËõ»º³åÇøµÄµÚÒ»¸ö×Ö½Ú£¬²¢¶ÔÆäÖ´ÐÐÄ£ÔËËãÒÔ»ñµÃÊ£Óà×Ö½Ú£¬µ±source[0]Ϊ0ʱ£¬CPU¶Ô0½øÐÐȡģʱ²Ù×÷½«·¢Éú³ý0Òì³£¡£
ËÄ¡¢½áÊøÓï
´óÊý¾Ýʱ´úÏ£¬´óÁ¿Êý¾Ý¾Û¼¯¡¢Á¬½Ó¼°ÍøÂç½çÏÞµÄÑÓÉ춼ΪÊý¾Ý¿âµÄµÄÄþ¾²Ìá³öÁ˸ü¸ßµÄÒªÇó¡£Êý¾Ý¿â×÷ΪÐÅÏ¢¼¼ÊõϵͳµÄºËÐĺͻù´¡£¬³ÐÔØ×ÅÔ½À´Ô½¶àµÄÒªº¦ÒµÎñϵͳ£¬³ÉΪÆóÒµºÍ»ú¹¹×î¾ßÓÐÕ½ÂÔÐԵĺËÐÄÊý¾Ý×ʲú£¬Òò´ËÊý¾Ý¿â·½ÃæµÄÄþ¾²ÖµµÃÎÒÃÇÁ¬Ðø¹Ø×¢¡£
²Î¿¼Á´½Ó£º
[1]https://jfrog.com/blog/7-rce-and-dos-vulnerabilities-found-in-clickhouse-dbms/
[2]https://github.com/ClickHouse/ClickHouse
[3]https://thehackernews.com/2022/03/multiple-flaws-uncovered-in-clickhouse.html