ã¯ããã«
ããã«ã¡ã¯Necoãã¼ã ã®satã§ããæ¬æ¥ã¯Necoãã¼ã ã®è©±ã§ã¯ãªããç§ãå é±è¬å¸«ã¨ãã¦åå ãããã»ãã¥ãªãã£ãã£ã³ãå ¨å½å¤§ä¼ 2018ãã¨ããã¤ãã³ãã®åå å ±åããããã¾ãããã®ã¤ãã³ãã®ä¸ã§ãã¨ãã«ç§ãåãæã£ãéä¸éçºã³ã¼ã¹ãLinuxéçºè ãç®æãã!ããã¼ãã«ã¤ãã¦è¿°ã¹ã¾ãã
ã»ãã¥ãªãã£ãã£ã³ãå ¨å½å¤§ä¼ã¨ã¯ããçã®ææã«å ¨å½ã®å¦çãä¸ãæã«éã¾ã£ã¦ã5æ¥éãã®éã®ããã¨ä¸ç·ã«ã»ãã¥ãªãã£æè¡ã«ã¤ãã¦å¦ã¶ã¤ãã³ãã§ããã¤ãã³ããã®ãã®ã«ã¤ãã¦ã®è©³ç´°ã¯ä»¥ä¸ãªã³ã¯å ãã覧ãã ããã
ãLinuxéçºè ãç®æãã!ãã³ã¼ã¹ã®æ¦è¦
ãLinuxéçºè ãç®æãã!ãã³ã¼ã¹ã¯åè¬è ãå®éã«Linuxã«ã¼ãã«ã®é¨åãéçºã追å ãããã¨ã«ãã£ã¦Linuxã«ã¼ãã«ã®éçºã«ã¤ãã¦ã®ç解ãæ·±ãã¦ãããããã®ãã®ã§ã*1ãä»åã¯2人ã®å¦çããã®ãã¼ãã«åãçµã¿ã¾ããã
ä¸äººã®æ¹ã¯Linuxã®ã«ã¼ãã«ã¢ã¸ã¥ã¼ã«(å¾è¿°)ãç¬èªéçºãã¾ãããããä¸äººã®æ¹ã¯ç¬èªã®slabã¢ãã±ã¼ã¿(å¾è¿°)ãå®è£ ãã¾ãããã§ã¯ããäºæ¹ãå ·ä½çã«ã©ã®ãããªãã¨ããããã«ã¤ãã¦è¿°ã¹ã¦ããããã¨æãã¾ãã
ç¬èªã«ã¼ãã«ã¢ã¸ã¥ã¼ã«ã®éçº
ã«ã¼ãã«ã¢ã¸ã¥ã¼ã«ã¨ã¯
ã«ã¼ãã«ã¢ã¸ã¥ã¼ã«ã¨ã¯ã·ã¹ãã èµ·åæãããã³ãã®å¾ã®åä½ä¸ã«ã«ã¼ãã«ã«æ©è½ã追å ããããã®é¨åã§ããWebãã©ã¦ã¶ã§ãããã©ã°ã¤ã³ãæãæµ®ãã¹ã¦ããããã°ãããã¨æãã¾ããã«ã¼ãã«ã®æ©è½ã®ãã¡ã®å¤ãã®é¨åã¯æåããã«ã¼ãã«ã«çµã¿è¾¼ãã§ãããã¨ãã§ãã¾ãããã¢ã¸ã¥ã¼ã«ã¨ãã¦ç¬ç«ãããã¡ã¤ã«ã«ãã¦ããã¦å¿ è¦ã«ãªã£ãæã«ã«ã¼ãã«ã«çµã¿è¾¼ããã¨ãã§ãã¾ãã
ãã¨ãã°ã¿ãªããã®PCã«ç¹ãã£ã¦ããå種ããã¤ã¹ãæä½ããããã¤ã¹ãã©ã¤ããªã©ãããã§ããã¢ã¸ã¥ã¼ã«ã¯ã«ã¼ãã«æ¬ä½ã¨åæã«ãã«ãã§ãã¾ãããå¾ããå¥éåå¥ã«ãã«ããã§ãã¾ããæ¬ã³ã¼ã¹ã§ã¯å¾è ã®ã¢ããã¼ããã¨ãã¾ããã
éçºã®æµã
ã¾ãã¯ã«ã¼ãã«ã¢ã¸ã¥ã¼ã«ã®ãã¼ãæã«ã«ã¼ãã«ã®ãã°*2ã«"hello world"ã¨è¡¨ç¤ºããã ãã®æ°è¡ã®ããã°ã©ã ãä½ãã¨ããããå§ãã¾ãããåç´ãªããã°ã©ã ãªã®ã§ãããèªåèªèº«ã®ã³ã¼ããã«ã¼ãã«ã®ä¸é¨ã¨ãã¦åãã¨ããã®ã¯ãªããªãä½é¨ã§ãããã®ã§ã¯ããã¾ããã
ç¶ãã¦ã«ã¼ãã«ã¢ã¸ã¥ã¼ã«ã«åé¡ããã£ããã©ããªããã¨ããã®ã確èªãã¦ããã ãã¾ãããå ·ä½çã«ã¯é常ã®ããã»ã¹ãããã³ã«ã¼ãã«ã¢ã¸ã¥ã¼ã«ã®ä¸¡æ¹ããNULLãã¤ã³ã¿ã«ã¢ã¯ã»ã¹ããããã°ã©ã ãæ¸ãã¾ãããããããã¨åè ã¯NULLãã¤ã³ã¿ã«ã¢ã¯ã»ã¹ããããã°ã©ã ãç°å¸¸çµäºããã ãã§çµäºãã¾ããã
ããã«å¯¾ãã¦å¾è ã¯ã·ã¹ãã å ¨ä½ãåä½ããªããªã£ã¦ãã¾ãã¾ãããWindowsã§ãããã«ã¼ã¹ã¯ãªã¼ã³ãåºãç¶æ ã«ç¸å½ãã¾ãã
å®ã¯ãããå®éã®ã«ã¼ãã«ã§ãã®ãããªé害ãããã°ç«æ´¾ãªèå¼±æ§ã«ãªãã¾ã*3ããã«ãã¦ã¼ã¶ã·ã¹ãã ã§æªæã®ããä¸è¬ã¦ã¼ã¶ã®ããã°ã©ã ã«ãã£ã¦ã·ã¹ãã å ¨ä½ããã¦ã³ãã¦ãã¾ããããªå ´åãèããã°ããã£ã¦ããã ãããã¨æãã¾ããããæ¸ãã ãã§ãªãã¨ãªãç解ã¯ã§ããã®ã§ããããã¯ãèãã ããªã®ã¨å®éã«ã·ã¹ãã å ¨ä½ãè½ã¨ãã¦ã¿ãã®ã¨ã§ã¯ç解ã®åº¦åããéãã¾ãã
ç¶ãã¦å½¼ã¯æå®æéå¾ã«æå®ã®å¦çãå¼ã³åºãã«ã¼ãã«ã¿ã¤ãã¼ã¨ãããã®ã«ã¤ãã¦å¦ã³ã¾ãããæåã¯ã«ã¼ãã«ã¢ã¸ã¥ã¼ã«ããã¼ããã¦ãã10ç§å¾ã«ã¡ãã»ã¼ã¸ãä¸ååºåãã¦çµãããã¨ãããã®ããå§ã¾ã£ã¦ãã¿ã¤ãã¼ãäºã¤åæã«èµ·åãããã®ãäºã¤ã®ã¿ã¤ãã¼ã«å¥ã®ã¡ãã»ã¼ã¸ã表示ããããã®ããªã©ãªã©ãå¤ç¨®å¤æ§ãªã«ã¼ãã«ã¢ã¸ã¥ã¼ã«ãä½ãã¾ããã
æ®å¿µãªããæ¬ã¤ãã³ãã®çãæéã§ã¯ããã§çµãã£ã¦ãã¾ãã¾ããããå½¼ãå ·ä½çã«ã©ããããã®ãéçºããã®ããããã³ããã®å ã«ã©ãããã¡ãã¥ã¼ãç¨æããã¦ããã®ãã«ã¤ãã¦ã¯ä¸è¨ã®ä¸é£ã®ä¸ã®ææ¸ã¨Cè¨èªã½ã¼ã¹ãã¡ã¤ã«ãããããã ãã(ç¬èªéçºãã¼ã«ã®ä½¿ãæ¹ã«ã¤ãã¦è¿°ã¹ã¦ããé¨åã¯èªã¾ãªãã¦ããã§ã)ã
è¬å¸«ã®ç®ããè¦ã¦æé·ããã¨ãã
å½¼ã¯ä½ã¬ã¤ã¤ã®ããã°ã©ã ã«æ £ãã¦ããªããã¨ããæåã¯Cè¨èªã®ç解ããã¼ã¤ããªãã£ãã®ã§ãããæå¾ã«ã¯ç«æ´¾ã«ã«ã¼ãã«ã¢ã¸ã¥ã¼ã«ãä½ããã¾ã§ã«æé·ãã¾ãããåå¿è ã«ã¨ã£ã¦ã®æé£é¢ã§ãããã¤ã³ã¿ã«ã¤ãã¦ãããã°ã©ã ã®ã¡ã¢ãªããããä½åº¦ãå³ç¤ºããªããå¿ æ»ã«å¦ãã çµæãããç¨åº¦ç解ã§ããã¾ã§ã«ããã¤ãã¾ããããã¤ã³ã¿ã¯æ¬æ¥ä¸æä¸å¤ã§ç解ã§ãããã®ã§ã¯ãªãã®ã§ãããã¯ããããã¨ã§ãã
è£è©±: ã«ã¼ãã«å ã¤ã³ã¿ã¼ãã§ã¼ã¹ã®å¤æ´
ã«ã¼ãã«ã¿ã¤ãã¼ã使ã£ãã«ã¼ãã«ã¢ã¸ã¥ã¼ã«ãä½ã£ã¦ããæã«æãã¬åé¡ã«ééãã¾ãããããã¯ç§ãæä¾ãããµã³ãã«ã½ã¼ã¹ãæ°å¹´åã«æ¸ããå¤ããã®ã ã£ããããä»åéçºã«ä½¿ã£ãã«ã¼ãã«v4.18ã§ã¯ãã«ãã§ããªãã£ããã¨ã§ããå ¨ç¶æå³ãã¦ããªãã£ããã¨ãªããããããã¼ã¸ã§ã³ã®ã«ã¼ãã«ã«å¯¾ãã¦ä½ã£ãã«ã¼ãã«ã¢ã¸ã¥ã¼ã«ãå°æ¥ãä¿®æ£ãªãã«ä½¿ããä¿è¨¼ã¯Linuxã«ã¼ãã«ã«ããã¦ã¯ã©ãã«ããªããã¨ãå¦ãã§ããã ãã¾ããããã®ä»¶ã«ã¤ãã¦ã®è©³ç´°ã¯ä¸è¨ã®è¨äºãããããã ããã
ç¬èªslabã¢ãã±ã¼ã¿ã®å®è£
slabã¢ãã±ã¼ã¿ã¨ã¯
ã«ã¼ãã«ã®ã¡ã¢ãªç®¡çãµãã·ã¹ãã ã¯ãã¼ãã¦ã§ã¢ã¨ã®éã§ã¡ã¢ãªããã¼ã¸ã¨ããåä½(é常4KB)ã§ããã¨ããã¾ããã¡ã¢ãªç®¡çãµãã·ã¹ãã ã¯ã«ã¼ãã«ã®ä»ã®ã³ã³ãã¼ãã³ããããã³ããã»ã¹ã«å¯¾ãã¦ã¯ãã¼ã¸ãå²ãå½ã¦ã¾ãããã®å²ãå½ã¦ããã°ã©ã ã®ãã¨ãbuddyã¢ãã±ã¼ã¿ã¨å¼ã³ã¾ãã
ãããããã¤ãåä½ã®ã¡ã¢ãªãªãã¸ã§ã¯ãã欲ããã«ã¼ãã«ãµãã·ã¹ãã ã«ã¨ã£ã¦ããã¯ä½¿ãã«ããã§ãããã¨ãã°ã¡ã¢ãªã8ãã¤ãã ãã»ããã®ã«ãã¼ã¸åä½ã§ããè¦æ±ã§ããªããã°ã8ãã¤ãã®ããã«1ãã¼ã¸ãæ¶è²»ããã¨ãã壮絶ãªç¡é§ãçºçããããããããã¯èªåèªèº«ã§ãã¼ã¸ãå°åããã¦ç®¡çããªããã°ãªãã¾ããã
ããã§ããã¼ã¸ãå°åããã¦ç®¡çããã¦ãããã®ãslabã¢ãã±ã¼ã¿ã¨ããããã¿ã§ããslabã¢ãã±ã¼ã¿ã¯buddyã¢ãã±ã¼ã¿ãããã¼ã¸ãç²å¾ããä¸ã§ããã¼ã¸ãã«ã¼ãã«å ãµãã·ã¹ãã ã«ãã¤ãåä½ã«å°åããã¦æ¸¡ãã¾ããå³ä¸ã«kmalloc()ã¨æ¸ãã¦ããã®ã¯ãã¦ã¼ã¶ç©ºéã«ãããmalloc()ã«ç¸å½ãããã®ã§ããããã¤ãåä½ã®ã¡ã¢ãªå²ãå½ã¦ãããé¢æ°ã§ãã
linuxã«ã¯slabã®å®è£ ãè¤æ°ååå¨ãã¾ããå ·ä½çã«ã¯SLOB, SLAB, SLUBã¨ãã3ã¤ã§ããä¼¼ããããªååããããããã£ã¦ãããããã§ãããæ°ã«ããªãã§ãã ããã
éçºã®æµã
å½¼ã¯èªåã®slabã¢ãã±ã¼ã¿ã«SLOBA(ãã°)ã¨ãããã£ãããååãä»ãã¾ãããååããä»ããã°çµãã£ããããªãã®ã§ãâ¦ã¨ããã®ã¯åè«ã¨ãã¦ãæçµæ¥ã¾ã§ã®ç®çã¯ãç¹å®ç¨éã§ã¯SLOB(æãåç´ãªå®è£ ãã¡ã¢ãªãå°ãªããããªç°å¢ã§ä½¿ããã)ã¨SLAB(æ±ç¨ãã¨ã³ã¿ã¼ãã©ã¤ãºãµã¼ãåãã«ãé·ãã«ããã£ã¦ä½¿ããã¦ãã)ã«åã¤ãã¨ããæ確ãªãã®ã§ãã*4ã
ãã«ã¹ã¯ã©ããã§slabã¢ãã±ã¼ã¿ãä½ãã®ã¯ãªããªã骨ãæããã®ã§ãæåã¯SLOBããã¨ã«ãã¦ä½ãå§ãã¦ã次第ã«ç¬èªã®ã³ã¼ããå¢ããã¦ããã¨ããã¢ããã¼ããã¨ãã¾ããããã³ããã¼ã¯ãã¹ãã¨ãã¦æ¡ç¨ããã®ã¯kernelã½ã¼ã¹ã«å¯¾ããdu -s
ã³ãã³ãçºè¡ã®æè¦æéã§ãããã£ã¬ã¯ããªã¨ã³ããªãã¨ã«dentryã¨å¼ã°ããã«ã¼ãã«å
ã®ãã¼ã¿ãslabã¢ãã±ã¼ã¿ããå²ãå½ã¦ãããã®ã§ãslabã¸ã®å¤§éã¢ã¯ã»ã¹ã®æè¦æéãè¨æ¸¬ã§ããã¨ããããã§ã*5ã
éçºã®åæ段éã§ãSLOBã®ã¡ã¢ãªç²å¾å¦çã¯SLOBãæã£ã¦ãããã¼ã¸ã®éã«æ¯ä¾ãã¦å¤ããªããã¨ããäºå®ã«æ°ã¥ããå½¼ã¯ããã£ãããã¼ã¿æ§é ã工夫ãã¦ãå®æ°æéã§ã¡ã¢ãªç²å¾ã§ããããã«å·¥å¤«ãã¾ãããããã«ãã®å¾ã«ã¯ãSLOBã¯è¤æ°CPUããåæã¢ã¯ã»ã¹ãããã¨ã¹ã±ã¼ã«ããªãããªã©ã®SLOBã®åé¡ã次ã ã«è¦ã¤ãåºããæ¹åãã¦ããã¾ãããã¹ã±ã¼ã©ããªãã£ãä¸ããæ¹åã«ããã¦ã¯ãspinlockã®ä½¿ãæ¹ã«é£åããããã«ç¡æ°ã®ãã°ãä»è¾¼ãã§ãã¾ããããæçµæ¥ã«ã¯ãªãã¨ãå ¨ã¦è§£æ±ºããããã§ãã
æçµçã«ã¯du -s
ã«ã¤ãã¦ã¯ã·ã³ã°ã«ã³ã¢æ§è½ããã«ãã³ã¢(4ã³ã¢)æ§è½å
±ã«SLOBã«ã¯10å以ä¸ã®å¤§å·®ãã¤ãã¦å§åãSLABã¨ã¯ã»ã¼äºè§ãã¨ããçµæãå©ãåºãã¾ããããã®ä¸ãSLOBAã®ã³ã¼ãéã¯SLABã®ç´1/6ã«éããªãã¨ããã®ã§ãããé©ãã§ãã
çè ã®è¦ç«ã¦ã§ã¯ãSLOBã«ã¯ã»ã¨ãã©ã®ã¯ã¼ã¯ãã¼ãã§ãå§åããã¨æãã¾ãããSLABã«å¯¾ãã¦ã¯åã£ããè² ããããã¨ãã£ãã¨ããã§ãããããã²è²ã ãªã·ã¹ãã æ§æãã¯ã¼ã¯ãã¼ãã§ãã¼ã¿ãã¨ã£ã¦ããã ãããã¨ããã§ãã
ãã以ä¸æè¡çãªè©³ç´°ã«ã¯è¸ã¿è¾¼ã¿ã¾ããããåèã¾ã§ã«SLOBã¨SLABãSLOBAã®æ§é ã表ãæ¦è¦å³ãè¼ãã¦ããã¾ããkmalloc()ã§åå¾ãããµã¤ãºãã¨ã«slabã¢ãã±ã¼ã¿ãåå¨ããã¨ããã¤ã¡ã¼ã¸ã§è¦ã¦ããã ããã°ã¨æãã¾ã*6ã
- SLOB
- SLAB
- SLOBA
è¬å¸«ã®ç®ããè¦ã¦æé·ããã¨ãã
å½¼ã¯æãåããéãã«ã¤ãã¦ã¯æåããæãããã¨ã¯ä½ããªãã£ãã§ããä»åã¯Linuxã«ã¼ãã«éçºã®ãä½æ³ãå¹ççãªã½ã¼ã¹ã³ã¼ã解æããã³ãã©ãã«ã·ã¥ã¼ãã£ã³ã°ã®æ¹æ³ãªã©ãä½é¨ã§ããã®ãããã£ãã®ã§ã¯ãªããã¨æãã¾ããä»å¾ã¯ããã«é«éã«ããã¤ãé«å質ãªã³ã¼ããæ¸ããã¨ã³ã¸ãã¢ã«ãªã£ã¦ãããã®ã§ã¯ãªãã§ããããã
è£è©±: éçºã¯ã¤ã³ã¯ãªã¡ã³ã¿ã«ã«
å½¼ã¯äºæ¥ç®ãããã§ãã¨ãããã°ãåããªãç¶æ ã§æ©ãã§ãã¾ããããã®éããåé¡ã®ç¡ãã£ããã¨ãããã£ã¦ããã³ãããããããåé¡ãæ¤åºããã³ããããã¾ã§ã®éã®ã©ã®ã³ããããç¯äººããäºåæ¢ç´¢ã«ãã£ã¦è¦ã¤ããbisectã¨å¼ã°ããæ¹æ³*7ã使ããã¨ãã¾ããããããã¯ä¸å¯è½ã§ããããªããªãåé¡ãèµ·ããªãã£ãç¶æ ããèµ·ããããã«ãªãã¾ã§ä¸åã³ãããããã«æ°ç¾è¡ãå¤æ´ãã¦ãã¾ã£ã¦ããããã§ãã
å½¼ã®è¨æ¶ã«ã¯ãã°ã«æ©ã¾ããããã¨ã«å ãã¦ã次ã¯ã¤ã³ã¯ãªã¡ã³ã¿ã«ã«éçºããããã¨ããæããå»ã¾ãããã¨ã§ããããå¤åã
ãããã«
æ¬ã³ã¼ã¹ã¯ãLinuxéçºè ãç®æãã!ãã¨éæã£ã¦ãã¾ãããããµãããä»å¾Linuxéçºãç¶ãããã©ããã¯å½¼ã次第ã§ããæ¬ã³ã¼ã¹ãLinuxã¨ããç¹å®ã½ããã¦ã§ã¢ã®éçºæè¡ã ãã§ã¯ãªããããã©ãã«ã«ééããæã®å¯¾å¦æ¹æ³ãããä½ããå¤ããã¨ãã¯ä¸åã«ä¸ã¤ã ãã¨ããååãããã½ã¼ã¹ã³ã¼ããèªãã³ãããªã©æ±ç¨çãªç¥èãå¾ããã£ããã¨ãªã£ãã®ã§ããã°å¹¸ãã§ãã
*1:ä¸è¦ã»ãã¥ãªãã£ã«ã¯é¢ä¿ãªãããã«è¦ãã¾ãããLinuxã«éããã«ã¼ãã«ã«é¢ããã»ãã¥ãªãã£ç¥èãå¾ãã«ã¯ãã®åºç¤ã¨ãã¦ã«ã¼ãã«ãã®ãã®ã®ç¥èãå¿ è¦ãªã®ã§ãå®ã¯ååé¢ä¿ãããã®ã§ã
*2:dmesgã³ãã³ãã«ãã£ã¦è¦ããã¾ã
*3:ãã¨ãã°CVE-2018-11232ãããã¾ããèå³ã®ããããã¯èªãã§ã¿ã¦ãã ããã
*4:SLUBã«ã¤ãã¦ã¯æéã®é½åä¸çç¥ãã¾ãã
*5:ãã¡ã¤ã«ã·ã¹ãã ãã¹ãã¬ã¼ã¸ããã¤ã¹ã§ã¯ãªãã¡ã¢ãªä¸ã«åå¨ããtmpfsä¸ã«ä½ããã¨ã«ãã£ã¦ããã®ã³ãã³ãçºè¡ã«å¯¾ããI/Oå¦çã®å½±é¿ãç¡ããã¦ãã¾ã
*6:slabã¢ãã±ã¼ã¿ã使ãã®ã¯kmalloc()ã ãã§ã¯ãªãã®ã§ãããããã«ã¤ãã¦ã¯å²æãã¾ã
*7:ãã¨ãã°åè ããå¾è ã®éã«16ã³ãããããã°ãæåã¯8åç®ã®ã³ãããã§åé¡ãèµ·ããã確èªãã¦ãåé¡ãèµ·ããªããã°æ¬¡ã¯12åç®ã®ã³ãããã§ç¢ºèªâ¦ã¨ããããã«å®¹çè ãä¸åº¦ã«ååã¥ã¤æ¸ããã¦ãã