UbuntuÄÚºËOverlayFSȨÏÞÌÓÒÝÎó²îÆÊÎö£¨CVE-2021-3493£©

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

±³  ¾°


ƾ֤¹Ù·½ÏÈÈÝ £¬OverlayFsÎó²îÔÊÐíUbuntuϵÄÍâµØÓû§»ñµÃrootȨÏÞ¡£Õâ¸öÎó²îÊÇUbuntuϵͳÖеÄÌض¨ÎÊÌâ £¬ÔÚ¸ÃÎÊÌâÖÐ £¬Î´×¼È·ÑéÖ¤¹ØÓÚÓû§namespaceÎļþϵͳ¹¦Ð§µÄÓ¦ÓóÌÐò¡£ÓÉÓÚUbuntu¸½´øÁËÒ»¸öÔÊÐí·ÇÌØȨµÄOverlayfs¹ÒÔصIJ¹¶¡ £¬ÍŽáÕâ¸ö²¹¶¡¹ÒÔØOverlayfs¿ÉÒÔȨÏÞÌÓÒÝ £¬µÖ´ïȨÏÞÌáÉýµÄÄ¿µÄ¡£


Ó°Ïì°æ±¾


Ubuntu 20.10

Ubuntu 20.04 LTS

Ubuntu 18.04 LTS

Ubuntu 16.04 LTS

Ubuntu 14.04 ESM


Îó²î¸´ÏÖ


Ê×ÏÈÉó²éÄں˰汾 £¬ÎªÊÜÓ°Ïì°æ±¾±àÒëexploitºóÖ´ÐÐ £¬ÌáȨÀֳɡ£ÈçÏÂͼËùʾ£º


1.jpg


Ïà¹ØÏÈÈÝ


£¨1£©ÐéÄâÎļþϵͳ

Ϊ֧³ÖÖÖÖÖ±¾»úÎļþϵͳ £¬ÇÒÔÚͬʱÔÊÐí»á¼ûÆäËû²Ù×÷ϵͳµÄÎļþ £¬LinuxÄÚºËÔÚÓû§Àú³Ì£¨»òC±ê×¼¿â£©ºÍÎļþϵͳʵÏÖÖ®¼äÒýÈëÁËÒ»¸öÁýͳ²ã¡£¸ÃÁýͳ²ã³Æ֮ΪÐéÄâÎļþϵͳ£¨Virtual File System£©¼ò³ÆVFS £¬ÈçÏÂͼËùʾ£º


2.jpg


VFSΪËùÓеÄÎļþϵͳÌṩÁËͳһµÄ½Ó¿Ú £¬¶Ôÿ¸öÏêϸÎļþϵͳµÄ»á¼ûҪͨ¹ýVFS½ç˵µÄ½Ó¿ÚÀ´ÊµÏÖ¡£VFSÁýͳÁ˼¸¸öÖ÷ÒªµÄ½á¹¹£ºsuper_block £¬dentry £¬inode £¬file £¬Í¨¹ýÕâЩ½á¹¹½«Ò»¸öÕæʵµÄÎļþÏÏû³Áýͳµ½ÄÚ´æÖÐ £¬´Ó¶øͨ¹ýÖÎÀíÕâЩ¹¤¾ß¶ÔÎļþϵͳ¾ÙÐвÙ×÷¡£


£¨2£©OverlayÎļþϵͳ

OverlayFSÊÇÒ»¸öÃæÏòLinuxµÄÎļþϵͳ·þÎñ £¬×ÅʵÏÖÒ»¸öÃæÏòÆäËûÎļþϵͳµÄÍŽá¹ÒÔØ¡£ËüÓÚ2014Äê±»ºÏ²¢µ½LinuxÄں˵Ä3.18°æ±¾¡£OverlayFSµÄÖ÷Òª»úÖÆÉæ¼°µ½Á½¸öÎļþϵͳ £¬ÌṩͳһÃû³ÆµÄĿ¼ʱ £¬Ä¿Â¼»á¼ûºÏ²¢¡£³ý´ËÖ®Íâ £¬OverlayFS·ºÆðÆäÖÐÒ»¸öËù±¬·¢µÄ¹¤¾ß £¬¡°Éϲ㡱ÎļþϵͳÓÅÏÈ¡£OverlayFSÓëÆäËûÁýÕÖÐÍÎļþϵͳ²î±ð £¬OverlayFSºÏ²¢µÄĿ¼×ÓÊ÷·×Æ綨ÊÇÀ´×Ô²î±ðµÄÎļþϵͳ¡£Ð§¹ûÈçÏÂͼËùʾ£º


