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£©ÐéÄâÎļþϵͳ
Ϊ֧³ÖÖÖÖÖ±¾»úÎļþϵͳ£¬ÇÒÔÚͬʱÔÊÐí»á¼ûÆäËû²Ù×÷ϵͳµÄÎļþ£¬LinuxÄÚºËÔÚÓû§Àú³Ì£¨»òC±ê×¼¿â£©ºÍÎļþϵͳʵÏÖÖ®¼äÒýÈëÁËÒ»¸öÁýͳ²ã¡£¸ÃÁýͳ²ã³Æ֮ΪÐéÄâÎļþϵͳ£¨Virtual File System£©¼ò³ÆVFS£¬ÈçÏÂͼËùʾ£º
VFSΪËùÓеÄÎļþϵͳÌṩÁËͳһµÄ½Ó¿Ú£¬¶Ôÿ¸öÏêϸÎļþϵͳµÄ»á¼ûҪͨ¹ýVFS½ç˵µÄ½Ó¿ÚÀ´ÊµÏÖ¡£VFSÁýͳÁ˼¸¸öÖ÷ÒªµÄ½á¹¹£ºsuper_block£¬dentry£¬inode£¬file£¬Í¨¹ýÕâЩ½á¹¹½«Ò»¸öÕæʵµÄÎļþÏÏû³Áýͳµ½ÄÚ´æÖУ¬´Ó¶øͨ¹ýÖÎÀíÕâЩ¹¤¾ß¶ÔÎļþϵͳ¾ÙÐвÙ×÷¡£
£¨2£©OverlayÎļþϵͳ
OverlayFSÊÇÒ»¸öÃæÏòLinuxµÄÎļþϵͳ·þÎñ£¬×ÅʵÏÖÒ»¸öÃæÏòÆäËûÎļþϵͳµÄÍŽá¹ÒÔØ¡£ËüÓÚ2014Äê±»ºÏ²¢µ½LinuxÄں˵Ä3.18°æ±¾¡£OverlayFSµÄÖ÷Òª»úÖÆÉæ¼°µ½Á½¸öÎļþϵͳ£¬ÌṩͳһÃû³ÆµÄĿ¼ʱ£¬Ä¿Â¼»á¼ûºÏ²¢¡£³ý´ËÖ®Í⣬OverlayFS·ºÆðÆäÖÐÒ»¸öËù±¬·¢µÄ¹¤¾ß£¬¡°Éϲ㡱ÎļþϵͳÓÅÏÈ¡£OverlayFSÓëÆäËûÁýÕÖÐÍÎļþϵͳ²î±ð£¬OverlayFSºÏ²¢µÄĿ¼×ÓÊ÷·×Æ綨ÊÇÀ´×Ô²î±ðµÄÎļþϵͳ¡£Ð§¹ûÈçÏÂͼËùʾ£º
Æä¹ÒÔØÎļþµÄ»ù±¾ÏÂÁîÈçÏ£º
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½á¹¹Ìå½ç˵ÈçÏÂͼËùʾ£º
ÒÔUbuntu20.04µÄÄں˲¹¶¡linux_5.4.0-26.30.diffΪÀý£¬²¹¶¡ÈçÏÂͼËùʾ£º
Ìí¼ÓÁËfs_flagsÊý¾ÝÓò£¬²¢ÉèÖÃΪFS_USERNS_MOUNT£¬ÌåÏÖ½«ÔÊÐíÒ»¸öͨË×Óû§ÔÚµÍȨÏÞÓû§ÃüÃû¿Õ¼äÖÐmoutÒ»¸öoverlayfsÎļþϵͳ¡£µ±È¥mountÒ»¸öoverlayfsÎļþϵͳʱ£¬Å²Ó÷¾¶ÈçÏÂͼËùʾ£º
»áŲÓõ½do_new_mount()º¯Êý£¬¸Ãº¯ÊýÊǽ¨ÉèÒ»¸öеÄmount£¬²¢½«Æä·ÅÈënamespaceÊ÷ÖУ¬ÊµÏÖ´úÂëÈçÏÂͼËùʾ£º
ÐÐ2792£¬»ñÈ¡Òª¹ÒÔصÄÎļþϵͳÀàÐÍ£¬ÕâÀïÊÇoverlay¡£È»ºó¾ÍÊǾÙÐÐcapabilitiyУÑ飬ÈçÏÂͼËùʾ£º
ÓÉÓÚfs_flags±»ÉèÖÃΪFS_USERNS_MOUNT£¬½øÈëns_capable()º¯Êý£¬×îºóͨ¹ýÄ¥Á·ºó£¬ÈçÏÂͼËùʾ£º
²¢ÇÒÉèÖÃcurrent->flagsΪPF_SUPERPRIV£¬¼´ÔÚÄ¿½ñÀú³ÌÉÏÉèÖó¬µÈȨÏÞ£¬²¢·µ»Øture¡£ÒÔÊÇͨ¹ý¹ÒÔØoverlayÎļþϵͳ£¬Ä¿½ñÀú³Ì¾ß±¸Á˳¬µÈȨÏÞ¡£
£¨2£©È¨ÏÞÌÓÒÝ
¸ÃÎó²îÊÇÔÚsetxattr()º¯ÊýÖб¬·¢µÄ£¬µ±¶ÔÎļþÀ©Õ¹ÊôÐÔµÄcapabilitiy¾ÙÐÐÉèÖÃʱ£¬È¨ÏÞУÑé²»³¹µ×¡£ÏÂÃæÊÇ"SSD Secure Disclosure"Åû¶µÄExpÖ´ÐÐÇéÐΣ¬Å²Ó÷¾¶ÈçÏÂͼËùʾ£º
ÕâÀïpathnameΪ¡°./ovlcap/merge/magic¡±£¬ÐÐ468£¬Å²ÓÃcap_convert_nscap()º¯Êý£¬½«ÒªÉèÖõÄcapת»»µ½nscapÖУ¬ÈçÏÂͼËùʾ£º
½øÈëcap_convert_nscap()º¯Êý£¬¾ÙÐÐÏà¹Ø¼ì²âºó£¬ÈôÊÇÊÇcapabilitiy°æ±¾2£¬ÔòÖ±½ÓŲÓÃns_capable()¾ÙÐÐÄ¥Á·£¬Æ¾Ö¤×¢ÊÍ¿ÉÖª£¬ÈôÊÇuserÓ㬵ÈȨÏÞ£¬Ö±½ÓдÈë²¢·µ»Ø¡£
ºÁÎÞÒÉÎÊ£¬ÕâÀïÒ»¶¨ÊÇÄ¥Á·Í¨¹ýµÄ¡£´òÓ¡Òªº¦Äڴ棬ÈçÏÂͼËùʾ£º
¼Ä´æÆ÷raxΪ0x1£¬ÌåÏÖ·µ»Øture¡£ÓÉÓÚÄ¿½ñ»á¼ûµÄinodeÊôÓÚoverlayÎļþϵͳµÄ¡£´Ócap_convert_nscap()º¯Êý׼ȷ·µ»Øºó£¬Ëæ¼´½øÈëvfs_setxattr()º¯Êý£¬ÕâÊǵÚÒ»´Î½øÈë¡£½ÓÏÂÀ´¾ÍÊÇ·Ö·¢µ½overlayÎļþϵͳ¶ÔÓ¦µÄovl_xattr_set()º¯ÊýÖУ¬Å²Ó÷¾¶ÈçÏÂͼËùʾ£º
¿´ovl_xattr_set()º¯ÊýµÄ²¿·ÖʵÏÖ´úÂ룬»ñÈ¡upperdentryºÍrealdentry£¬ÈçÏÂͼËùʾ£º
»ñÈ¡ºó£¬´òÓ¡upperdentryºÍrealdentryÄڴ棬ÈçÏÂͼËùʾ£º
ƾ֤overlayÎļþϵͳÌØÕ÷£¬ÕâÀïµÄupperdentryºÍrealdentryÓ¦¸ÃÊÇ¡°./ovlcap/upper¡±Ä¿Â¼ÏµÄmagicµÄĿ¼Ï´òÓ¡ÄÚ´æ¿ÉÖª£¬ÈçÏÂͼËùʾ£º
È·¶¨ÕæʵµÄdentryºó£¬µÚ¶þ´ÎŲÓÃvfs_setxattr()º¯Êý£¬ÈçÏÂͼËùʾ£º
´ËʱµÄdentryÊÇÊôÓÚext3ÎļþϵͳµÄ£¬´òÓ¡ÄÚ´æ¿ÉÖª£¬ÈçÏÂͼËùʾ£º
µ½´Ë¿ÉÖª£¬ÏÖʵÉÏÊǶÔext3Îļþϵͳϵġ°./ovlcap/upper/magic¡±¾ÙÐÐÉèÖÃcap¡£È¨ÏÞÌÓÒÝÀú³ÌÈçÏÂͼËùʾ£º
Îó²îʹÓÃÆÊÎö
"SSD Secure Disclosure"¹Ù·½ÒѾÅû¶ÁËÏà¹ØExp£¬ÏêϸÆÊÎöÈçÏ£º
ÕâÀï½ç˵ºóÃæ¹ÒÔØoverlayÎļþϵͳµÄÎļþ¼ÐÃû³Æ:
²¢×Ô½ç˵xmkdirº¯Êý½¨ÉèÕâЩÎļþ¼Ð:
È»ºó»ñÈ¡Ä¿½ñÓû§µÄuidºÍgid£º
½¨ÉèеÄuser namespace£¬ÓÉÓÚoverlayfs mountÐèÒªCAP_SYS_MOUNTÄÜÁ¦£¬Òò´ËÐèҪн¨Ò»¸öNEWUSERµÄnamespace£¬ÕâÑù¾Í¾ßÓÐCAP_SYS_MOUNT£¬
CLONE_NEWNSºÍCLONE_NEWUSER½ç˵£º
ÓÃÄ¿½ñÓû§µÄuidºÍgidµÈ¸Äд/proc/selfϵĶÔÓ¦Îļþ£¬²¢ÇÒÓøÃȨÏÞϵÄnamespace¹ÒÔØoverlayfs£¬Ç°Ãæ¼ò½é˵ÁË£¬ÓÉÓÚubuntuµÄ²¹¶¡±£´æ£¬¸Ã²Ù×÷ÊÇÕýµ±µÄ¡£
¶ÔӦĿ¼Ï¿ÉÒÔ¿´µ½ÎÒÃÇÐÞ¸ÄÁ˵ÄÎļþ£¬Í¨¹ý/proc/self/exe¿ÉÒÔÕÒµ½Ä¿½ñÀú³ÌµÄ¶þ½øÖÆʵÌ壨Îļþ£©£º
¼ÌÐø»Øµ½expÖУ¬ÏÂÃæ½á¹¹ÁËÒ»¸öcap£¬¸Äcap½ç˵µÄpermittedΪ0xffffffff£¬²¢ÇÒ¿ªÆôEffective£¬È»ºó½«/proc/selfϵÄÎļþ¿½±´µ½mergeÎļþ¼ÐÏ£¬Æ¾Ö¤overlayÎļþϵͳÌØÕ÷£¬Õâ¸ö¿½±´Àú³ÌÏÖʵÊǽ¨Éè./ovlcap/upper/magicÎļþ£¬×îºóŲÓÃsetxattr()º¯Êý£¬½«capÉèÖõ½./ovlcap/merge/magicÉÏÃæ¡£
ƾ֤ǰÎÄÎó²îÔÀíÏÈÈÝ£¬È¨ÏÞÌÓÒݺ󣬴ËʱÊôÓÚext3ÎļþϵͳµÄ./ovlcap/upper/magicÎļþµÄcapabilitiyΪall+ep£¬±ã¿ÉÒÔʹÓÃcapabilitiy¾ÙÐÐȨÏÞÌáÉý£¬½Ó×ÅÆô¶¯./ovlcap/upper/magicÀú³Ì£¬¸ÃÀú³ÌµÄcapabilitiyÒѾ߱¸all+ep£¬È»ºó¾ÙÐÐsetuid(0)ºÍsetgid(0)ÌáȨ²Ù×÷£¬ÕâÊDZ»ÔÊÐíµÄ¡£
²¹¶¡¸ú×Ù
Îó²î³ÉÒòÔÚÉÏÃæÒѾÏÈÈÝÁË£¬ÕâÀïµÄ²¹¶¡Ò²ºÜ³¹µ×£¬½«cap_convert_nscap·ÅÈëÁËvfs_setxattrÖУ¬¼´Ã¿´Î½øÈëvfs_setxattr()º¯Êýʱ£¬¶¼ÏȾÙÐÐȨÏÞУÑ飬ÅжÏcapabilitiyºÍÃüÃû¿Õ¼äµÄȨÏÞÊÇ·ñÆ¥Åä¡£
²Î¿¼Á´½Ó£º
[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Çå¾²Ñо¿¡¢¹¤¿ØϵͳÇå¾²Ñо¿¡¢ÔÆÇå¾²Ñо¿¡£Ñо¿Ð§¹ûÓ¦ÓÃÓÚ²úÆ·½¹µãÊÖÒÕÑо¿¡¢¹ú¼ÒÖصã¿Æ¼¼ÏîÄ¿¹¥¹Ø¡¢×¨ÒµÇå¾²·þÎñµÈ¡£