ãžã«ã³ã³ïŒ ããã¯äœã§ãã
2016幎8æãGoogleããã®å
¬åŒã®çºè¡šãªãã§ãæ°ãããªãã¬ãŒãã£ã³ã°ã·ã¹ãã ã®ãœãŒã¹ãçºèŠãããŸãã ãã¯ã·ã¢ã ãã®OSã¯ããžã«ã³ã³ãšåŒã°ãããã€ã¯ãã«ãŒãã«ã«åºã¥ããŠããŸãããžã«ã³ã³ã¯ã LKïŒãªãã«ã«ãŒãã«ïŒã«åºã¥ããŠããŸãã
ãã¯ã·ã¢ã¯Linuxã§ã¯ãããŸãã
ãã®èšäºã§ã¯äœãè°è«ãããŸããïŒ
Zirconã®vDSOã¯ã ã·ã¹ãã ã³ãŒã«ïŒsyscallsïŒã«ã¢ã¯ã»ã¹ããå¯äžã®æ段ã§ãã
ããããã³ãŒãããããã»ããµåœä»€SYSENTER / SYSCALLãçŽæ¥åŒã³åºãããšã¯æ¬åœã«äžå¯èœã§ããïŒ ãããããããã®ããã»ããµåœä»€ã¯ã·ã¹ãã ABIã®äžéšã§ã¯ãããŸããã ãŠãŒã¶ãŒã³ãŒãã¯ããã®ãããªæ瀺ã«çŽæ¥åŸãããšã¯çŠæ¢ãããŠããŸãã
ãã®ãããªã¢ãŒããã¯ãã£ã®ã¹ãããã«é¢ãã詳现ãç¥ãããå Žåã¯ãCatã«æåŸ
ããŸãã
Zircon vDSOïŒä»®æ³åçå
±æãªããžã§ã¯ãïŒ
é åèªvDSOã¯ãä»®æ³åçå
±æãªããžã§ã¯ãã®ç¥ã§ãã
- åçå
±æãªããžã§ã¯ãã¯ãELF圢åŒïŒ.soãã¡ã€ã«ïŒã®å
±æã©ã€ãã©ãªãæãããã«äœ¿çšãããçšèªã§ãã
- ãã®ãªããžã§ã¯ãã¯ããã¡ã€ã«ã·ã¹ãã äžã®æ¢åã®åå¥ã®ãã¡ã€ã«ããããŒããããªããããä»®æ³ã§ãã vDSOã€ã¡ãŒãžã¯ãã«ãŒãã«ã«ãã£ãŠçŽæ¥æäŸãããŸãã
ã«ãŒãã«ã®ãµããŒã
ãŠãŒã¶ãŒã¢ãŒãã¢ããªã±ãŒã·ã§ã³ã®å¯äžã®å¶åŸ¡ãããABIãšããŠã®vDSOã®ãµããŒãã¯ã2ã€ã®æ¹æ³ã§å®è£
ãããŸãã
ä»®æ³ã¡ã¢ãªãªããžã§ã¯ãã®æåœ±ïŒ VMOãä»®æ³ã¡ã¢ãªãªããžã§ã¯ã ïŒã
zx_vmar_mapãvDSOã® VMOãåŠçããïŒããã³åŒæ°ã§ZX_VM_PERM_EXECUTE
èŠæ±ãããïŒå Žåãã«ãŒãã«ã¯ãªãã»ãããšãµã€ãºãå®è¡äžã®vDSOã»ã°ã¡ã³ããšå³å¯ã«äžèŽããããšãèŠæ±ããŸãã ããã«ãããããã»ã¹ã¡ã¢ãªãžã®vDSOæ圱ã1ã€ã ãä¿èšŒãããŸãã ããã»ã¹ãžã®vDSOã®æåã®æ£åžžãªæ圱åŸãåé€ã§ããªããªããŸãã ãŸããvDSOãããã»ã¹ã¡ã¢ãªã«åæ圱ããããšãããšã誀ã£ããªãã»ããããµã€ãºãæã€vDSOãŸãã¯ãããžã§ã¯ãã®æ圱VMOãåé€ããããšãããšããšã©ãŒZX_ERR_ACCESS_DENIED
倱æããŸãã
vDSOã³ãŒãã®ãªãã»ãããšãµã€ãºã¯ãã³ã³ãã€ã«æ®µéã§ELFãã¡ã€ã«ããæœåºãããã«ãŒãã«ã³ãŒãã§äžèšã®ãã§ãã¯ãå®è¡ããããã«äœ¿çšãããŸãã vDSOãããžã§ã¯ã·ã§ã³ãæåã«æåããåŸãOSã«ãŒãã«ã¯ãã§ãã¯ãé«éåããããã«ã¿ãŒã²ããããã»ã¹ã®ã¢ãã¬ã¹ãèšæ¶ããŸãã
ã·ã¹ãã ã³ãŒã«é¢æ°ã®ãªã¿ãŒã³ã¢ãã¬ã¹ã確èªããŠãã ããã
ãŠãŒã¶ãŒã¢ãŒãã³ãŒããã«ãŒãã«ãåŒã³åºããšãäœã¬ãã«ã®ã·ã¹ãã ã³ãŒã«çªå·ãã¬ãžã¹ã¿ã§éä¿¡ãããŸãã äœã¬ãã«ã·ã¹ãã ã³ãŒã«ã¯ãvDSOãšZirconã³ã¢éã®å
éšïŒãã©ã€ããŒãïŒã€ã³ã¿ãŒãã§ã€ã¹ã§ãã äžéšïŒã»ãšãã©ïŒã¯ããããªãã¯ABIã®ã·ã¹ãã ã³ãŒã«ã«çŽæ¥å¯Ÿå¿ããŸãããããã§ãªããã®ããããŸãã
vDSOã³ãŒãã®äœã¬ãã«ã·ã¹ãã ã³ãŒã«ããšã«ããã®ã³ãŒã«ãè¡ãã³ãŒãã«åºå®ãããäžé£ã®ãªãã»ããããããŸãã vDSOã®ãœãŒã¹ã³ãŒãã¯ããã®ãããªåå Žæãèå¥ããå
éšæåãå®çŸ©ããŸãã ã³ã³ãã€ã«æã«ããããã®å Žæã¯vDSOã·ã³ãã«ããŒãã«ããååŸãããåäœã¬ãã«ã·ã¹ãã ã³ãŒã«ã®ã³ãŒãã¢ãã¬ã¹ã®æå¹æ§ã®äºæž¬ã決å®ããã«ãŒãã«ã³ãŒãã®çæã«äœ¿çšãããŸãã ãããã®è¿°èªã䜿çšãããšãvDSOã³ãŒãã»ã°ã¡ã³ãã®å
é ããã®ãªãã»ãããäžãããããšãåŒã³åºãå
ã®ã³ãŒãã®æå¹æ§ããã°ãã確èªã§ããŸãã
åŒã³åºãå
ã®ã³ãŒããã·ã¹ãã åŒã³åºããè¡ãããšãèš±å¯ãããŠããªãããšãè¿°èªã«ãã£ãŠæ±ºå®ãããå ŽåãåŒã³åºãå
ã®ã³ãŒããååšããªããŸãã¯ç¹æš©ã®ããåœä»€ãå®è¡ããããšãããã®ããã«ãåæäŸå€ãã¹ããŒãããŸãã
æ°ããããã»ã¹ãäœæãããšãã®vDSO
ã·ã¹ãã ã³ãŒã«zx_process_start㯠ãæ°ããäœæãããããã»ã¹ã®æåã®ã¹ã¬ããã®å®è¡ãéå§ããããã«äœ¿çšãããŸãã ãã®ã·ã¹ãã ã³ãŒã«ã®æåŸã®ãã©ã¡ãŒã¿ãŒïŒããã¥ã¡ã³ãã®arg2ãåç
§ïŒã¯ãäœæãããããã»ã¹ã®æåã®ã¹ã¬ããã®åŒæ°ãæž¡ããŸãã åãå
¥ããããåæã«åŸã£ãŠãããã°ã©ã ããŒããŒã¯vDSOãæ°ããããã»ã¹ã®ã¢ãã¬ã¹ç©ºéã«ïŒã·ã¹ãã ãéžæããã©ã³ãã ãªå Žæã«ïŒãããã³ã°ããåŒæ°arg2ãæã€ãããã³ã°ã®ããŒã¹ã¢ãã¬ã¹ãäœæãããããã»ã¹ã®æåã®ã¹ã¬ããã«è»¢éããŸãã ãã®ã¢ãã¬ã¹ã¯ELFãã¡ã€ã«ã®ããããŒã¢ãã¬ã¹ã§ããããã«ãããã·ã¹ãã ã³ãŒã«ãè¡ãããã«å¿
èŠãªååä»ãé¢æ°ãèŠã€ããããšãã§ããŸãã
ã¡ã¢ãªã«ãŒãïŒã¬ã€ã¢ãŠãïŒvDSO
vDSOã¯äžè¬çãªEFLå
±æã©ã€ãã©ãªã§ãããä»ã®ã©ã€ãã©ãªãšåæ§ã«èããããšãã§ããŸãã ãã ããvDSOã§ã¯ãæå³çã«ELF圢åŒå
šäœã®å°ããªãµãã»ãããéžæãããŸãã ããã«ã¯ããã€ãã®å©ç¹ããããŸãã
- ãã®ãããªELFã®ããã»ã¹ãžã®ãããã³ã°ã¯åçŽã§ãããELFããã°ã©ã ãå®å
šã«ãµããŒãããããã«å¿
èŠãªè€éãªå¢çã±ãŒã¹ã¯å«ãŸããŠããŸããã
- vDSOã®äœ¿çšã«ã¯ãå®å
šã«æ©èœããåçELFãã€ã³ãã£ã³ã°ã¯å¿
èŠãããŸããã ç¹ã«ãvDSOã«ã¯åçãªåé
眮ã¯ãããŸããã å¿
èŠãªã¢ã¯ã·ã§ã³ã¯ãELFãã¡ã€ã«ã®PT_LOADã»ã°ã¡ã³ããæ圱ããããšã ãã§ãã
- vDSOã³ãŒãã¯ã¹ããŒãã¬ã¹ã§ãªãšã³ãã©ã³ãã§ãã ããã»ããµã¬ãžã¹ã¿ãšã¹ã¿ãã¯ã§ã®ã¿åäœããŸãã ããã«ãããæå°éã®å¶éã§ããŸããŸãªã³ã³ããã¹ãã§ã®äœ¿çšã«é©ãããã®ãšãªããå¿
é ã®ABIãªãã¬ãŒãã£ã³ã°ã·ã¹ãã ã«æºæ ããŠããŸãã ãŸããä¿¡é Œæ§ãšã»ãã¥ãªãã£ã®ã³ãŒãåæãšæ€èšŒãç°¡çŽ åããŸãã
ãã¹ãŠã®vDSOã¡ã¢ãªã¯2ã€ã®é£ç¶ããã»ã°ã¡ã³ãã§è¡šãããåã»ã°ã¡ã³ãã«ã¯æŽåãããããŒãžå
šäœãå«ãŸããŸãã
- æåã®ã»ã°ã¡ã³ãã¯èªã¿åãå°çšã§ãELFããããŒãšå®æ°ããŒã¿ãââå«ãŸããŸãã
- 2çªç®ã®ã»ã°ã¡ã³ãã¯å®è¡å¯èœã§ãvDSOã³ãŒããå«ãŸããŠããŸãã
vDSOã€ã¡ãŒãžå
šäœã¯ãããã2ã€ã®ã»ã°ã¡ã³ãã®ããŒãžã®ã¿ã§æ§æãããŠããŸãã vDSOã¡ã¢ãªã衚瀺ããã«ã¯ãELFããããŒããæœåºããã2ã€ã®å€ïŒåã»ã°ã¡ã³ãã®ããŒãžæ°ïŒã®ã¿ãå¿
èŠã§ãã
OSããŒãæå®æ°ããŒã¿
äžéšã®ã·ã¹ãã ã³ãŒã«ã¯ãåã«å®æ°ã®å€ãè¿ããŸãïŒå€ã¯å®è¡æã«èŠæ±ããå¿
èŠãããããŠãŒã¶ãŒã¢ãŒãã³ãŒãã«ã³ã³ãã€ã«ããããšã¯ã§ããŸããïŒã ãããã®å€ã¯ãã³ã³ãã€ã«æã«ã«ãŒãã«ã§åºå®ãããããããŒãæã«ã«ãŒãã«ã«ãã£ãŠæ±ºå®ãããŸãïŒããŒããã©ã¡ãŒã¿ãŒãšããŒããŠã§ã¢ãã©ã¡ãŒã¿ãŒïŒã äŸïŒ zx_system_get_versionïŒïŒ ã zx_system_get_num_cpusïŒïŒããã³zx_ticks_per_secondïŒïŒ ã ããšãã°ãæåŸã®é¢æ°ã®æ»ãå€ã¯ã ã«ãŒãã«ã³ãã³ãã©ã€ã³ãã©ã¡ãŒã¿ãŒã®åœ±é¿ãåããŸãã
CPUã®æ°ã¯äžå®ã§ããïŒèå³æ·±ãããšã«ã zx_system_get_num_cpusïŒïŒé¢æ°ã®èª¬æã«ã¯ãOSãããã»ããµãŒæ°ã®ããã ã¹ã¯ããããµããŒãããŠããªãããšãæ瀺çã«èšèŒãããŠããŸãã
ãã®æ°å€ã¯ãã·ã¹ãã ã®å®è¡äžã«å€æŽããããšã¯ã§ããŸãããèµ·åæã®ã¿ã§ãã
ããã¯ãå°ãªããšããOSããµãŒããŒãšããŠäœçœ®ä»ããããŠããªãããšãéæ¥çã«ç€ºããŠããŸãã
ãããã®å€ã¯äžå®ã§ãããããOSã«ãŒãã«ãžã®å®éã®ã·ã¹ãã ã³ãŒã«ã«å¯ŸããŠæ¯æãããšã¯æå³ããããŸããã 代ããã«ãvDSOå®æ°ã»ã°ã¡ã³ãããèªã¿åãããããŒã¿ãè¿ãåçŽãªC ++é¢æ°ãå®è£
ãããŠããŸãã ã³ã³ãã€ã«äžã«ãã£ããã£ãããå€ïŒã·ã¹ãã ã®ããŒãžã§ã³æååãªã©ïŒã¯ãåã«vDSOã«ã³ã³ãã€ã«ãããŸãã
ããŒãæã«æ±ºå®ãããå€ã®å Žåãã«ãŒãã«ã¯vDSOã®å
容ãå€æŽããå¿
èŠããããŸãã ããã¯ãã«ãŒãã«ãæåã®ãŠãŒã¶ãŒããã»ã¹ãéå§ããåã«VMO vDSOã圢æããïŒããã³VMOèšè¿°åãæž¡ãïŒæ©æå®è¡å¯èœã³ãŒãã䜿çšããŠè¡ãããŸãã ã³ã³ãã€ã«äžã«ãvDSOã€ã¡ãŒãžïŒ vdso_constants ïŒããã®ãªãã»ãããELFãã¡ã€ã«ããæœåºãããã«ãŒãã«ã«åã蟌ãŸããŸãã ãŸããããŒãäžã«ãã«ãŒãã«ã¯èªèº«ã®ã¢ãã¬ã¹ç©ºéã§vdso_constantsãã«ããŒããããŒãžãäžæçã«è¡šç€ºããŠãæ£ããå€ã§æ§é ãäºååæåããŸãïŒçŸåšã®ã·ã¹ãã èµ·åæïŒã
ãªããã®ãã¹ãŠã®é ç ïŒ
æãéèŠãªçç±ã®1ã€ã¯ã»ãã¥ãªãã£ã§ãã ã€ãŸããæ»æè
ãä»»æã®ïŒã·ã§ã«ïŒã³ãŒããå®è¡ã§ããå ŽåãvDSOé¢æ°ã䜿çšããŠã·ã¹ãã é¢æ°ãåŒã³åºãå¿
èŠããããŸãã æåã®éå£ã¯ãäœæãããåããã»ã¹ã®åè¿°ã®vDSOããŠã³ããŒãã¢ãã¬ã¹ã®ã©ã³ãã åã§ãã ãŸããOSã«ãŒãã«ã¯vDSOã®VMOïŒä»®æ³ã¡ã¢ãªãªããžã§ã¯ãïŒãæ
åœãããããå®å
šã«ç°ãªãvDSOãç¹å®ã®ããã»ã¹ã«ãããã³ã°ããããšãéžæã§ããããã«ããå±éºãªïŒç¹å®ã®ããã»ã¹ã«ã¯äžèŠãªïŒã·ã¹ãã ã³ãŒã«ãçŠæ¢ã§ããŸãã ããšãã°ã ãã©ã€ããŒãåããã»ã¹ãçæããªãããã«ããããMMIOãšãªã¢ã®æ圱ãåŠçãããã§ããŸãã ããã¯ãæ»æ察象ãæžããããã®åªããããŒã«ã§ãã
泚ïŒçŸåšãããã€ãã®vDSOã®ãµããŒããç©æ¥µçã«éçºãããŠããŸãã æŠå¿µå®èšŒã®å®è£
ãšç°¡åãªãã¹ãã¯æ¢ã«ååšããŸãããå®è£
ã®ä¿¡é Œæ§ãåäžããã䜿çšå¯èœãªãªãã·ã§ã³ã決å®ããã«ã¯ãããã«äœæ¥ãå¿
èŠã§ãã çŸåšã®ã³ã³ã»ããã§ã¯ãå®å
šãªvDSOã·ã¹ãã ã³ãŒã«ã€ã³ã¿ãŒãã§ã€ã¹ã®ãµãã»ããã®ã¿ããšã¯ã¹ããŒãããvDSOã€ã¡ãŒãžãªãã·ã§ã³ãæäŸããŠããŸãã
ä»ã®ãªãã¬ãŒãã£ã³ã°ã·ã¹ãã ã«ã€ããŠã¯ã©ãã§ããïŒåæ§ã®ææ³ã¯ãä»ã®ãªãã¬ãŒãã£ã³ã°ã·ã¹ãã ã§ãæ¢ã«äœ¿çšãããŠããããšã«æ³šæããŠãã ããã ããšãã°ã Windowsã«ã¯ProcessSystemCallDisablePolicyããããŸã ã
NT32ããã³GDIã䜿çšããæ©èœãå¶éããWin32kã·ã¹ãã ã³ãŒã«ç¡å¹åã®å¶é