3.jpg


Æä¹ÒÔØÎļþµÄ»ù±¾ÏÂÁîÈçÏ£º

mount -t overlay overlay -o lowerdir=lower1:lower2:lower3,upperdir=upper,workdir=work merged¡£


ÆäÖС°lower1:lower2:lower3¡±ÌåÏÖ²î±ðµÄlower²ãĿ¼ £¬²î±ðµÄĿ¼ʹÓá°:¡±ÍÑÀë £¬ÌõÀí¹ØϵÒÀ´ÎΪlower1 > lower2 > lower3£¨×¢£º¶àlower²ã¹¦Ð§Ö§³ÖÔÚLinux-4.0ºÏÈë £¬Linux-3.18°æ±¾Ö»ÄÜÖ¸¶¨Ò»¸ölower dir£©,È»ºóupperºÍworkĿ¼»®·ÖÌåÏÖ£ºupper²ãĿ¼ºÍÎļþϵͳ¹ÒÔغó £¬ÓÃÓÚ´æ·ÅÔÝʱºÍ¼ä½ÓÎļþµÄÊÂÇé»ùĿ¼£¨work base dir£© £¬×îºóµÄmergedĿ¼¾ÍÊÇ×îÖյĹÒÔصãĿ¼¡£ÈôÒ»ÇÐ˳Ëì £¬ÔÚÖ´ÐÐÒÔÉÏÏÂÁîºó £¬overlayfs¾ÍÀֳɹÒÔص½mergedĿ¼ÏÂÁË¡£


£¨3£©capabilitiy

ΪÁ˾ÙÐÐȨÏÞ¼ì²é £¬Linuxϵͳ½«Àú³Ì·ÖΪÁËÁ½ÀࣺprivilegedÀú³Ì£¨effective UIDΪ0£©ºÍ unprivileged Àú³Ì£¨effective UIDΪ·Ç0£©¡£privilegedÀú³Ì¿ÉÒÔÈƹýËùÓеÄÄÚºËȨÏÞ¼ì²é £¬¶øunprivileged Àú³ÌÒª¾ÙÐÐÑÏ¿áµÄȨÏÞ¼ì²é¡£´Ó2.2°æ±¾µÄÄÚºË×îÏÈ £¬linux¶ÔȨÏÞ¾ÙÐÐÁËϸ·Ö £¬·ÖΪ¶àÖÖ²î±ðµÄȨÏÞ £¬³Æ֮Ϊcapability¡£capability¿ÉÒÔ×÷ÓÃÔÚÀú³ÌÉÏ £¬Ò²¿ÉÒÔ×÷ÓÃÔÚ³ÌÐòÎļþÉÏ¡£ÏÖÔÚ £¬LinuxϵͳÉÏʵÏÖÁË37ÖÖcapability¡£


ÿ¸öÀú³Ì¶¼ÓÐÎå¸öcapabilityÜöÝÍ£ºPermitted £¬Inheritable £¬Effective £¬Ambient £¬Bounding¡£ÎļþµÄcapabilityÉúÑÄÔÚÎļþµÄÀ©Õ¹ÊôÐÔsecurity.capabilityÖС£ÎļþÓÐÈý¸öcapabilitiyÜöÝÍ£ºPermitted £¬Inheritable £¬Effective¡£ÎļþµÄcapabilityºÍÀú³ÌµÄcapabilityÒ»ÆðÀ´¾öÒéÔÚÖ´ÐÐexecveºó £¬Àú³ÌµÄcapability¡£


