{"id":159,"date":"2024-04-16T15:33:57","date_gmt":"2024-04-16T07:33:57","guid":{"rendered":"https:\/\/yewpo.top\/?p=159"},"modified":"2024-04-16T15:33:57","modified_gmt":"2024-04-16T07:33:57","slug":"qemu-%e5%90%af%e5%8a%a8-linux-%e5%86%85%e6%a0%b8","status":"publish","type":"post","link":"https:\/\/www.yewpo.top\/index.php\/159\/","title":{"rendered":"QEMU \u542f\u52a8 Linux \u5185\u6838"},"content":{"rendered":"<h2>1 \u7f16\u8bd1 Linux \u5185\u6838<\/h2>\n<blockquote><p>\u6211\u4eec\u5047\u8bbe\u4f60\u5df2\u7ecf\u5b89\u88c5\u597d\u4e86 QEMU \u6a21\u62df\u5668\u3002<\/p>\n<p><strong>\u5982\u679c\u4f60\u4f7f\u7528\u4e86 5.0.0 \u4e4b\u540e\u7684\u7248\u672c\uff0c\u914d\u7f6e QEMU \u7684\u7f16\u8bd1\u914d\u7f6e\u7684\u65f6\u5019\uff0c\u9700\u8981\u6dfb\u52a0 &#8211;enable-kvm, &#8211;enable-slirp<\/strong>\u3002\u65b9\u5f0f\u5982\u4e0b\uff1a<\/p>\n<pre><code class=\"language-shell\">.\/configure --enable-slirp --enable-kvm\nmake -j`<code>nproc`<\/code><\/code><\/pre>\n<\/blockquote>\n<h3>1.1 \u83b7\u53d6 Linux \u6e90\u7801<\/h3>\n<p>\u53ef\u4ee5\u5728 <a href=\"https:\/\/kernel.org\/\">Linux \u5185\u6838\u7f51\u7ad9<\/a>\u83b7\u53d6\u6e90\u7801\u3002\u8fd9\u91cc\uff0c\u6211\u9009\u62e9\u7684\u662f $v5.10.215$ \u7684\u7248\u672c\u3002\u4e0b\u8f7d\u540e\uff0c\u4f7f\u7528 tar \u5de5\u5177\u8fdb\u884c\u89e3\u538b\u3002<\/p>\n<pre><code class=\"language-shell\">wget https:\/\/cdn.kernel.org\/pub\/linux\/kernel\/v5.x\/linux-5.10.215.tar.xz\ntar xvf linux-5.10.215.tar.xz\ncd linux-5.10.215<\/code><\/pre>\n<h3>1.2 \u521b\u5efa\u914d\u7f6e\u6587\u4ef6<\/h3>\n<p>\u5728 <code>linux-5.10.215<\/code> \u7684\u76ee\u5f55\u4e0b\uff0c\u53ef\u4ee5\u901a\u8fc7 <code>make menuconfig<\/code> \u8fdb\u884c\u914d\u7f6e\u3002<code>make defconfig<\/code> \u53ef\u4ee5\u751f\u6210\u4e00\u4e2a\u9ed8\u8ba4\u914d\u7f6e\uff0c<code>make kvm_guest.config<\/code> \u53ef\u4ee5\u751f\u6210\u5728 QEMU \u4e2d\u8fd0\u884c\u7684\u5185\u6838\u914d\u7f6e\u3002\u6240\u4ee5\u8fd9\u91cc\u53ef\u4ee5\u4f7f\u7528 <code>make kvm_guest.config<\/code>\u3002<\/p>\n<p>\u5982\u679c\u9700\u8981\u8c03\u8bd5\u4fe1\u606f\uff0c\u53ef\u4ee5\u9009\u62e9\u5728 <code>.config<\/code> \u6587\u4ef6\u91cc\u641c\u7d22\u627e\u5230\u4ee5\u4e0b\u914d\u7f6e\u9009\u9879\u8fdb\u884c\u914d\u7f6e\u3002<\/p>\n<pre><code>CONFIG_KCOV=y\nCONFIG_DEBUG_INFO=y\nCONFIG_KASAN=y\nCONFIG_SECURITYFS=y\nCONFIG_CONFIGFS_FS=y\n\nCONFIG_KASAN_INLINE=y\nCONFIG_DEBUG_INFO_DWARF4=y<\/code><\/pre>\n<blockquote><p>\u6700\u540e\u4e24\u4e2a\u9700\u8981\u5c06\u524d\u9762\u7684\u8fdb\u884c <code>make olddefconfig<\/code> \u4e4b\u540e\u624d\u53ef\u4ee5\u88ab\u641c\u7d22\u627e\u5230\u3002<\/p>\n<p>DWARF4 \u662f\u4e00\u4e2a\u8c03\u8bd5\u683c\u5f0f\u6807\u51c6\u3002<\/p><\/blockquote>\n<p>\u7136\u540e\uff0c<code>make olddefconfig<\/code> \u53ef\u4ee5\u5bf9\u5176\u8fdb\u884c\u91cd\u65b0\u751f\u6210\u914d\u7f6e\u6587\u4ef6\u3002\u6700\u540e\uff0c\u901a\u8fc7 <code>make -j0<\/code> \u8fdb\u884c\u7f16\u8bd1\u3002\u6570\u5341\u5206\u949f\u540e\uff0c\u5c31\u53ef\u4ee5\u5f97\u5230\u7f16\u8bd1\u7684\u7ed3\u679c\uff08\u7b14\u8005\u7528 8 \u6838\u53ea\u7f16\u8bd1\u4e86 9 \u5206\u949f\uff09\u3002<\/p>\n<h2>2 \u521b\u5efa\u955c\u50cf\u6587\u4ef6<\/h2>\n<p>\u6309\u7167\u535a\u5ba2\u91cc\u9762\u7684\u4ecb\u7ecd\uff0c\u63a8\u8350\u4e86 syzkaller \u5185\u7684\u955c\u50cf\u6784\u5efa\u65b9\u5f0f\u3002<\/p>\n<blockquote><p><strong>\u4f7f\u7528 debootstrap \u521b\u5efa\u955c\u50cf\u6587\u4ef6<\/strong><\/p>\n<p>\u9996\u5148\u4f7f\u7528\u547d\u4ee4 <code>sudo apt install debootstrap<\/code> \u5b89\u88c5 debootstrap\uff1b\u521b\u5efa\u4e00\u4e2a\u955c\u50cf\u6587\u4ef6\u5939\uff0c\u5728\u8fd9\u4e2a\u6587\u4ef6\u4e2d\u6267\u884c\u4ee5\u4e0b\u7684\u64cd\u4f5c\uff1a<\/p>\n<pre><code class=\"language-shell\">wget https:\/\/raw.githubusercontent.com\/google\/syzkaller\/master\/tools\/create-image.sh -O create-image.sh\nchmod +x create-image.sh\n.\/create-image.sh<\/code><\/pre>\n<p>\u521b\u5efa\u7ed3\u679c\u5c31\u662f\u4e00\u4e2a <code>bullseye.img<\/code> \u955c\u50cf\u3002<\/p><\/blockquote>\n<h2>3 \u5728 QEMU \u4e0a\u8fd0\u884c Linux<\/h2>\n<p>\u521b\u5efa\u4ee5\u4e0b\u811a\u672c <code>startup.sh<\/code>\uff1a<\/p>\n<pre><code class=\"language-shell\">#!\/usr\/bin\/env bash\n\nqemu-system-x86_64 \\\n    -m 2G \\\n    -smp 2 \\\n    -kernel $KERNEL\/arch\/x86\/boot\/bzImage \\\n    -append \"console=ttyS0 root=\/dev\/sda earlyprintk=serial net.ifnames=0\" \\\n    -drive file=$IMAGE\/bullseye.img,format=raw \\\n    -net user,host=10.0.2.10,hostfwd=tcp:127.0.0.1:10021-:22 \\\n    -net nic,model=e1000 \\\n    -enable-kvm \\\n    -nographic \\\n    -pidfile vm.pid \\\n    2&gt;&amp;1 | tee vm.log<\/code><\/pre>\n<blockquote><p>\u9700\u8981\u4fee\u6539 <code>$KERNEL<\/code> \u548c <code>$IMAGE<\/code> \u4e24\u4e2a\u53d8\u91cf\uff0c\u5e76\u4e14\u7ed9\u8be5\u811a\u672c\u6267\u884c\u6743\u9650\u3002<\/p><\/blockquote>\n<p>\u8fd0\u884c <code>startup.sh<\/code>\uff0c\u4f1a\u770b\u5230\u4ee5\u4e0b\u7ed3\u679c\uff1a<\/p>\n<p><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/raw.githubusercontent.com\/YEWPO\/yewpoblogonlinePic\/main\/image-20240416134850752.png'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  decoding=\"async\" data-original=\"https:\/\/raw.githubusercontent.com\/YEWPO\/yewpoblogonlinePic\/main\/image-20240416134850752.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"image-20240416134850752\" \/><\/div><\/p>\n<h3>3.1 \u4f7f\u7528 syzkaller \u7ba1\u7406<\/h3>\n<blockquote><p>syzkaller \u4e00\u4e2a\u65e0\u76d1\u7763\u7684\u5185\u6838\u6a21\u7cca\u6d4b\u8bd5\u5668\u3002<\/p><\/blockquote>\n<p>\u6309\u7167<a href=\"https:\/\/github.com\/google\/syzkaller\/blob\/master\/docs\/linux\/setup.md\">\u8fd9\u91cc<\/a>\u6765\u5b89\u88c5 syzkaller\uff0c\u5e76\u6309\u7167\u4ee5\u4e0b\u793a\u4f8b\u7f16\u5199 syzkaller \u7684\u914d\u7f6e\uff0c\u5e76\u547d\u540d\u4e3a <code>my.cfg<\/code>\u3002<\/p>\n<pre><code>{\n    \"target\": \"linux\/amd64\",\n    \"http\": \"127.0.0.1:56741\",\n    \"workdir\": \"$GOPATH\/src\/github.com\/google\/syzkaller\/workdir\",\n    \"kernel_obj\": \"$KERNEL\",\n    \"image\": \"$IMAGE\/bullseye.img\",\n    \"sshkey\": \"$IMAGE\/bullseye.id_rsa\",\n    \"syzkaller\": \"$GOPATH\/src\/github.com\/google\/syzkaller\",\n    \"procs\": 8,\n    \"type\": \"qemu\",\n    \"vm\": {\n        \"count\": 4,\n        \"kernel\": \"$KERNEL\/arch\/x86\/boot\/bzImage\",\n        \"cpu\": 2,\n        \"mem\": 2048\n    }\n}<\/code><\/pre>\n<p>\u5176\u4e2d\uff0c<code>$GOPATH<\/code> \u53ef\u4ee5\u4e0d\u7528\u5728\u610f\uff0c<code>workdir<\/code> \u548c <code>syzkaller<\/code> \u76f4\u63a5\u4f7f\u7528\u81ea\u5df1\u521b\u5efa\u8fd9\u4e24\u4e2a\u76ee\u5f55\u7684\u5730\u5740\u3002<code>$KERNEL<\/code> \u4f7f\u7528\u4e0b\u8f7d\u7684 Linux \u6e90\u7801\u7684\u76ee\u5f55\u5730\u5740\uff1b<code>$IMAGE<\/code> \u4f7f\u7528\u81ea\u5df1\u521b\u5efa\u955c\u50cf\u7684\u76ee\u5f55\u3002<\/p>\n<p>\u6700\u540e\uff0c\u5728 <code>syzkaller<\/code> \u7684\u76ee\u5f55\u4e0b\u4f7f\u7528\u547d\u4ee4 <code>.\/bin\/syz-manager -config=my.cfg<\/code>\uff0c\u4f7f\u7528 <code>-debug<\/code> \u53ef\u4ee5\u589e\u52a0\u8c03\u8bd5\u4fe1\u606f\u3002\u8fd0\u884c\u6210\u529f\u4e4b\u540e\uff0c\u5728 <code>127.0.0.1:56741<\/code> \u4e0a\u67e5\u770b syzkaller \u7684\u4fe1\u606f\u3002\u76f8\u5173\u4fe1\u606f\u7684\u663e\u793a\u5982\u4e0b\uff1a<\/p>\n<p><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/raw.githubusercontent.com\/YEWPO\/yewpoblogonlinePic\/main\/image-20240416152013962.png'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  decoding=\"async\" data-original=\"https:\/\/raw.githubusercontent.com\/YEWPO\/yewpoblogonlinePic\/main\/image-20240416152013962.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"image-20240416152013962\" \/><\/div><\/p>\n<blockquote><p><strong>\u6211\u7684\u6240\u6709\u6570\u636e\u90fd\u662f 0\uff1f<\/strong><\/p>\n<p>\u771f\u5de7\uff0c\u6211\u4e5f\u9047\u5230\u4e86\u3002\u6253\u5370 syzkaller \u7684\u8c03\u8bd5\u4fe1\u606f\uff0c\u53ef\u4ee5\u53d1\u73b0\u7684\u662f\uff0cLinux \u7684\u7f51\u7edc\u63a5\u53e3\u6ca1\u6709\u88ab\u6b63\u5e38\u7684\u8bc6\u522b\u548c\u8bbe\u7f6e\uff08\u5c31\u662f\u6709\u4e00\u4e2a ERROR\uff09\u3002\u901a\u8fc7 STFW\uff0c\u627e\u5230\u4e86\u4e0b\u9762\u53c2\u8003\u8d44\u6599\u4e2d\u7684\u4e00\u4e2a\u90ae\u4ef6\u5217\u8868\uff0c\u63cf\u8ff0\u4e86\u540c\u6837\u7684\u95ee\u9898\u3002<\/p>\n<p>\u89e3\u51b3\u65b9\u5f0f\uff1a\u5728\u4e0a\u9762\u63d0\u5230\u7684 <code>my.cfg<\/code> \u7684 <code>vm<\/code> \u7684\u5c5e\u6027\u4e2d\uff0c\u6dfb\u52a0 <code>\"cmdline\": \"net.ifnames=0\"<\/code>\u3002<\/p>\n<p>\u6765\u81ea ChatGPT \u7684\u56de\u7b54\uff1a<code>net.ifnames=0<\/code> \u5c31\u662f\u7981\u7528\u53ef\u9884\u6d4b\u7684\u7f51\u7edc\u63a5\u53e3\u547d\u540d\u7ea6\u5b9a\uff0c\u5e76\u6539\u7528\u4f20\u7edf\u7684\u65b9\u6cd5\u3002<\/p><\/blockquote>\n<h2>\u53c2\u8003\u8d44\u6599<\/h2>\n<p><a href=\"https:\/\/vccolombo.github.io\/cybersecurity\/linux-kernel-qemu-setup\/\">Linux kernel QEMU setup<\/a><\/p>\n<p><a href=\"https:\/\/github.com\/google\/syzkaller\/blob\/master\/docs\/linux\/setup_ubuntu-host_qemu-vm_x86-64-kernel.md\">Setup: Ubuntu host, QEMU vm, x86-64 kernel<\/a><\/p>\n<p><a href=\"https:\/\/dwarfstd.org\/dwarf4std.html\">DWARF4<\/a><\/p>\n<p><a href=\"https:\/\/github.com\/google\/syzkaller\">syzkaller<\/a><\/p>\n<p><a href=\"https:\/\/groups.google.com\/g\/syzkaller\/c\/t9Z_Qh2TZxc?pli=1\">syzkaller can&#8217;t start linux mail list<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728 QEMU \u4e0a\u8fd0\u884c x86-64 \u7684 5.10.215 \u7684 Linux \u5185\u6838\uff0c\u4e14\u4ea6\u53ef\u4ee5\u4f7f\u7528 syzkaller \u6765\u8fd0\u884c\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[10],"class_list":["post-159","post","type-post","status-publish","format-standard","hentry","category-os","tag-linux"],"_links":{"self":[{"href":"https:\/\/www.yewpo.top\/index.php\/wp-json\/wp\/v2\/posts\/159","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.yewpo.top\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.yewpo.top\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.yewpo.top\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yewpo.top\/index.php\/wp-json\/wp\/v2\/comments?post=159"}],"version-history":[{"count":0,"href":"https:\/\/www.yewpo.top\/index.php\/wp-json\/wp\/v2\/posts\/159\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.yewpo.top\/index.php\/wp-json\/wp\/v2\/media?parent=159"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yewpo.top\/index.php\/wp-json\/wp\/v2\/categories?post=159"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yewpo.top\/index.php\/wp-json\/wp\/v2\/tags?post=159"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}