Îó²îÔ­Àí


£¨1£©OverlayFS¹ÒÔØ

ͨ³£ÇéÐÎÏ £¬¹ÒÔØÎļþϵͳÊÇÐèÒªÌØȨµÄ £¬¿ÉÊÇÔÚUbuntuϵͳÖÐ £¬Í¨Ë×Óû§±ã¿ÉÒÔ¹ÒÔØOverlayFS¡£ÒÔ5.4.0°æ±¾ÄÚºËÖ÷Ïß´úÂëΪÀý £¬ovl_fs_type½á¹¹Ìå½ç˵ÈçÏÂͼËùʾ£º

 

4.jpg


ÒÔUbuntu20.04µÄÄں˲¹¶¡linux_5.4.0-26.30.diffΪÀý £¬²¹¶¡ÈçÏÂͼËùʾ£º

 

5.jpg


Ìí¼ÓÁËfs_flagsÊý¾ÝÓò £¬²¢ÉèÖÃΪFS_USERNS_MOUNT £¬ÌåÏÖ½«ÔÊÐíÒ»¸öͨË×Óû§ÔÚµÍȨÏÞÓû§ÃüÃû¿Õ¼äÖÐmoutÒ»¸öoverlayfsÎļþϵͳ¡£µ±È¥mountÒ»¸öoverlayfsÎļþϵͳʱ £¬Å²Ó÷¾¶ÈçÏÂͼËùʾ£º


6.jpg


»áŲÓõ½do_new_mount()º¯Êý £¬¸Ãº¯ÊýÊǽ¨ÉèÒ»¸öеÄmount £¬²¢½«Æä·ÅÈënamespaceÊ÷ÖÐ £¬ÊµÏÖ´úÂëÈçÏÂͼËùʾ£º


7.jpg


ÐÐ2792 £¬»ñÈ¡Òª¹ÒÔصÄÎļþϵͳÀàÐÍ £¬ÕâÀïÊÇoverlay¡£È»ºó¾ÍÊǾÙÐÐcapabilitiyУÑé £¬ÈçÏÂͼËùʾ£º


8.jpg


ÓÉÓÚfs_flags±»ÉèÖÃΪFS_USERNS_MOUNT £¬½øÈëns_capable()º¯Êý £¬×îºóͨ¹ýÄ¥Á·ºó £¬ÈçÏÂͼËùʾ£º


9.jpg


²¢ÇÒÉèÖÃcurrent->flagsΪPF_SUPERPRIV £¬¼´ÔÚÄ¿½ñÀú³ÌÉÏÉèÖó¬µÈȨÏÞ £¬²¢·µ»Øture¡£ÒÔÊÇͨ¹ý¹ÒÔØoverlayÎļþϵͳ £¬Ä¿½ñÀú³Ì¾ß±¸Á˳¬µÈȨÏÞ¡£


 £¨2£©È¨ÏÞÌÓÒÝ

¸ÃÎó²îÊÇÔÚsetxattr()º¯ÊýÖб¬·¢µÄ £¬µ±¶ÔÎļþÀ©Õ¹ÊôÐÔµÄcapabilitiy¾ÙÐÐÉèÖÃʱ £¬È¨ÏÞУÑé²»³¹µ×¡£ÏÂÃæÊÇ"SSD Secure Disclosure"Åû¶µÄExpÖ´ÐÐÇéÐÎ £¬Å²Ó÷¾¶ÈçÏÂͼËùʾ£º


10.jpg


ÕâÀïpathnameΪ¡°./ovlcap/merge/magic¡± £¬ÐÐ468 £¬Å²ÓÃcap_convert_nscap()º¯Êý £¬½«ÒªÉèÖõÄcapת»»µ½nscapÖÐ £¬ÈçÏÂͼËùʾ£º


11.jpg


½øÈëcap_convert_nscap()º¯Êý £¬¾ÙÐÐÏà¹Ø¼ì²âºó £¬ÈôÊÇÊÇcapabilitiy°æ±¾2 £¬ÔòÖ±½ÓŲÓÃns_capable()¾ÙÐÐÄ¥Á· £¬Æ¾Ö¤×¢ÊÍ¿ÉÖª £¬ÈôÊÇuserÓ㬵ÈȨÏÞ £¬Ö±½ÓдÈë²¢·µ»Ø¡£


12.jpg


ºÁÎÞÒÉÎÊ £¬ÕâÀïÒ»¶¨ÊÇÄ¥Á·Í¨¹ýµÄ¡£´òÓ¡Òªº¦ÄÚ´æ £¬ÈçÏÂͼËùʾ£º


13.jpg


¼Ä´æÆ÷raxΪ0x1 £¬ÌåÏÖ·µ»Øture¡£ÓÉÓÚÄ¿½ñ»á¼ûµÄinodeÊôÓÚoverlayÎļþϵͳµÄ¡£´Ócap_convert_nscap()º¯Êý׼ȷ·µ»Øºó £¬Ëæ¼´½øÈëvfs_setxattr()º¯Êý £¬ÕâÊǵÚÒ»´Î½øÈë¡£½ÓÏÂÀ´¾ÍÊÇ·Ö·¢µ½overlayÎļþϵͳ¶ÔÓ¦µÄovl_xattr_set()º¯ÊýÖÐ £¬Å²Ó÷¾¶ÈçÏÂͼËùʾ£º


14.jpg


¿´ovl_xattr_set()º¯ÊýµÄ²¿·ÖʵÏÖ´úÂë £¬»ñÈ¡upperdentryºÍrealdentry £¬ÈçÏÂͼËùʾ£º


15.jpg


»ñÈ¡ºó £¬´òÓ¡upperdentryºÍrealdentryÄÚ´æ £¬ÈçÏÂͼËùʾ£º


16.jpg


ƾ֤overlayÎļþϵͳÌØÕ÷ £¬ÕâÀïµÄupperdentryºÍrealdentryÓ¦¸ÃÊÇ¡°./ovlcap/upper¡±Ä¿Â¼ÏµÄmagicµÄĿ¼Ïî £¬´òÓ¡ÄÚ´æ¿ÉÖª £¬ÈçÏÂͼËùʾ£º


17.jpg


È·¶¨ÕæʵµÄdentryºó £¬µÚ¶þ´ÎŲÓÃvfs_setxattr()º¯Êý £¬ÈçÏÂͼËùʾ£º


18.jpg


´ËʱµÄdentryÊÇÊôÓÚext3ÎļþϵͳµÄ £¬´òÓ¡ÄÚ´æ¿ÉÖª £¬ÈçÏÂͼËùʾ£º


19.jpg


µ½´Ë¿ÉÖª £¬ÏÖʵÉÏÊǶÔext3Îļþϵͳϵġ°./ovlcap/upper/magic¡±¾ÙÐÐÉèÖÃcap¡£È¨ÏÞÌÓÒÝÀú³ÌÈçÏÂͼËùʾ£º


20.jpg


Îó²îʹÓÃÆÊÎö


"SSD Secure Disclosure"¹Ù·½ÒѾ­Åû¶ÁËÏà¹ØExp £¬ÏêϸÆÊÎöÈçÏ£º

 

21.jpg


ÕâÀï½ç˵ºóÃæ¹ÒÔØoverlayÎļþϵͳµÄÎļþ¼ÐÃû³Æ:


22.jpg


²¢×Ô½ç˵xmkdirº¯Êý½¨ÉèÕâЩÎļþ¼Ð:


23.jpg


È»ºó»ñÈ¡Ä¿½ñÓû§µÄuidºÍgid£º

 

24.png


½¨ÉèеÄuser namespace £¬ÓÉÓÚoverlayfs mountÐèÒªCAP_SYS_MOUNTÄÜÁ¦ £¬Òò´ËÐèҪн¨Ò»¸öNEWUSERµÄnamespace £¬ÕâÑù¾Í¾ßÓÐCAP_SYS_MOUNT £¬


25.jpg


CLONE_NEWNSºÍCLONE_NEWUSER½ç˵£º


26.jpg


ÓÃÄ¿½ñÓû§µÄuidºÍgidµÈ¸Äд/proc/selfϵĶÔÓ¦Îļþ £¬²¢ÇÒÓøÃȨÏÞϵÄnamespace¹ÒÔØoverlayfs £¬Ç°Ãæ¼ò½é˵ÁË £¬ÓÉÓÚubuntuµÄ²¹¶¡±£´æ £¬¸Ã²Ù×÷ÊÇÕýµ±µÄ¡£


27.jpg


 ¶ÔӦĿ¼Ï¿ÉÒÔ¿´µ½ÎÒÃÇÐÞ¸ÄÁ˵ÄÎļþ £¬Í¨¹ý/proc/self/exe¿ÉÒÔÕÒµ½Ä¿½ñÀú³ÌµÄ¶þ½øÖÆʵÌ壨Îļþ£©£º


28.jpg


¼ÌÐø»Øµ½expÖÐ £¬ÏÂÃæ½á¹¹ÁËÒ»¸öcap £¬¸Äcap½ç˵µÄpermittedΪ0xffffffff £¬²¢ÇÒ¿ªÆôEffective £¬È»ºó½«/proc/selfϵÄÎļþ¿½±´µ½mergeÎļþ¼ÐÏ £¬Æ¾Ö¤overlayÎļþϵͳÌØÕ÷ £¬Õâ¸ö¿½±´Àú³ÌÏÖʵÊǽ¨Éè./ovlcap/upper/magicÎļþ £¬×îºóŲÓÃsetxattr()º¯Êý £¬½«capÉèÖõ½./ovlcap/merge/magicÉÏÃæ¡£


29.jpg


ƾ֤ǰÎÄÎó²îÔ­ÀíÏÈÈÝ £¬È¨ÏÞÌÓÒݺó £¬´ËʱÊôÓÚext3ÎļþϵͳµÄ./ovlcap/upper/magicÎļþµÄcapabilitiyΪall+ep £¬±ã¿ÉÒÔʹÓÃcapabilitiy¾ÙÐÐȨÏÞÌáÉý £¬½Ó×ÅÆô¶¯./ovlcap/upper/magicÀú³Ì £¬¸ÃÀú³ÌµÄcapabilitiyÒѾ߱¸all+ep £¬È»ºó¾ÙÐÐsetuid(0)ºÍsetgid(0)ÌáȨ²Ù×÷ £¬ÕâÊDZ»ÔÊÐíµÄ¡£


30.jpg


²¹¶¡¸ú×Ù


Îó²î³ÉÒòÔÚÉÏÃæÒѾ­ÏÈÈÝÁË £¬ÕâÀïµÄ²¹¶¡Ò²ºÜ³¹µ× £¬½«cap_convert_nscap·ÅÈëÁËvfs_setxattrÖÐ £¬¼´Ã¿´Î½øÈëvfs_setxattr()º¯Êýʱ £¬¶¼ÏȾÙÐÐȨÏÞУÑé £¬ÅжÏcapabilitiyºÍÃüÃû¿Õ¼äµÄȨÏÞÊÇ·ñÆ¥Åä¡£


31.jpg


²Î¿¼Á´½Ó£º

[1] https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2021-3493

[2] https://access.redhat.com/security/cve/cve-2021-3493
[3] https://ubuntu.com/security/CVE-2021-3493
[4] https://github.com/briskets/CVE-2021-3493
[5] https://cve.report/CVE-2021-3493.pdf
[6] https://blog.csdn.net/qq_15770331/article/details/96699386
[7] https://lwn.net/Articles/671641/
[8] https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1793458/comments/4
[9] https://git.launchpad.net/~ubuntu-kernel/ubuntu/+source/linux/+git/xenial/commit/?id=98a3740920f8f3362c1ac50598af2dc632f5051a


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


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


adlab.jpg