Quantcast
Channel: φ(・・*)ゞ ウーン カーネルとか弄ったりのメモ
Viewing all 191 articles
Browse latest View live

TwitterのPC版のUIからだと連携解除できないappの連携解除方法メモ

$
0
0

iPhoneとかで連携したappの一部はPCのWeb版からだとrevokeできなかったのでやり方のメモです。

PCのWeb版だと連携しているアプリを見るとLearn how to revoke an iOS appとリンクがあるだけでRevoke Accessボタンがないappがあります。Twitter for iPhoneとかを使ってるアプリがこうなってるようです。

revokeしたい場合はスマホのアプリもしくは、モバイル版のtwitterにアクセスしてrevokeします。 ただ、それでも個別にrevokeということは出来ないのでiPhoneを使っているならTwittre for iPhoneをrevokeします。そうするとこのrevokeに連動してTwitter for iPhoneと連携しているappが一気にrevokeされます。 もし、許可したいappがある場合は再度許可してあげる必要があります。


qemu: pyhtonでゲストとシリアル通信

$
0
0

ゲスト側のLinuxカーネルでシリアルコンソールを有効にしているときに、ホストからpythonでシリアルコンソールにアクセスするときメモです。

ゲスト側はカーネルコマンドラインでシリアルの設定をするのと、qemuのオプションで-serial ptyとしてptyを使うようにする。

$ qemu-kvm -initrd ./initramfs-4.17.2-200.fc28.x86_64.img -kernel ./vmlinuz-4.17.2-200.fc28.x86_64 -m 512 -append "console=ttyS0,115200" -serial pty -nographic
QEMU 2.11.1 monitor - type 'help' for more information
(qemu) qemu-system-x86_64: -serial pty: char device redirected to /dev/pts/2 (label serial0)

pythonのコードは特にパッケージとかはインストールしていなくて、qemu起動時に表示された /dev/pts/Xをオープンしてデータの読み書きを行います。

#!/usr/bin/env python3#  qemu-system-x86_64 -initrd ./initramfs-4.17.2-200.fc28.x86_64.img  -kernel ./vmlinuz-4.17.2-200.fc28.x86_64 -m 512 -append "console=ttyS0,115200" -serial pty -nographicimport io, os
pty = io.TextIOWrapper(
    io.FileIO(
        os.open(
            "/dev/pts/2", os.O_NOCTTY | os.O_RDWR
        ),
        "w+"
    )
)
pty.write("uname -a\n");
for line initer(pty.readline, None):
    print(line.strip())

こんな感じで使えます。

f:id:masami256:20180701003342p:plain

Linux:パフォーマンスに影響あるデバッグオプションがどれだけ影響あるか試してみた

$
0
0

なんとなくやってみた系ですね。

今回はCONFIG_DEBUG_OBJECTSのところです。

f:id:masami256:20180706233206p:plain

CONFIG_DEBUG_OBJECTS_FREEがkmalloc/kfreeをヘヴィにつかうような場合にパフォーマンス劣化するよーなんていってます。

f:id:masami256:20180706233254p:plain

まずはCONFIG_DEBUG_OBJECTSの項目を全部無効にした場合。

この時点でもロック周りに時間取ってますね。

f:id:masami256:20180706233504p:plain

hackbenchを引数 10 process 20000で実行してる時の様子がこんな感じです。

f:id:masami256:20180706233612p:plain

次にCONFIG_DEBUG_OBJECTSの項目を全部無効にした場合。

起動した時点でかなりの時間をロックで使ってます。

f:id:masami256:20180706233435p:plain

そして、hackbenchを同じく実行するとこうこうなります/(^o^)\

f:id:masami256:20180706233745p:plain

このときはこんな感じになっていてもうどうにもならない感がありますね。

f:id:masami256:20180706233833p:plain

説明に書いてあるとおり、ほんと遅くなりますね。

( ´ー`)フゥー...

日経Linux 2018年 7 月号

日経Linux 2018年 7 月号

dockerでNignxのリバースプロキシとwebアプリをlinkしたローカル開発環境を作る

$
0
0

前に仕事で作ったdockerを使ったwebアプリの開発環境の覚書です。

実環境はAWSで動いていて、ALBがhttpsでリクエストを受けてALBとwebアプリはhttpで通信します。このような構成をdockerで作りたかったわけです。 簡単な概要はこんな図になります。

f:id:masami256:20180724230335p:plain

ALBのところをNginxのリバースプロキシに置き換えて作りました。

Nginxのリバースプロキシはこんな設定です。

server {
       listen         443;
       server_name    www.webapp-test.local;
       ssl on;
       ssl_certificate      /etc/nginx/server.crt;
       ssl_certificate_key  /etc/nginx/server.key;

       location / {
             proxy_set_header Host $host;
             proxy_set_header X-Real-IP $remote_addr;
             proxy_set_header X-Forwarded-Proto https;
             proxy_set_header X-Forwarded-Host $host;
             proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

             # name is docker's link alias.
             proxy_pass http://local.webapp-test.local:3000/;
             proxy_redirect http:// https://;
       }
}

アプリの方でX-Forwarded-*を参照するのでセットしたり、hostヘッダはそのまま流したりしてます。 server_nameは実際にはちゃんとしたサーバ名ですがここではこんな名前にしてます。この名前はdocker-compose.ymlファイルのlinkで使う名前と合わせています。 www.webapp-test.localがブラウザでアクセスするURLになって、proxy_passで記述しているのがアプリのURLですね。どっちもlinkする時に使います。

Dockerfileはこの程度です。ベースのイメージは軽めなやつがよかったのでalpineを使ってます。

FROM alpine:latest

RUN apk update && \
apk add nginx && \
mkdir -p /run/nginx && \
rm -rf /var/cache/apk/*

COPY nginx/nginx.conf /etc/nginx/nginx.conf
COPY nginx/server.conf /etc/nginx/conf.d/server.conf

COPY nginx/server.crt /etc/nginx/server.crt
COPY nginx/server.key /etc/nginx/server.key

CMD ["/usr/sbin/nginx", "-g", "daemon off;"]

webアプリの方はDockerfileとかは特に変わったことはしてません。webaアプリのほうにあるdocker-compose.ymlでlinkしてあげるだけです。

version:'2'services:webapp:build: .
    image: webapp
    hostname: local
    domainname: local.webapp-test.local
  proxy:image: local_dev_proxy
    ports:- 443:443
    links:- webapp:local.webapp-test.local
    hostname: www
    domainname: www.webapp-test.local

webappがwebアプリ、proxyがリバースプロキシです。hostとdomainnameはNginxの設定と合わせています。proxyのほうは443ポートを公開してます。ホストからアクセスする時は普通にhttpsの443番ポートを使います。で、proxyからwebappにアクセスを流したいのでlinkを使ってます。 あ、リバースプロキシもdocker-compose.yml使ってビルドしていて、名前はlocal_dev_proxyとしてます。

docker-compose upでwebアプリとリバースプロキシを起動しておいてcurlでアクセスを確認するとこうなります。

f:id:masami256:20180724232128p:plain

とまあ、ローカルの開発環境でALBの代わりにNginxでリバースプロキシを作ったというめもでした。

Docker実践ガイド impress top gearシリーズ

Docker実践ガイド impress top gearシリーズ

linux: カーネルからioctl(2)可能なfdをユーザ空間に返す

$
0
0

KVMはioctl(2)でVMを作ったりvcpuを作ったりします。この時に使うfdは/dev/kvmファイルに対してioctl(2)を実行した時の戻り値です。ioctl(2)の戻り値がioctl(2)可能なfdとなってます。ユーザーランドに返すfdはどうやって作るのかというのが今回のめもです。

早速ですが、出来たコードはこうなります。

#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt#include <linux/module.h>#include <linux/kernel.h>#include <linux/slab.h>#include <linux/anon_inodes.h>#include <linux/string.h>#include <linux/miscdevice.h>#include <linux/fs.h>#include <linux/file.h>

MODULE_DESCRIPTION("ioctl test");
MODULE_AUTHOR("masami256");
MODULE_LICENSE("GPL");

struct fd_test_data {
    unsignedlong id;
};

staticlong fd_test_anon_fd_ioctl(struct file *filp, unsignedint ioctl, unsignedlong arg)
{
    int r = -1;
    struct fd_test_data *p = filp->private_data;

    pr_info("%s: ioctl is %d\n", __func__, ioctl);

    switch (ioctl) {
    case0:
        r = p->id;
        break;
    default:
        pr_warn("unkown ioctl %ud\n", ioctl);
    }

    return r;
}

staticstruct file_operations fd_test_anon_fd_fops = {
    .unlocked_ioctl     = fd_test_anon_fd_ioctl,
    .compat_ioctl       = fd_test_anon_fd_ioctl,
    .llseek     = noop_llseek,
};

staticint create_file(unsignedlong id)
{
    struct fd_test_data *p = kmalloc(sizeof(*p), GFP_KERNEL);
    int fd;
    char name[256] = { 0x0 };
    struct file *filp;

    if (!p)
        return -ENOMEM;

    p->id = id;

    snprintf(name, sizeof(name), "fd_test-%ld\n", id);


    filp =  anon_inode_getfile(name, &fd_test_anon_fd_fops, p, O_RDWR);
    if (!filp)
        return -1;

    fd = get_unused_fd_flags(O_CLOEXEC);
    if (fd < 0)
        return -1;

    fd_install(fd, filp);

    return fd;
}

staticlong fd_test_ioctl(struct file *filp, unsignedint ioctl, unsignedlong arg)
{
    long r = -EINVAL;

    pr_info("%s: ioctl is %d\n", __func__, ioctl);

    switch (ioctl) {
    case0:
        r = create_file(arg);
        break;
    default:
        pr_warn("unkown ioctl %ud\n", ioctl);
    }

    return r;
}


staticstruct file_operations fd_test_chardev_fops = {
    .unlocked_ioctl     = fd_test_ioctl,
    .compat_ioctl       = fd_test_ioctl,
    .llseek         = noop_llseek,
};

staticstruct miscdevice fd_test_chardev = {
    .minor      = 243,
    .name       = "fd_test",
    .fops       = &fd_test_chardev_fops,
};

staticint fd_test_init(void)
{
    int fd;

    fd = misc_register(&fd_test_chardev);
    if (fd < 0) {
        pr_warn("failed to create miscdevice\n");
        return fd;
    }

    pr_info("device file created\n");
    return fd;
}

staticvoid fd_test_exit(void)
{
    misc_deregister(&fd_test_chardev);
    pr_info("finish %s\n", __func__);

}

module_init(fd_test_init);
module_exit(fd_test_exit);

まずはmiscデバイスを作っていて、最初にこのファイルを開いてioctl(2)を実行します。そうするとioctl(2)を実行できるfdが返るという感じです。 このfdの作り方は以下の3ステップでできます。

  1. fdを新たに割り当て
  2. file構造体を作成
  3. fdとファイル構造体を関連付ける

あ、上記のコードだと1と2は逆ですが。

1のfdの割り当てはget_unused_fd_flags()で行います。 2はanon_inode_getfile()です。この関数の3番目の引数はfile構造体のprivate_data変数に設定するデータです。上記のコードだとfd_test_data構造体を設定してます。 最後の3はfd_install()で、見ての通りfdとfile構造体を渡してます。 そして、fdをユーザーランドに返せば完了です。

テストコードはこんな感じです。

#include <stdio.h>#include <stdlib.h>#include <unistd.h>#include <fcntl.h>#include <sys/types.h>#include <sys/stat.h>#include <sys/ioctl.h>int main(int argc, char **argv)
{
    int fd;
    int anon_fd;
    int r;

    unsignedlong id = argc == 2 ? strtoul(argv[1], NULL, 10) : 1234UL;

    fd = open("/dev/fd_test", O_RDWR);
    if (fd < 0) {
        perror("open");
        exit(-1);
    }

    anon_fd = ioctl(fd, 0, id);
    if (anon_fd < 0) {
        perror("ioctl");
        exit(-1);
    }


    r = ioctl(anon_fd, 0, 0UL);

    printf("id is %d\n", r);
    close(fd);
}

これをコンパイルして動かすとこんなふうになります。

masami@kerntest:~/fd_test$ sudo ./a.out 1234
id is 1234
masami@kerntest:~/fd_test$ sudo ./a.out 12345678
id is 12345678
masami@kerntest:~/fd_test$ 

( ´ー`)フゥー...

Linuxとかカーネル方面のYoutubeチャンネル

$
0
0

Linuxとかカーネル方面のYoutubeチャンネルをめも

hupstream

Kernel Recipesというタイトルのシリーズがカーネルの濃い発表動画。

www.youtube.com

KVM Forum

KVMQEMUなど。

www.youtube.com

The Linux Foundation

色んなカンファレンス動画がある。

https://www.youtube.com/user/TheLinuxFoundation/videos

USENIX

色んなカンファレンス動画がある。

www.youtube.com

Fedora Project

Flockが開発者・ユーザーがあつまるイベントでディストリビューションの開発に関するネタが多い。

www.youtube.com

DebConf Videos

Debianのカンファレンス。

www.youtube.com

FOSDEM

FOSDEM(Free and Open Source Development European Meeting)。ヨーロッパで行われてるOSS系のイベント。

www.youtube.com

BSDCan

BSD!

https://www.youtube.com/channel/UCuQhwHMJ0yK2zlfyRr1XZ_Q/featured

bsdconferences

BSD系のカンファレンスはこちらが多いか。

www.youtube.com

EPTの設定をbhyveで調べる

$
0
0

KVMよりもEPTの使用前提なbhyveのほうがコード読みやすかったのです。Nested Paging in bhyveというFreeBSDのメモリ管理からbhyveでのEPT周りの実装を解説した論文があったのも理由としては大きいですね。

EPTPの設定

vmx_vminit()という関数でeptpの設定をする関数を呼びます。

814staticvoid *
  815 vmx_vminit(struct vm *vm, pmap_t pmap)
  816 {
  817uint16_t vpid[VM_MAXCPU];
  ~ 略 ~
  827         }
  828         vmx->vm = vm;
  829830         vmx->eptp = eptp(vtophys((vm_offset_t)pmap->pm_pml4));

pmap_tはpmap構造体で、PML4のアドレスを保持している(LinuxだとPGD)。pml4_entry_tはu_int64_tの別名(typedef)。

309/*  310  * The kernel virtual address (KVA) of the level 4 page table page is always  311  * within the direct map (DMAP) region.  312  */313struct pmap {
  314struct mtx              pm_mtx;
  315         pml4_entry_t            *pm_pml4;       /* KVA of level 4 page table */316uint64_t                pm_cr3;
  317         TAILQ_HEAD(,pv_chunk)   pm_pvchunk;     /* list of mappings in pmap */318         cpuset_t                pm_active;      /* active on cpus */319enum pmap_type          pm_type;        /* regular or nested tables */320struct pmap_statistics  pm_stats;       /* pmap statistics */321struct vm_radix         pm_root;        /* spare page table pages */322long                    pm_eptgen;      /* EPT pmap generation id */323int                     pm_flags;
  324struct pmap_pcids       pm_pcids[MAXCPU];
  325 };

eptp()はこのような処理。

195uint64_t196 eptp(uint64_t pml4)
  197 {
  198uint64_t eptp_val;
  199200         eptp_val = pml4 | (EPT_PWLEVELS - 1) << 3 | PAT_WRITE_BACK;
  201if (ept_enable_ad_bits)
  202                 eptp_val |= EPT_ENABLE_AD_BITS;
  203204return (eptp_val);
  205 }

この関数はExtended-Page-Table Pointer (EPTP)の設定をしています。EPTPはIntel SDM Vol3の24.6.11 Extended-Page-Table Pointer (EPTP)に説明があります。

まず200行目を見ます。EPT_PWLEVELSは4で、PAT_WRITE_BACKは0x6です。そうすると、以下のようなbit列になります。

>>> bin(3 << 3 | 0x6)
'0b11110'

EPTPのbit2:0は0もしくは6を設定する仕様です。ここではPAT_WRITE_BACKで6を設定しています。次にbit5:3がEPT page-walk lengthとなっています。bit5:3は0b11なので3です。 202行目のEPT_ENABLE_AD_BITSは(1 << 6)です。1<<6は2進数で0b1000000なので6bit目を1にしてます。EPTPの6bit目はAccess/Dirty flagを有効にする設定です。EPTPのbit11:7は予約済みで、bit N-1:12はSDMには「Bits N–1:12 of the physical address of the 4-KByte aligned EPT PML4 table 3」とあります。Nは「N is the physical-address width supported by the logical processor.」とのことです。bit63:Nは予約済みです。なので、bit6:0までを設定するのがEPTPの設定ですね。

EPTの設定

vmx_init()からept_init()を呼びます。

ここでvmx_init()までをφ(..)メモメモ

初期化の関数はvmm_ops構造体のinit変数にvmx_init()を設定する。

3423struct vmm_ops vmm_ops_intel = {
 3424         vmx_init,

呼び出し方はVMM_INITマクロで定義されている。

169staticstruct vmm_ops *ops;
  170 #define VMM_INIT(num)   (ops != NULL ? (*ops->init)(num) : 0)

vmm_init()からvmx_init()を呼び出している。

321staticint322 vmm_init(void)
  323 {
  324int error;
  325326         vmm_host_state_init();
  327328         vmm_ipinum = lapic_ipi_alloc(&IDTVEC(justreturn));
  329if (vmm_ipinum < 0)
  330                 vmm_ipinum = IPI_AST;
  331332         error = vmm_mem_init();
  333if (error)
  334return (error);
  335336if (vmm_is_intel())
  337                 ops = &vmm_ops_intel;
  338elseif (vmm_is_amd())
  339                 ops = &vmm_ops_amd;
  340else341return (ENXIO);
  342343         vmm_resume_p = vmm_resume;
  344345return (VMM_INIT(vmm_ipinum));
  346 }

で、本題に戻ってept_init()

77int78 ept_init(int ipinum)
   79 {
   80int use_hw_ad_bits, use_superpages, use_exec_only;
   81uint64_t cap;
   8283         cap = rdmsr(MSR_VMX_EPT_VPID_CAP);
   8485/*   86          * Verify that:   87          * - page walk length is 4 steps   88          * - extended page tables can be laid out in write-back memory   89          * - invvpid instruction with all possible types is supported   90          * - invept instruction with all possible types is supported   91          */92if (!EPT_PWL4(cap) ||
   93             !EPT_MEMORY_TYPE_WB(cap) ||
   94             !INVVPID_SUPPORTED(cap) ||
   95             !INVVPID_ALL_TYPES_SUPPORTED(cap) ||
   96             !INVEPT_SUPPORTED(cap) ||
   97             !INVEPT_ALL_TYPES_SUPPORTED(cap))
   98return (EINVAL);
   99100         ept_pmap_flags = ipinum & PMAP_NESTED_IPIMASK;
  101102         use_superpages = 1;
  103         TUNABLE_INT_FETCH("hw.vmm.ept.use_superpages", &use_superpages);
  104if (use_superpages && EPT_PDE_SUPERPAGE(cap))
  105                 ept_pmap_flags |= PMAP_PDE_SUPERPAGE;   /* 2MB superpage */106107         use_hw_ad_bits = 1;
  108         TUNABLE_INT_FETCH("hw.vmm.ept.use_hw_ad_bits", &use_hw_ad_bits);
  109if (use_hw_ad_bits && AD_BITS_SUPPORTED(cap))
  110                 ept_enable_ad_bits = 1;
  111else112                 ept_pmap_flags |= PMAP_EMULATE_AD_BITS;
  113114         use_exec_only = 1;
  115         TUNABLE_INT_FETCH("hw.vmm.ept.use_exec_only", &use_exec_only);
  116if (use_exec_only && EPT_SUPPORTS_EXEC_ONLY(cap))
  117                 ept_pmap_flags |= PMAP_SUPPORTS_EXEC_ONLY;
  118119return (0);
  120 }

最初にMSRからEPTをVPIDのケーパビリティを読み出します。これはSDM Vol3のA.10 VPID AND EPT CAPABILITIESに説明があります。そして、必要な機能が使えるかチェックしてます。あとはLinuxで言うところのsysctlで設定されたデータの読み出しと、フラグの設定ですね。

amd64/vmm/intel/ept.cにはもう一つ名前にinitが付く関数があります。それはept_pinit()です。この関数はept_vmspace_alloc()の処理から呼ばれます。

181struct vmspace *
  182 ept_vmspace_alloc(vm_offset_t min, vm_offset_t max)
  183 {
  184185return (vmspace_alloc(min, max, ept_pinit));
  186 }
  187

vmspace_alloc()はメモリ管理サブシステムの関数です。3番目の引数にept_pinit()を渡すことで、初期化処理の関数としてept_pinit()を呼ぶようにしています。これは論文によるとVMMをサポートするためにこのような形になったようです。

ept_pinit()はこのような関数です。こちらもメモリ管理サブシステムのほうの関数を呼びます。

174staticint175 ept_pinit(pmap_t pmap)
  176 {
  177178return (pmap_pinit_type(pmap, PT_EPT, ept_pmap_flags));
  179 }

pmap_pinit_type()はbyhveの追加時に新規に作られた関数とのことです。こちらもEPTのためですね。

2407/* 2408  * Initialize a preallocated and zeroed pmap structure, 2409  * such as one in a vmspace structure. 2410  */2411int2412 pmap_pinit_type(pmap_t pmap, enum pmap_type pm_type, int flags)
 2413 {
 2414         vm_page_t pml4pg;
 2415         vm_paddr_t pml4phys;
 2416int i;
 24172418/* 2419          * allocate the page directory page 2420          */2421while ((pml4pg = vm_page_alloc(NULL, 0, VM_ALLOC_NORMAL |
 2422             VM_ALLOC_NOOBJ | VM_ALLOC_WIRED | VM_ALLOC_ZERO)) == NULL)
 2423                 VM_WAIT;
 24242425         pml4phys = VM_PAGE_TO_PHYS(pml4pg);
 2426         pmap->pm_pml4 = (pml4_entry_t *)PHYS_TO_DMAP(pml4phys);
 2427         CPU_FOREACH(i) {
 2428                 pmap->pm_pcids[i].pm_pcid = PMAP_PCID_NONE;
 2429                 pmap->pm_pcids[i].pm_gen = 0;
 2430         }
 2431         pmap->pm_cr3 = ~0;      /* initialize to an invalid value */24322433if ((pml4pg->flags & PG_ZERO) == 0)
 2434                 pagezero(pmap->pm_pml4);
 24352436/* 2437          * Do not install the host kernel mappings in the nested page 2438          * tables. These mappings are meaningless in the guest physical 2439          * address space. 2440          */2441if ((pmap->pm_type = pm_type) == PT_X86) {
 2442                 pmap->pm_cr3 = pml4phys;
 2443                 pmap_pinit_pml4(pml4pg);
 2444         }
 24452446         pmap->pm_root.rt_root = 0;
 2447         CPU_ZERO(&pmap->pm_active);
 2448         TAILQ_INIT(&pmap->pm_pvchunk);
 2449         bzero(&pmap->pm_stats, sizeof pmap->pm_stats);
 2450         pmap->pm_flags = flags;
 2451         pmap->pm_eptgen = 0;
 24522453return (1);
 2454 }

pm_typeとしてPT_EPTを渡しているので2441行目のところは実行されません。ここは通常のページテーブルの設定の場合のみに実行ですね。それ以外はpmap構造体の設定でpml4の物理アドレを設定したりとかしてます。

次に気になるのはept_vmspace_alloc()が何時呼ばれるのか?ですね。

ept_vmspace_alloc()の呼ばれ方

vmx_init()と同様にvmm_ops構造体に関数を設定しています。設定先の変数はvmspace_allocです。この関数も直接は呼び出さないでマクロのVMSPACE_ALLOCマクロから呼ばれます。

178 #define VMSPACE_ALLOC(min, max) \
  179         (ops != NULL ? (*ops->vmspace_alloc)(min, max) : NULL)

vm_create()がVMSPACE_ALLOCマクロを使っています。

422int423 vm_create(constchar *name, struct vm **retvm)
  424 {
  425struct vm *vm;
  426struct vmspace *vmspace;
  427428/*  429          * If vmm.ko could not be successfully initialized then don't attempt  430          * to create the virtual machine.  431          */432if (!vmm_initialized)
  433return (ENXIO);
  434435if (name == NULL || strlen(name) >= VM_MAX_NAMELEN)
  436return (EINVAL);
  437438         vmspace = VMSPACE_ALLOC(0, VM_MAXUSER_ADDRESS);
  439if (vmspace == NULL)
  440return (ENOMEM);
  441442         vm = malloc(sizeof(struct vm), M_VM, M_WAITOK | M_ZERO);
  443         strcpy(vm->name, name);
  444         vm->vmspace = vmspace;
  445         mtx_init(&vm->rendezvous_mtx, "vm rendezvous lock", 0, MTX_DEF);
  446447         vm_init(vm, true);
  448449         *retvm = vm;
  450return (0);
  451 }

vm_create()を呼んでいるのはsysctl_vmm_create()です。なのでVMの作成時に初期化処理の流れで呼ばれる感じですね。

まとめ

EPTPはeptl()で設定します。EPTに使うページテーブルの設定はept_init()でケーパビリティのチェックやフラグの設定をしてからpmap_pinit_type()でpmap構造体の設定を行うことで設定しています。

(´-`).。oO(BSD系のコードは初見でも読みやすい

( ´ー`)フゥー...

はじめてUNIXで仕事をする人が読む本 (アスキードワンゴ)

はじめてUNIXで仕事をする人が読む本 (アスキードワンゴ)

unikernelのruntimejsを試してみる

$
0
0

runtime.jsを試してみたのでメモ書きです。

f:id:masami256:20180909150234p:plain

runtme.jsはunikernelの一つでカーネルにv8のエンジンが組み込まれてて、JavaScriptの実行がサポートされています。runtime.jsのサンプルで、eshttpを使ったwebアプリのサンプルが有ったのでこれを使って動かしてみます。 今回使ったjsのコードやDockerfileなどは↓にあります。

github.com

実行するコードは以下の内容でnodeコマンドでそのまま動かすことができるようになってます。

const eshttp = require('eshttp');
const server = new eshttp.HttpServer();
const response = new eshttp.HttpResponse(200, {'server': 'runtimejs'}, 'Hello World!');

server.onrequest = request => {
  request.respondWith(response);
};

server.listen(9000);
console.log('listening to port 9000');

今回の計測はやり方として良くはないんだけど、手頃な環境がなかったのですべて1つのマシン上で行ってます。ベンチマークの実行にはabコマンドを使ってます。 hostマシンはFedora28です。

実行方法は以下の3パターンを試しました。

  1. ホストローカルで実行
  2. runteime.jsで実行
  3. Fedora 28の仮想マシン上のdockerで実行

まずはdockerもruntime.jsも使わずにローカルでindex.jsを実行した場合。

Test 1: Requests per second:    3031.68 [#/sec] (mean)
Test 2: Requests per second:    4135.48 [#/sec] (mean)
Test 3: Requests per second:    4542.56 [#/sec] (mean)
Test 4: Requests per second:    3834.94 [#/sec] (mean)
Test 5: Requests per second:    4983.80 [#/sec] (mean)
Test 6: Requests per second:    4654.19 [#/sec] (mean)
Test 7: Requests per second:    4711.87 [#/sec] (mean)
Test 8: Requests per second:    5130.57 [#/sec] (mean)
Test 9: Requests per second:    5187.80 [#/sec] (mean)
Test 10: Requests per second:    5351.89 [#/sec] (mean)

runtime.jsで実行した場合。

Test 1: Requests per second:    2577.45 [#/sec] (mean)
Test 2: Requests per second:    2562.92 [#/sec] (mean)
Test 3: Requests per second:    2494.01 [#/sec] (mean)
Test 4: Requests per second:    2558.20 [#/sec] (mean)
Test 5: Requests per second:    2802.85 [#/sec] (mean)
Test 6: Requests per second:    2705.70 [#/sec] (mean)
Test 7: Requests per second:    2850.22 [#/sec] (mean)
Test 8: Requests per second:    2901.33 [#/sec] (mean)
Test 9: Requests per second:    2505.95 [#/sec] (mean)
Test 10: Requests per second:    2331.00 [#/sec] (mean)

fedora 28の仮想環境の上でdockerで実行した場合。

Test 1: Requests per second:    2086.77 [#/sec] (mean)
Test 2: Requests per second:    3054.37 [#/sec] (mean)
Test 3: Requests per second:    3071.91 [#/sec] (mean)
Test 4: Requests per second:    2478.68 [#/sec] (mean)
Test 5: Requests per second:    2888.59 [#/sec] (mean)
Test 6: Requests per second:    2938.15 [#/sec] (mean)
Test 7: Requests per second:    3135.09 [#/sec] (mean)
Test 8: Requests per second:    3611.41 [#/sec] (mean)
Test 9: Requests per second:    3088.80 [#/sec] (mean)
Test 10: Requests per second:    3299.46 [#/sec] (mean)

この結果だとdockerのほうが良い感じの結果になってます。qemuの実行方法やvm環境で動くカーネルも違うので一概にはどっちが良いとか言えない面もありすね。

runtime.jsのqemuコマンドライン

masami   19666 28.3  0.2 1110156 139224 pts/1  Sl+  14:20   0:01 qemu-system-x86_64 -m 512 -smp 1 -s -kernel /home/masami/.runtime/runtime.2064 -initrd .initrd -net nic,model=virtio,macaddr=1a:46:0b:ca:bc:7c -net user,net=192.168.76.0/24,dhcpstart=192.168.76.9,hostfwd=udp::9000-:9000,hostfwd=tcp::9000-:9000 -nographic -monitor none -enable-kvm -no-kvm-irqchip -serial stdio

virt-managerのほうのqemuコマンドライン

qemu     11627  0.9  1.4 10844960 974920 ?     Sl   12:43   0:52 /usr/bin/qemu-system-x86_64 -machine accel=kvm -name guest=fedora-labo,debug-threads=on -S -object secret,id=masterKey0,format=raw,file=/var/lib/libvirt/qemu/domain-1-fedora-labo/master-key.aes -machine pc-i440fx-2.7,accel=kvm,usb=off,vmport=off,dump-guest-core=off -cpu Haswell-noTSX-IBRS,vme=on,ss=on,vmx=on,f16c=on,rdrand=on,hypervisor=on,arat=on,tsc_adjust=on,ssbd=on,xsaveopt=on,pdpe1gb=on,abm=on -m 8192 -realtime mlock=off -smp 1,sockets=1,cores=1,threads=1 -uuid 239af4a6-ef28-4fa8-aacb-13b2588b0c21 -no-user-config -nodefaults -chardev socket,id=charmonitor,path=/var/lib/libvirt/qemu/domain-1-fedora-labo/monitor.sock,server,nowait -mon chardev=charmonitor,id=monitor,mode=control -rtc base=utc,driftfix=slew -global kvm-pit.lost_tick_policy=delay -no-hpet -no-shutdown -global PIIX4_PM.disable_s3=1 -global PIIX4_PM.disable_s4=1 -boot strict=on -device ich9-usb-ehci1,id=usb,bus=pci.0,addr=0x6.0x7 -device ich9-usb-uhci1,masterbus=usb.0,firstport=0,bus=pci.0,multifunction=on,addr=0x6 -device ich9-usb-uhci2,masterbus=usb.0,firstport=2,bus=pci.0,addr=0x6.0x1 -device ich9-usb-uhci3,masterbus=usb.0,firstport=4,bus=pci.0,addr=0x6.0x2 -device virtio-serial-pci,id=virtio-serial0,bus=pci.0,addr=0x5 -drive file=/var/lib/libvirt/images/fedora-labo.qcow2,format=qcow2,if=none,id=drive-virtio-disk0 -device virtio-blk-pci,scsi=off,bus=pci.0,addr=0x7,drive=drive-virtio-disk0,id=virtio-disk0,bootindex=1 -drive if=none,id=drive-ide0-0-0,readonly=on -device ide-cd,bus=ide.0,unit=0,drive=drive-ide0-0-0,id=ide0-0-0 -netdev tap,fd=25,id=hostnet0,vhost=on,vhostfd=27 -device virtio-net-pci,netdev=hostnet0,id=net0,mac=52:54:00:95:01:e7,bus=pci.0,addr=0x3 -chardev pty,id=charserial0 -device isa-serial,chardev=charserial0,id=serial0 -chardev socket,id=charchannel0,path=/var/lib/libvirt/qemu/channel/target/domain-1-fedora-labo/org.qemu.guest_agent.0,server,nowait -device virtserialport,bus=virtio-serial0.0,nr=1,chardev=charchannel0,id=channel0,name=org.qemu.guest_agent.0 -chardev spicevmc,id=charchannel1,name=vdagent -device virtserialport,bus=virtio-serial0.0,nr=2,chardev=charchannel1,id=channel1,name=com.redhat.spice.0 -device usb-tablet,id=input0,bus=usb.0,port=1 -spice port=5900,addr=127.0.0.1,disable-ticketing,image-compression=off,seamless-migration=on -device qxl-vga,id=video0,ram_size=67108864,vram_size=67108864,vram64_size_mb=0,vgamem_mb=16,max_outputs=1,bus=pci.0,addr=0x2 -device intel-hda,id=sound0,bus=pci.0,addr=0x4 -device hda-duplex,id=sound0-codec0,bus=sound0.0,cad=0 -chardev spicevmc,id=charredir0,name=usbredir -device usb-redir,chardev=charredir0,id=redir0,bus=usb.0,port=2 -chardev spicevmc,id=charredir1,name=usbredir -device usb-redir,chardev=charredir1,id=redir1,bus=usb.0,port=3 -device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x8 -msg timestamp=on

runtime.jsのほうはqemuのオプションを調整することで結果がよくなるかも?

以下はめも runtime.jsは--kvmオプションを使わないとkvmが有効になりません。--nographicオプションを付けるとqemuGUIは表示しません。

--kernelでqemuに渡すカーネルを渡せるようだけど、initrdも作る必要ありそう。

( ´ー`)フゥー...

Docker/Kubernetes 実践コンテナ開発入門

Docker/Kubernetes 実践コンテナ開発入門


systemtapでlivepatchする

$
0
0

CVE-2018-14634(Integer overflow in Linux's create_elf_tables function)でRed Hatのbugzillaを見ていて軽減策としてsystemtapでlivepatch的なことをしていて面白いな〜って思ったのでめもです。

環境はFedora 28で、カーネルのバージョンは4.18.9-200です。systemtapを使っているのでkernel-debuginfoパッケージも入れてます。

utsname構造体のnodenameを書き換えてホスト名を変えてみたいと思います。まずは初期状態はこうです。kerntestがnodenameになります。

masami@kerntest:~$ uname -a                                                                                                                                                                                        
Linux kerntest 4.18.9-200.fc28.x86_64 #1 SMP Thu Sep 2002:43:23 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

cのコードでuname(2)を実行するものを作ります。

#include <stdio.h>#include <sys/utsname.h>int main(int argc, char **argv)
{
        struct utsname utsname = { 0 };

        printf("call uname(2) to execute livepatch via systemtap\n");

        if (uname(&utsname)) {
                perror("uname");
                return -1;
        }

        printf("patched nodename: %s\n", utsname.nodename);
        return0;
}

まずはこれを-oオプション無しにコンパイルしてa.outで実行した場合。

masami@kerntest:~$ ./a.out
call uname(2) to execute livepatch via systemtap
patched nodename: kerntest

なにも起きませんね。

次に以下のsystemtapスクリプトを実行します。 uname(2)で呼ばれる__do_sys_newuname()にprobeを設定しています。 このスクリプトの内容としてはuname(2)を実行したプロセス名がdo-livepatchならそのプロセスが所属するuts名前空間に設定されてるnodenameの値を書き換えてます。

#!/usr/bin/env stap


%{
#include <linux/sched.h>#include <linux/string.h>
%}

function set_dummy_uname:long()
%{
        struct task_struct *p = current;
        if (strcmp(p->nsproxy->uts_ns->name.nodename, "livepatched")) {
                if (unlikely(!strcmp(p->comm, "do-livepatch"))) {
                        memset(p->nsproxy->uts_ns->name.nodename, 0, sizeof(p->nsproxy->uts_ns->name.nodename));
                        strcpy(p->nsproxy->uts_ns->name.nodename, "livepatched");
                }
        }

        STAP_RETURN(0);

%}

probe begin {
        printf("start\n")
}


probe kernel.function("__do_sys_newuname") {
        set_dummy_uname()
}

probe end {
        printf("Done\n")
}

上記のコードを実行します。

masami@kerntest:~$ sudo stap -v -g test.stp                                                                                                                                                                       
Pass 1: parsed user script and 474 library scripts using 157272virt/50300res/8740shr/41432data kb, in 90usr/20sys/106real ms.                                                                                     
Pass 2: analyzed script: 3 probes, 1 function, 1 embed, 0 globals using 211816virt/105600res/9628shr/95976data kb, in 750usr/30sys/777real ms.                                                                    
Pass 3: translated to C into "/tmp/stapmurOiN/stap_134d2448e08da1a0409648297476fac2_1549_src.c" using 211816virt/105912res/9940shr/95976data kb, in 10usr/0sys/6real ms.                                          
Pass 4: compiled C into "stap_134d2448e08da1a0409648297476fac2_1549.ko" in 1990usr/740sys/2506real ms.
Pass 5: starting run.
start

そして、cコードの方をdo-livepatchという名前のバイナリでコンパイルして実行するとnodenameが書き換えられます。これ以降はuname(2)は変更した名前が返るようになってます。

masami@kerntest:~$ ./do-livepatch 
call uname(2) to execute livepatch via systemtap
patched nodename: livepatched
masami@kerntest:~$ uname -a
Linux livepatched 4.18.9-200.fc28.x86_64 #1 SMP Thu Sep 20 02:43:23 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
masami@kerntest:~$ uname -n
livepatched

今まではすでにログインしてたのでbashプロンプトのほうはホスト名変わってませんが、新規に接続するとホスト名が新しい名前になってます。

masami@saga:~$ ssh kerntest 
Last login: Thu Sep 27 02:05:41 2018 from 192.168.122.1
masami@livepatched:~$ 

というわけで、systemtapでlivepatch的なことをする実験でした( ´ー`)フゥー...

linux: seq_fileの使い方めも

$
0
0

sysfs、debugfs、procfs等でファイルを作ってユーザーランドからreadするときにseq_file構造体を使う方法が有るけど使ったことなかったのでめもです。

コード

こんな感じです。

#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt#include <linux/module.h>#include <linux/kernel.h>#include <linux/string.h>#include <linux/fs.h>#include <linux/debugfs.h>#include <linux/seq_file.h>

MODULE_DESCRIPTION("seq file test");
MODULE_AUTHOR("masami256");
MODULE_LICENSE("GPL");

#define SEQ_FILE_TEST_DATA_ARRAY_SIZE 8struct seq_file_test_data {
    char s[16];
};

staticstruct seq_file_test_data data_array[SEQ_FILE_TEST_DATA_ARRAY_SIZE];

staticstruct dentry *seq_file_test_file;

staticvoid *seq_file_get_next_pos(loff_t *pos)
{
    if (*pos > SEQ_FILE_TEST_DATA_ARRAY_SIZE)
        returnNULL;

    return data_array + *pos;
}

staticvoid *seq_file_test_start(struct seq_file *m, loff_t *pos)
{
    return seq_file_get_next_pos(pos);
}

staticvoid seq_file_test_stop(struct seq_file *m, void *v)
{
}

staticvoid *seq_file_test_next(struct seq_file *m, void *v, loff_t *pos)
{
    (*pos)++;

    return seq_file_get_next_pos(pos);
}

staticint seq_file_test_show(struct seq_file *m, void *v)
{
    struct seq_file_test_data *p = v;

    seq_printf(m, "%s", p->s);
    return0;
}

staticstruct seq_operations seq_file_test_seq_ops = {
    .start = seq_file_test_start,
    .stop = seq_file_test_stop,
    .next = seq_file_test_next,
    .show = seq_file_test_show,
};

staticint seq_file_test_open(struct inode *inode, struct file *file)
{
    return seq_open(file, &seq_file_test_seq_ops);
}

staticstruct file_operations seq_file_test_fops = {
    .owner = THIS_MODULE,
    .open = seq_file_test_open,
    .read = seq_read,
    .llseek = seq_lseek,
    .release = seq_release,
};

staticint seq_file_test_init(void)
{
    int i;
    pr_info("%s start\n", __func__);

    for (i = 0; i < SEQ_FILE_TEST_DATA_ARRAY_SIZE; i++) {
        struct seq_file_test_data *p = &data_array[i];
        sprintf(p->s, "test data %d\n", i);
    }

    seq_file_test_file = debugfs_create_file("seq_file_test", 0444,
                        NULL, NULL,
                        &seq_file_test_fops);

    if (IS_ERR(seq_file_test_file))
        return PTR_ERR(seq_file_test_file);

    return0;
}

staticvoid seq_file_test_exit(void)
{
    pr_info("%s bye\n", __func__);
    debugfs_remove(seq_file_test_file);
}

module_init(seq_file_test_init);
module_exit(seq_file_test_exit);

実行例

masami@kerntest:~/seq_file_test$ sudo cat /sys/kernel/debug/seq_file_test
test data 0
test data 1
test data 2
test data 3
test data 4
test data 5
test data 6
test data 7
masami@kerntest:~/seq_file_test$

動作の概要

seq_file構造体はinclude/linux/seq_file.hでこんな感じで定義されてます。

struct seq_operations {
    void * (*start) (struct seq_file *m, loff_t *pos);
    void (*stop) (struct seq_file *m, void *v);
    void * (*next) (struct seq_file *m, void *v, loff_t *pos);
    int (*show) (struct seq_file *m, void *v);
};

show()がデータを表示するための関数です。start()がファイル読み込み時に呼ばれて、データがあればデータのポインタを返します。続いてnext()が呼ばれていってNULLが返るまでは処理が続く感じです。 show()のほうは引数のvにstart()とかnext()で返したポインタが渡ってきます。なのでseq_file_test_show()ではseq_printf()で一つのデータの内容を表示させてるだけなのにcatはちゃんとすべてのデータが読めるってことですね。 ファイルを作成したときはfile_operations構造体でファイルのopen、readなどの関数を設定しますがseq_file構造体を使ってreadの処理を行う場合はopen()を行う関数の方でseq_open()を呼びます。seq_open()に渡すのはfile_operations構造体のopen()に渡されるfile構造体と、seq_file用のseq_operations構造体です。

分かってみればそんなに難しいことはないのでこれからは利用していきたいですね( ´∀`)bグッ!

fedoraでdockerを使ってaarch64のクロスビルド環境を作る

$
0
0

qemuのstaticなバイナリとbinfmt_miscを使ってdockerでクロスビルド環境を作ってみます。

今回作ったものはこちらに置きました。

github.com

環境

HostはFedora 29で、arm64v8/fedoraにあるaarch 64のFedora 28(2018/10/11時点でのlatestはfedora 28です)。このイメージはオフィシャルなものです。

qemu

qemuのパッケージで必要なのは qemu-user-static です。これをサクッとインストールしましょう。

binfmt_misc

つぎにbinfmt_miscの設定が必要なんですが、fedoraの場合systemdのproc-sys-fs-binfmt_misc.mountが動いてればOKです。自分の場合はインストールした後に所要で再起動したのですが、restartとかすれば良い気がします。

masami@saga:~$ systemctl status proc-sys-fs-binfmt_misc.mount
● proc-sys-fs-binfmt_misc.mount - Arbitrary Executable File Formats File System
   Loaded: loaded (/usr/lib/systemd/system/proc-sys-fs-binfmt_misc.mount; static; vendor preset: disabled)
   Active: active (mounted) since Thu 2018-10-11 20:07:16 JST; 2h 2min ago
    Where: /proc/sys/fs/binfmt_misc
     What: binfmt_misc
     Docs: https://www.kernel.org/doc/html/latest/admin-guide/binfmt-misc.html
           https://www.freedesktop.org/wiki/Software/systemd/APIFileSystems
    Tasks: 0 (limit: 4915)
   Memory: 60.0K
   CGroup: /system.slice/proc-sys-fs-binfmt_misc.mount

Oct 11 20:07:16 saga systemd[1]: Mounting Arbitrary Executable File Formats File System...
Oct 11 20:07:16 saga systemd[1]: Mounted Arbitrary Executable File Formats File System.

/proc/sys/fs/binfmt_miscを手動で設定するときはELFバイナリのシグネチャとかを自分で設定しないといけないんですが、proc-sys-fs-binfmt_misc.mountが上手いことやってくれてるようです。/proc/sys/fs/binfmt_misc/が↓のようになっていれば設定完了です。

masami@saga:~$ ls /proc/sys/fs/binfmt_misc/
./            qemu-aarch64_be  qemu-armeb  qemu-microblaze    qemu-mips64    qemu-mipsn32    qemu-ppc      qemu-riscv32  qemu-sh4          qemu-xtensa    status
../           qemu-alpha       qemu-hppa   qemu-microblazeel  qemu-mips64el  qemu-mipsn32el  qemu-ppc64    qemu-riscv64  qemu-sh4eb        qemu-xtensaeb
qemu-aarch64  qemu-arm         qemu-m68k   qemu-mips          qemu-mipsel    qemu-or1k       qemu-ppc64le  qemu-s390x    qemu-sparc32plus  register

docker image

arm64v8/fedoraのイメージを使います。

試しに動作確認をしてたのが以下になります。unameコマンドで表示されるアーキテクチャがaarch64になってますね。

masami@saga:~$ sudo docker pull arm64v8/fedora
Using default tag: latest
Trying to pull repository docker.io/arm64v8/fedora ... 
sha256:a2adc1621935869bcd51a84b007b3ee6aa8aa9aef0bf30a947f7312fd43e5b0b: Pulling from docker.io/arm64v8/fedora
f9afc51fb922: Pull complete 
Digest: sha256:a2adc1621935869bcd51a84b007b3ee6aa8aa9aef0bf30a947f7312fd43e5b0b
Status: Downloaded newer image for docker.io/arm64v8/fedora:latest
masami@saga:~$ sudo docker image ls
REPOSITORY                 TAG                 IMAGE ID            CREATED             SIZE
docker.io/arm64v8/fedora   latest              95cddd448075        4 weeks ago         290 MB
runtimejstest_web          latest              5cf57ccadd2f        4 weeks ago         675 MB
docker.io/node             8                   8198006b2b57        5 weeks ago         673 MB
docker.io/amazonlinux      latest              585cc50169e6        3 months ago        163 MB
alpine                     latest              3fd9065eaf02        9 months ago        4.15 MB
masami@saga:~$ sudo docker run -it docker.io/arm64v8/fedora /bin/bash
[root@54034b092275 /]# uname -a
Linux 54034b092275 4.19.0-rc7-test+ #102 SMP Mon Oct 8 11:06:09 JST 2018 aarch64 aarch64 aarch64 GNU/Linux

ホストでunameコマンド使ったらx86_64となります。

masami@saga:~$ uname -a
Linux saga 4.19.0-rc7-test+ #102 SMP Mon Oct 8 11:06:09 JST 2018 x86_64 x86_64 x86_64 GNU/Linux

クロスビルド環境の作成

では、本題のクロスビルド環境を作ってみます。今回はソースはホストで編集し、docker-compose upでmakeとmake testを動かすようにします。ソースはDockerfileが有るディレクトリにsrc/というディレクトリを作ってそこに置きましょう。

Dockerfileはこうなります。とりあえずCMDでmakeしないでbashを起動させるだけにします。

FROM docker.io/arm64v8/fedora

RUN mkdir /src && \
dnf install -y gcc make file

WORKDIR /src

CMD /bin/bash

docker-compose.ymlはこうなります。selinuxが有効なのでvolumesの時にzオプションを付けています。commandのところでCMDを上書きしてmakeコマンドを実行するようにしました。

version: '3'

services:
  builder:
    build: .
    image: aarch64-cross-builder
    hostname: fedora-aarch64
    volumes:
      - ./src:/src:z
    command: make all

実行

masami@saga:~/codes/arm-cross-build$ sudo docker-compose up
Creating arm-cross-build_builder_1 ... done
Attaching to arm-cross-build_builder_1
builder_1  | rm -f hello
builder_1  | cc hello.c -o hello
builder_1  | file ./hello
builder_1  | ./hello: ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-aarch64.so.1, for GNU/Linux 3.7.0, BuildID[sha1]=39cbef1ba26dcae61413b891b9bd4e9d202a5083, not stripped
builder_1  | ./hello
builder_1  | Hello, World
arm-cross-build_builder_1 exited with code 0

まとめ

Fedora 29ならかなり簡単にクロスビルド環境を作ることが出来ますね( ´∀`)bグッ! qemuで完全なエミュレーションをしてももちろんOKですが、ユーザーランドのアプリならdockerでも良さげですね。

( ´ー`)フゥー...

ARMで学ぶ アセンブリ言語入門

ARMで学ぶ アセンブリ言語入門

When kallsyms doesn't show addresses even though kptr_restrict is 0

$
0
0

When I did grep kernel symbol address, addresses were all zero.

masami@saga:~$ grep slab_alloc /proc/kallsyms 
0000000000000000 t ___slab_alloc
0000000000000000 t __slab_alloc

So, I checked kptr_restrict if it's not zero.

masami@saga:~$ sudo sysctl kernel.kptr_restrict
kernel.kptr_restrict = 0

Um, kptr_restrict was already zero. By the way, how about kernel config that enables KALLSYMS ? Current kernel version is here.

masami@saga:~$ uname -a
Linux saga 4.18.13-300.fc29.x86_64 #1 SMP Wed Oct 10 17:22:50 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

So, in /boot there is kernel configs that I could check it.

masami@saga:~$ grep -i kallsyms /boot/config-4.18.13-300.fc29.x86_64
CONFIG_KALLSYMS=y
CONFIG_KALLSYMS_ALL=y
CONFIG_KALLSYMS_ABSOLUTE_PERCPU=y
CONFIG_KALLSYMS_BASE_RELATIVE=y

Ok, KALLSYMS is enabled. But how come I couldn't get addresses? Let's check kernel functions.

When you open /proc/kallsyms, kallsyms_show_value() is called. In my case, kptr_restrict is 0, so kallsyms_for_perf() is called.

int kallsyms_show_value(void)
{
    switch (kptr_restrict) {
    case0:
        if (kallsyms_for_perf())
            return1;
    /* fallthrough */case1:
        if (has_capability_noaudit(current, CAP_SYSLOG))
            return1;
    /* fallthrough */default:
        return0;
    }
}

kallsyms_for_perf() is following simple function.

staticinlineint kallsyms_for_perf(void)
{
#ifdef CONFIG_PERF_EVENTSexternint sysctl_perf_event_paranoid;
    if (sysctl_perf_event_paranoid <= 1)
        return1;
#endifreturn0;
}

As you can see, thee is #ifdef macro. so, check CONFIG_PERF_EVENTS in kernel config.

masami@saga:~$ grep CONFIG_PERF_EVENTS /boot/config-4.18.13-300.fc29.x86_64
CONFIG_PERF_EVENTS=y
CONFIG_PERF_EVENTS_INTEL_UNCORE=m
CONFIG_PERF_EVENTS_INTEL_RAPL=m
CONFIG_PERF_EVENTS_INTEL_CSTATE=m
CONFIG_PERF_EVENTS_AMD_POWER=m

Ok, if perf_event_paranoid is less than or equal to 1, it returns 1, otherwise return 0. Let's check perf_event_paranoid.

masami@saga:~$ sudo sysctl kernel.perf_event_paranoid
kernel.perf_event_paranoid = 2

Ah, I got it. However, what value can I use for? According to Documentation/sysctl/kernel.txt, there is a paragraph that describes perf_event_paranoid values. Maybe 1 is okay for me now.

masami@saga:~$ sudo sysctl -w kernel.perf_event_paranoid=1
kernel.perf_event_paranoid = 1

Then check symbols again.

masami@saga:~$ grep slab_alloc /proc/kallsyms 
ffffffff96272150 t ___slab_alloc
ffffffff96272790 t __slab_alloc

got it :)

Understanding the Linux Kernel: From I/O Ports to Process Management

Understanding the Linux Kernel: From I/O Ports to Process Management

virt-managerでarmのゲストを動かすメモ

$
0
0

忘れないようにメモっとこうという程度なので大したことはしてないです。

aarch64やarmhfpのイメージはIndex of /pub/Linux/Fedora/releasesから取得したとします。

qemuのバージョン

ホストはx86_64なFedora 29で、qemuは3.0.0になります。

masami@saga:~/arm/aarch64$ rpm -qa  | grep qemu-system
qemu-system-arm-core-3.0.0-1.fc29.x86_64
qemu-system-x86-3.0.0-1.fc29.x86_64
qemu-system-x86-core-3.0.0-1.fc29.x86_64
qemu-system-aarch64-core-3.0.0-1.fc29.x86_64
qemu-system-arm-3.0.0-1.fc29.x86_64
qemu-system-aarch64-3.0.0-1.fc29.x86_64

あとこの辺も必要かと思います。

masami@saga:~/arm/aarch64$ rpm -qa | grep edk2
edk2-aarch64-20180815gitcb5f4f45ce-1.fc29.noarch
edk2-ovmf-20180815gitcb5f4f45ce-1.fc29.noarch

aarch64

イメージはxz形式で圧縮されているのでまずは展開します。

masami@saga:~/arm/aarch64$ xz -dc Fedora-Server-28-1.1.aarch64.raw.xz  > Fedora-Server-28-1.1.aarch64.raw

そして、カーネルやコマンド諸々込みのファイルができるのですが、これをそのまま使ってもログイン可能なユーザーもいないし、rootログインできないのでまずはrootのパスワードを設定します。ここでは virt-customizeというコマンドを使います。これはlibguestfs-toolsってパッケージをインストールすると使えます。

masami@saga:~/arm/aarch64$ virt-customize --root-password file:./rootpw.txt -a Fedora-Server-28-1.1.aarch64.raw
[   0.0] Examining the guest ...
[  16.3] Setting a random seed
[  16.4] Setting the machine ID in /etc/machine-id
[  16.4] Setting passwords
[  17.7] Finishing off

このコマンドのオプションが見たままですがrootのパスワードを設定しています。パスワードはrootpw.txtってファイルに書いてます。このファイルの1行目に平文でパスワードを記述します。このコマンドでユーザー作ったりも出来ます。 それはともかく、これでrootログインできるようになったので後はvirt-installでインストールします。

ディスクイメージを/var/lib/libvirt/imagesに置き、以下のような感じでインストールします。これが最低限なコマンドラインオプションかと思います。

masami@saga:~/arm/aarch64$ sudo virt-install --name fedora28-aarch64 --ram 4096 --arch aarch64 --import --os-variant fedora22 --disk /var/lib/libvirt/images/Fedora-Server-28-1.1.aarch64.raw --boot uefi

armhfp版との違いとして--bootでufeiを指定してるというのがあります。armhfpの場合だとvmlinuzとかinitrdの指定があります。

あとはしばらく待っていればログインプロンプトが表示されるのでidをroot、パスワードは先程設定したものを入力すればログインできます(∩´∀`)∩ワーイ

[  OK  ] Started Update UTMP about System Runlevel Changes.

Fedora 28 (Server Edition)
Kernel 4.16.3-301.fc28.aarch64 on an aarch64 (ttyAMA0)

Admin Console: https://192.168.122.223:9090/ or https://[fe80::27d2:fdd6:dc02:4ab]:9090/

localhost login: root
Password:
[root@localhost ~]# uname -a
Linux localhost.localdomain 4.16.3-301.fc28.aarch64 #1 SMP Mon Apr 23 21:45:59 UTC 2018 aarch64 aarch64 aarch64 GNU/Linux  

また、サーバ版はCockpitが動いているのでAdmin Console: ~と書かれているURLにブラウザでアクセスすればブラウザからでも端末エミュレータが使えます。

f:id:masami256:20181106220907p:plain

armhfp

aarch64とも多少違うのでこちらもメモしておきます。基本的にはArchitectures/ARM/F28/Installation - Fedora Project Wikiの手順に沿えば良いのですが、qemuのバージョンが3.0.0の場合(今後はわかりません)はwikiの手順だけだとBug 1633328 – Armv7 guest fails to boot with qemu-3.0.0-1に書かれているように以下のようなワーニングが出てインストール完了しません。

[   51.049803] audit: type=1130 audit(1541508483.457:11): pid=1 uid=0 auid=4294967295 ses=4294967295 subj=kernel msg='unit=systemd-tmpfiles-setup comm="systemd" exe="/usr/lib/systemd/systemd" hostname=? addr=? terminal=? res=success'
[  OK  ] Reached target System Initialization.
[  OK  ] Reached target Basic System.
[  371.409670] dracut-initqueue[338]: Warning: dracut-initqueue timeout - starting timeout scripts
[  373.553982] dracut-initqueue[338]: Warning: dracut-initqueue timeout - starting timeout scripts
[  374.886815] dracut-initqueue[338]: Warning: dracut-initqueue timeout - starting timeout scripts
[  376.308904] dracut-initqueue[338]: Warning: dracut-initqueue timeout - starting timeout scripts
[  377.638877] dracut-initqueue[338]: Warning: dracut-initqueue timeout - starting timeout scripts

そのため、commentの14に書かれているようにvirt-install--qemu-commandline='-machine highmem=offというオプションを追加します。よって、virt-installコマンドラインはこんなふうになります。

sudo virt-install --name fedora28-armhfp --ram 1024 --arch armv7l \
  --import --os-variant fedora22 \
  --disk /var/lib/libvirt/images/Fedora-Minimal-armhfp-28-1.1-sda.raw \
  --boot kernel=/var/lib/libvirt/images/vmlinuz-4.16.3-301.fc28.armv7hl,initrd=/var/lib/libvirt/images/initramfs-4.16.3-301.fc28.armv7hl.img,kernel_args="console=ttyAMA0 rw root=LABEL=_/ rootwait" --qemu-commandline='-machine highmem=off'

こちらもvirt-installの前にvirt-customizeでrootのパスワードを設定しておく必要があります。

ゲストへの接続

普通にvirsh console ゲスト名で接続できます。

その他

armhfpのほうはhighmem=offなどの設定が必要なのが注意事項ですね ( ´ー`)フゥー...

ARMで学ぶ アセンブリ言語入門

ARMで学ぶ アセンブリ言語入門

libbfdのめも

$
0
0

libbfdの使い方のめもです。利用してるバージョンはbinutils-devel-2.31.1-13.fc29.x86_64です。

nmもどき

アドレスとセクション名、それにdebug情報があればファイル名と行数を表示。連想配列が使いたかったのでヘッダファイルだけで実装されてるuthashというライブラリを使ってます。

simple_nm.c

#include <stdio.h>#include <stdlib.h>#include <string.h>#include <bfd.h>#include "uthash.h"struct section_info {
    char name[64];
    unsignedlong vma;
    UT_hash_handle hh;
};

staticstruct section_info *sections_info = NULL;

staticvoid delete_all_hash_values(void)
{
    struct section_info *pos, *tmp;

    HASH_ITER(hh, sections_info, pos, tmp) {
        HASH_DEL(sections_info, pos);
        free(pos);
    }

    HASH_CLEAR(hh, sections_info);
}

staticstruct section_info *add_section(bfd *abfd, constchar *sname)
{
    struct section_info *info;

    asection *section = bfd_get_section_by_name(abfd, sname);
    if (!section)
        returnNULL;

    info = malloc(sizeof(*info));
    if (!info) {
        fprintf(stderr, "malloc failed\n");
        exit(-1);
    }
    memset(info, 0x0, sizeof(*info));

    strcpy(info->name, sname);
    info->vma = section->vma;

    HASH_ADD_STR(sections_info, name, info);

    return info;
}

staticstruct section_info *get_section_info(bfd *abfd, constchar *sname)
{
    struct section_info *info = NULL;

    HASH_FIND_STR(sections_info, sname, info);
    if (info)
        return info;

    return add_section(abfd, sname);
}

staticvoid show_function_info(bfd *abfd, asection *debug_info, asymbol **symbols, int idx)
{
    constchar *file, *func;
    unsignedint line;
    constchar *sname = symbols[idx]->section->name;
    constchar *name = symbols[idx]->name;
    struct section_info *info = get_section_info(abfd, sname);

    if (!info)
        return ;

    unsignedlong addr = symbols[idx]->value + info->vma;
    if (bfd_find_nearest_line(abfd, debug_info, symbols, addr, &file, &func, &line))
        printf("0x%lx%s%s%s:%u\n", addr, sname, name, file, line);
    else
        printf("0x%lx%s%s\n", addr, sname, name);
}

staticvoid show(char *prog)
{
    bfd *abfd;
    asection *debug_info;
    size_t nsyms;
    asymbol **symbols;
    int ret;

    bfd_init();

    abfd = bfd_openr(prog, NULL);
    if (!abfd) {
        fprintf(stderr, "failed to open %s\n", prog);
        exit(-1);
    }

    ret = bfd_check_format(abfd, bfd_object);
    if (!ret) {
        fprintf(stderr, "invalid object format\n");
        exit(-1);
    }

    debug_info = bfd_get_section_by_name(abfd, ".debug_info");

    symbols = malloc(bfd_get_symtab_upper_bound(abfd));
    if (!symbols) {
        fprintf(stderr, "malloc failed\n");
        exit(-1);
    }

    nsyms = bfd_canonicalize_symtab(abfd, symbols);

    for (int i = 0; i < nsyms; i++)
        show_function_info(abfd, debug_info, symbols, i);

    delete_all_hash_values();
    free(symbols);
    bfd_close(abfd);
}

int main(int argc, char **argv)
{
    if (argc != 2) {
        fprintf(stderr, "usage: %s<file>\n", argv[0]);
        exit(-1);
    }

    show(argv[1]);
    return0;
}

Makefile

objs=simple_nm.o

prog=simple_nm

all:$(objs)$(CC) -O0 -g $(objs) -o $(prog) -lbfd.c.o:$(CC) -O0 -I. -g -c -Wall $<test:  ./$(prog)$(prog)clean:  rm -f core* $(objs)$(prog)

実行例

0xffffffff829e0018 .bss panic_param
0xffffffff827347e3 .init.text unknown_bootoption /home/masami/linux-kernel/init/main.c:294
0xffffffff81002010 .text trace_initcall_finish_cb /home/masami/linux-kernel/init/main.c:841
0xffffffff810028e3 .text trace_initcall_start_cb /home/masami/linux-kernel/init/main.c:832
0xffffffff81002911 .text run_init_process /home/masami/linux-kernel/init/main.c:1011
0xffffffff8100294f .text try_to_run_init_process /home/masami/linux-kernel/init/main.c:1020
0xffffffff82734977 .init.text trace_event_define_fields_initcall_level /home/masami/linux-kernel/./include/trace/events/initcall.h:10
0xffffffff8273499f .init.text trace_event_define_fields_initcall_start /home/masami/linux-kernel/./include/trace/events/initcall.h:27
0xffffffff827349c4 .init.text trace_event_define_fields_initcall_finish /home/masami/linux-kernel/./include/trace/events/initcall.h:48
0xffffffff81002050 .text perf_trace_initcall_start /home/masami/linux-kernel/./include/trace/events/initcall.h:27
0xffffffff81002120 .text perf_trace_initcall_finish /home/masami/linux-kernel/./include/trace/events/initcall.h:48
0xffffffff81002200 .text trace_raw_output_initcall_level /home/masami/linux-kernel/./include/trace/events/initcall.h:10
0xffffffff81002250 .text trace_raw_output_initcall_start /home/masami/linux-kernel/./include/trace/events/initcall.h:27
0xffffffff81002290 .text trace_raw_output_initcall_finish /home/masami/linux-kernel/./include/trace/events/initcall.h:48
0xffffffff810022e0 .text __bpf_trace_initcall_level /home/masami/linux-kernel/./include/trace/events/initcall.h:10
0xffffffff810022f0 .text __bpf_trace_initcall_start /home/masami/linux-kernel/./include/trace/events/initcall.h:27
0xffffffff81002300 .text __bpf_trace_initcall_finish /home/masami/linux-kernel/./include/trace/events/initcall.h:48
0xffffffff82734a1c .init.text loglevel /home/masami/linux-kernel/init/main.c:230
0xffffffff81002310 .text initcall_blacklisted /home/masami/linux-kernel/init/main.c:790
0xffffffff82213020 .data blacklisted_initcalls
0xffffffff82329a50 .data descriptor.60757
0xffffffff82734a77 .init.text set_debug_rodata /home/masami/linux-kernel/ini

ptrace(2)で呼び出す関数を動的に変更

bfdで関数のアドレスを調べてptrace(2)でブレークポイントを設定して、ブレークポイントにきたらripを呼び出したい関数に変えて本来の関数は実行しない形。inline化されてるものには対応してませんけども。。

simple_break_point.c

#include <stdio.h>#include <stdlib.h>#include <string.h>#include <unistd.h>#include <sys/types.h>#include <sys/ptrace.h>#include <sys/wait.h>#include <sys/user.h>#include <assert.h>#include <bfd.h>staticvoid stub_function(void)
{
    printf("stub function is called\n");
}

staticvoid say_hello(void)
{
    printf("hello, world\n");
}

void *get_function_address(char *prog_name, char *func_name)
{
    bfd *abfd;
    asection *text;
    size_t nsyms;
    asymbol **symbols;
    void *addr = NULL;
    int ret;

    bfd_init();

    abfd = bfd_openr(prog_name, NULL);
    assert(abfd != NULL);

    ret = bfd_check_format(abfd, bfd_object);
    assert(ret != 0);

    text = bfd_get_section_by_name(abfd, ".text");

    symbols = malloc(bfd_get_symtab_upper_bound(abfd));
    assert(symbols != NULL);

    nsyms = bfd_canonicalize_symtab(abfd, symbols);

    for (int i = 0; i < nsyms; i++) {
        if (!strcmp(symbols[i]->name, func_name)) {
            addr = (void *) (symbols[i]->value + text->vma);
            break;
        }
    }

    free(symbols);
    bfd_close(abfd);

    return addr;
}

int main(int argc, char **argv)
{
    pid_t pid;
    long ret;
    void *addr;

    if (argc != 2) {
        printf("usage: %s<function name>\n", argv[0]);
        exit(-1);
    }

    addr = get_function_address(argv[0], argv[1]);
    if (!addr) {
        printf("function %s is not found\n", argv[1]);
        exit(-1);
    }

    pid = fork();
    assert(pid >=  0);

    if (!pid) {
        say_hello();
    } else {
        int status;
        void *break_point;
        long orig_text;

        ret = ptrace(PTRACE_ATTACH, pid, NULL, NULL);
        assert(ret != -1);
        waitpid(pid, &status, 0);

        orig_text = ptrace(PTRACE_PEEKTEXT, pid, addr, NULL);
        break_point = (void *) (unsignedlong) (orig_text | 0xcc);
        ret = ptrace(PTRACE_POKETEXT, pid, addr, break_point);
        assert(pid != -1);

        printf("[*] set break point at %p\n", addr);

        ret = ptrace(PTRACE_CONT, pid, NULL, NULL);
        assert(pid != -1);

        waitpid(pid, &status, 0);

        if (WIFEXITED(status)) {
            printf("program normally finishd\n");
            exit(0);
        } elseif (WIFSTOPPED(status)) {
            struct user_regs_struct regs = { 0 };
            ret = ptrace(PTRACE_GETREGS, pid, 0, &regs);
            assert(ret != -1);
            regs.rip = (unsignedlonglong) stub_function;

            ret = ptrace(PTRACE_SETREGS, pid, 0, &regs);
            assert(ret != -1);

            ret = ptrace(PTRACE_CONT, pid, NULL, NULL);
            assert(pid != -1);
        } else {
            printf("unkown error\n");
            exit(-1);
        }
    }

    return0;
}

Makefile

objs=simple_break_point.o

prog=simple_break_point

all:$(objs)$(CC) -O0 -g $(objs) -o $(prog) -lbfd.c.o:$(CC) -O0 -g -c -Wall $<test:  ./$(prog) say_helloclean:  rm -f core* $(objs)$(prog)

実行例

ここでブレークポイントを設定する関数のアドレスはnmで見るとこうなってます。

masami@saga:~/codes/simple_break_point$ nm ./simple_break_point | grep "say_hello\|main"
                 U __libc_start_main@@GLIBC_2.2.5
0000000000402a69 T main
00000000004028c7 t say_hello
ブレークポイントにヒットする場合
masami@saga:~/codes/simple_break_point$ ./simple_break_point say_hello
[*] set break point at 0x4028c7
stub function is called
ブレークポイントにヒットしない場合

すでに実行されたmain()に設定することでブレークポイントにヒットしない感じで。

mi@saga:~/codes/simple_break_point$ ./simple_break_point main
[*] set break point at 0x402a69
hello, world
program normally finishd

Linuxでプロセス単位にaslrのon/offを切り替える仕組みめも

$
0
0

gdb turns off ASLR « codeblogを見ていてpersonality(2)を使えば良いのか〜と知ったのでめもです。

tl;dr

personality(2)でADDR_NO_RANDOMIZEをセットすればoffにできる。

personality(2)

aslr以外にも設定可能な項目はいくつか有ります。設定されている内容を見るだけなら /proc/<pid>/personalityを読んで調べることができます。

テストコード

とりあえずこんな感じのコードを。

#include <stdio.h>#include <string.h>#include <stdlib.h>#include <unistd.h>#include <sys/types.h>#include <sys/wait.h>#include <sys/personality.h>staticvoid show_pointer_address(void)
{
    int n;

    printf("[*] local variable address is %p\n", &n);
}

staticvoid show_current_persona(void)
{
    int persona = personality(0xffffffff);
    printf("[*]current setting is 0x%x\n", persona);
}

int main(int argc, char **argv)
{
    show_current_persona();

    if (argc == 2&& !strcmp(argv[1], "show")) {
        show_pointer_address();
        return0;
    } elseif (argc == 2&& !strcmp(argv[1], "no_aslr")) {
        printf("[*]set aslr off\n");
        personality(ADDR_NO_RANDOMIZE);
    }

    pid_t pid = fork();

    if (pid < 0) {
        perror("fork");
        exit(-1);
    }

    if (!pid) {
        execl(argv[0], argv[0], "show",  NULL);
    } else {
        int status;
        waitpid(pid, &status, 0);
    }

    return0;
}

動かしてみる

aslrを無効にしない場合

masami@saga:~/codes/personality_test$ for((i=0;i<10;i++)); do ./a.out ; done | grep local
[*] local variable address is 0x7fffa4082aac
[*] local variable address is 0x7ffc06ed6a4c
[*] local variable address is 0x7fff8bc1fbac
[*] local variable address is 0x7ffdd78eb9dc
[*] local variable address is 0x7ffe2c88ed3c
[*] local variable address is 0x7ffd32bde89c
[*] local variable address is 0x7fffa323205c
[*] local variable address is 0x7ffd22dc153c
[*] local variable address is 0x7ffe5613520c
[*] local variable address is 0x7ffdee4e8dec

aslrを無効にした場合

masami@saga:~/codes/personality_test$ for((i=0;i<10;i++)); do ./a.out no_aslr; done | grep local
[*] local variable address is 0x7fffffffd2dc
[*] local variable address is 0x7fffffffd2dc
[*] local variable address is 0x7fffffffd2dc
[*] local variable address is 0x7fffffffd2dc
[*] local variable address is 0x7fffffffd2dc
[*] local variable address is 0x7fffffffd2dc
[*] local variable address is 0x7fffffffd2dc
[*] local variable address is 0x7fffffffd2dc
[*] local variable address is 0x7fffffffd2dc
[*] local variable address is 0x7fffffffd2dc


Linuxカーネルをgdbでデバッグ(またはディストリビューションのカーネルを使うときは当たってるパッチにも注意しよう)

$
0
0

この記事はLinux Advent Calendar 2018の1日目ですΣ(゚∀゚ノ)ノキャー

イントロ

ほんとは別の内容にしようと思ってたのですが、進めてる途中でカーネルデバッグをするハメになったのでカーネルデバッグをネタにしてみました。カーネルデバッグと言っても普通のデバッグと変わらないよね〜というところがわかると思います。(`・ω・´)<コワクナイヨー

デバッグの環境としてはlibvirt(qemu)で動いてるゲスト環境にホスト側からgdbデバッグする感じです。ディストリビューションFedora 29です。デバッグするカーネルFedoraカーネルで4.19.2-300.fc29.x86_64です。

テストコード

テストコードは↓です。これはdebugfsのディレクトリ(大概は/sys/kernel/debug/だと思います)にopen-testってファイルを作って、そのファイルを読むとhello, world!\nって読めるだけの単純なものです。

#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt#include <linux/module.h>#include <linux/kernel.h>#include <linux/fs.h>#include <linux/debugfs.h>

MODULE_DESCRIPTION("debugfs open test module");
MODULE_AUTHOR("masami266");
MODULE_LICENSE("GPL");

#define OPEN_TEST_FILE "open-test"staticstruct dentry *open_test_file;

staticchar open_test_file_buf[] = "hello, world!\n";

staticssize_t open_test_read(struct file *filp, char __user *buf, size_t len, loff_t *ppos)
{
        pr_info("%s\n", __func__);
        return simple_read_from_buffer(buf, len, ppos, open_test_file_buf, sizeof(open_test_file_buf));
}

staticstruct file_operations open_test_fops = {
        .owner = THIS_MODULE,
        .read = open_test_read,
};

staticint open_test_init(void)
{
        open_test_file = debugfs_create_file(OPEN_TEST_FILE, 0644,
                            NULL, open_test_file_buf,
                            &open_test_fops);

        if (!open_test_file) {
                pr_info("failed to create debugfs file\n");
                return -ENODEV;
        }

        pr_info("open_test module has been initialized\n");
        return0;
}

staticvoid open_test_exit(void)
{
        if (open_test_file)
                debugfs_remove(open_test_file);

        pr_info("good bye\n");
}

module_init(open_test_init);
module_exit(open_test_exit);

Makefileはこうです。

KERNDIR := /lib/modules/`uname -r`/build
BUILD_DIR := $(shell pwd)
VERBOSE = 0

obj-m := open_test.o
smallmod-objs := open_test.o

all:
        make -C $(KERNDIR) SUBDIRS=$(BUILD_DIR) KBUILD_VERBOSE=$(VERBOSE) modules

clean:
        rm -f *.o
        rm -f *.ko
        rm -f *.mod.c
        rm -f *~

実行してみる

これをメインラインのカーネルで実行するとこうなります。予想通りの挙動ですね〜

masami@kerntest:~/open-test$ uname -a
Linux kerntest 4.20.0-rc3-test+ #8 SMP Fri Nov 23 10:15:41 JST 2018 x86_64 x86_64 x86_64 GNU/Linux
masami@kerntest:~/open-test$ sudo insmod ./open_test.ko
masami@kerntest:~/open-test$ sudo cat /sys/kernel/debug/open-test
hello, world!

だがしかし、fedoraカーネルで実行するとエラーになります。。。これをデバッグするのが今回のネタとなります。

masami@kerntest:~/open-test$ uname -a
Linux kerntest 4.19.2-300.fc29.x86_64 #1 SMP Wed Nov 14 19:05:24 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
masami@kerntest:~/open-test$ sudo insmod ./open_test.ko
masami@kerntest:~/open-test$ sudo cat /sys/kernel/debug/open-test
cat: /sys/kernel/debug/open-test: Operation not permitted

デバッグ

状況確認

まずはdmesgを見てみます。

[  155.906829] open_test: loading out-of-tree module taints kernel.
[  155.906874] open_test: module verification failed: signature and/or required key missing - tainting kernel
[  155.907409] open_test: open_test module has been initialized

open_test_read()のpr_info()の部分は実行されていないのがわかります。そしたらstrace(1)を使ってみます。

openat(AT_FDCWD, "/sys/kernel/debug/open-test", O_RDONLY) = -1 EPERM (Operation not permitted)

straceを使うとopenat(2)でEPERMが返ってきてるのがわかります。ファイルをreadするにはopenする必要が有るから当然な感じですね。ということで、ファイルを開く処理のどこかでEPERMが返ってるわけですが、これをコードを読んでいって調べるのは大変なのでgdbでも使いましょう。

configの内容を合わせてみる

メインラインのカーネルも一旦config-4.19.2-300.fc29.x86_64を使ってビルドしてみましたが、問題ありませんでした。ということでコンフィグ的な差分では無いというのがわかりました。

デバッグの準備

gdbで接続するための準備

今回の環境ではlibvirtを使っているのでlibvirtgdbの接続ができるようにします。設定ファイルの変更ですがこれはvrishコマンドでできます。

masami@saga:~$ sudo virsh edit kerntest

エディタが立ち上がって編集可能になるので、まずは先頭の部分を以下のように変えます。

<domain type='kvm' xmlns:qemu='http://libvirt.org/schemas/domain/qemu/1.0'>

そして、一番下にでも以下の行を追加して上書き保存してエディタを終了しましょう。

<qemu:commandline>
    <qemu:arg value='-s'/>
  </qemu:commandline>

基本的にはこれだけでOKなんですが、デバッグされるホストのカーネルのほうでKASLRが有効になっていてリモートデバッグするときにはこのままだと適切な場所にブレークポイントを張ったりができないので、これを無効にする必要があります。詳細はこちらを参照してください。

kernhack.hatenablog.com

KASLRを無効にするのはカーネルコマンドラインでオプションを渡せばできます。起動時に毎回設定するのは面倒なのでgrubのほうでカーネルコマンドラインに追記しましょう。/etc/default/grubというファイルがgrub.cfgを作る時の設定ファイルです。fedoraの場合は以下の行がありますので、

GRUB_CMDLINE_LINUX="rhgb quiet"

こんな感じにします。

GRUB_CMDLINE_LINUX="rhgb quiet nokaslr"

そして、sudo grub2-mkconfig -o /boot/grub2/grub.cfgな感じでgrubの設定ファイルを作り直してから再起動しましょう。 これでtcpポート1234を使ってリモートでバッグできるようになりました。

デバッグ用のvmlinuxとソースの準備

デバッグするのにデバッグシンボルがないと不便ですし、ソースもみたいですよね。ということでこれも用意しましょう。これはgdbを実行するホストのほうで必要になります。 デバッグシンボル付きのvmlinuxはkernel-debuginfoパッケージでインストールすることができます。ホストとゲストで同じfedoraを使ってるならホスト側でsudo dnf debuginfo-install -y kernelを実行しても良いですね。もしくはゲスト側でインストールしてvmlinuxをscp等でダウンロードするのも有りです。vmlinuxが有る場所は以下の場所です。

/usr/lib/debug/lib/modules/4.19.2-300.fc29.x86_64/vmlinux

ソールはkernel-debuginfo-commonパッケージにあります。なのでsudo dnf debuginfo-install -y kernelを実行すればvmlinuxとソースの両方がインストールできます。ソースは以下の場所にインストールされます。

/usr/src/debug/kernel-4.19.fc29/linux-4.19.2-300.fc29.x86_64/

自分はゲストのほうでパッケージをインストールしてvmlinuxとソースコードディレクトリはscpでホスト側に持っていきました。

これでgdbを使う準備は完了です。

gdbで動作を追う

gdbを使うにしてもブレークポイントを設定する場所とかは確認したいので、まずはopenat()を見てみます。

SYSCALL_DEFINE4(openat, int, dfd, constchar __user *, filename, int, flags,
        umode_t, mode)
{
    if (force_o_largefile())
        flags |= O_LARGEFILE;

    return do_sys_open(dfd, filename, flags, mode);
}

do_sys_open()が呼ばれているのでこちらにブレークポイントを張って追いかけていきましょう。しかし、ファイルのオープンは色んな所で行われるため条件付きのブレークポイントにしないと面倒です。引数のfilenameが開きたいファイル名なのでこれを条件にしましょう。組み込み関数の$_streq()を使うと文字列の比較ができます。

gdbを起動するときのソースコードのパスも一緒に指定しました。

masami@saga:~$ gdb --directory=./linux-4.19.2-300.fc29.x86_64/ ./vmlinux  
Reading symbols from ./vmlinux...done.
gdb-peda$ 

そしてリモート接続します。あ、その前に別のターミナルからssh接続してモジュールのロードまで済ませて置きましょう。

gdb-peda$ target remote :1234
Remote debugging using :1234
Warning: not running or target is remote
0xffffffff819294a2 in native_safe_halt () at ./arch/x86/include/asm/irqflags.h:57
warning: Source file is more recent than executable.
57              asm volatile("sti; hlt": : :"memory");

ブレークポイントをセットしたら実行を再開させましょう。

gdb-peda$ b do_sys_open if $_streq(filename, "/sys/kernel/debug/open-test") == 1
Breakpoint 1 at 0xffffffff812ad830: file fs/open.c, line 1049.
gdb-peda$ c
Continuing.

以下のようにアクセスできない〜って言われた場合は無視してcを押して処理を継続しましょう。

Thread 1 hit Breakpoint 1, do_sys_open (dfd=0xffffff9c, filename=0x7f55d9b808b0 <error: Cannot access memory at address 0x7f55d9b808b0>, flags=0x88000, mode=0x0) at fs/open.c:1049
1049    {

これが設定した条件に引っかった時です。

Thread 1 hit Breakpoint 1, do_sys_open (dfd=0xffffff9c, filename=0x7ffe8f308807 "/sys/kernel/debug/open-test", flags=0x8000, mode=0x0) at fs/open.c:1049
1049    {
gdb-peda$ 

ここからは普通のgdbの使い方と一緒でnextとかstepを使ってどこでEPERMが返ってくるか調べていくとfull_proxy_open()がEPERMを返すことが分かりました。そんなわけでブレークポイントの条件をこちらに変えてもokです。

b full_proxy_open if $_streq(filp->f_path->dentry->d_iname, "open-test") == 1

良いところで止まったら、ゆっくり見ていきましょう。

gdb-peda$ c
Continuing.
[Switching to Thread 1]
Warning: not running or target is remote

Thread 1 hit Breakpoint 1, full_proxy_open (inode=inode@entry=0xffff8802261744b0, filp=filp@entry=0xffff88022fe10100) at fs/debugfs/file.c:288
warning: Source file is more recent than executable.
288     {

debugfs_file_get()は成功したようですね。

Warning: not running or target is remote
294             r = debugfs_file_get(dentry);
gdb-peda$ n
Warning: not running or target is remote
295             if (r)
gdb-peda$ p r
$1 = 0x0

しばらく先に進んでopen()が設定されているか調べていて、テストプログラムではreadしか設定していないのでここはNULLになってますね。

320             if (real_fops->open) {
gdb-peda$ p real_fops->open
$2 = (int (*)(struct inode *, struct file *)) 0x0 <irq_stack_union>

実行を続けるとdentryを片付けてエラーコード-1が返ってます。

gdb-peda$ n
Warning: not running or target is remote
338             debugfs_file_put(dentry);
gdb-peda$ n
Warning: not running or target is remote
339             return r;
gdb-peda$ p r
$3 = 0xffffffff

nで実行を継続していったときはrを最後に確認したのはdebugfs_file_get()の実行時なのでその後はgdb上では出てきてません(´・ω・`)ということでソースを見てみましょう。

staticint full_proxy_open(struct inode *inode, struct file *filp)
{
    struct dentry *dentry = F_DENTRY(filp);
    conststruct file_operations *real_fops = NULL;
    struct file_operations *proxy_fops = NULL;
    int r;

    r = debugfs_file_get(dentry);
    if (r)
        return r == -EIO ? -ENOENT : r;

    real_fops = debugfs_real_fops(filp);
    r = -EPERM;
    if (debugfs_is_locked_down(inode, filp, real_fops))
        goto out;

    real_fops = fops_get(real_fops);
    if (!real_fops) {
        /* Huh? Module did not cleanup after itself at exit? */
        WARN(1, "debugfs file owner did not clean up at exit: %pd",
            dentry);
        r = -ENXIO;
        goto out;
    }

    proxy_fops = kzalloc(sizeof(*proxy_fops), GFP_KERNEL);
    if (!proxy_fops) {
        r = -ENOMEM;
        goto free_proxy;
    }
    __full_proxy_fops_init(proxy_fops, real_fops);
    replace_fops(filp, proxy_fops);

    if (real_fops->open) {
        r = real_fops->open(inode, filp);
        if (r) {
            replace_fops(filp, d_inode(dentry)->i_fop);
            goto free_proxy;
        } elseif (filp->f_op != proxy_fops) {
            /* No protection against file removal anymore. */
            WARN(1, "debugfs file owner replaced proxy fops: %pd",
                dentry);
            goto free_proxy;
        }
    }

    goto out;
free_proxy:
    kfree(proxy_fops);
    fops_put(real_fops);
out:
    debugfs_file_put(dentry);
    return r;
}

debugfs_is_locked_down()の呼び出し前に以下の処理がありますね。ということは、real_fops->openがNULLの場合はrはそのままなので-1が返るってのがわかります。

r = -EPERM;

しかし、メインラインのカーネルではエラーにならなかったんですが??? まあ、メインラインのコードも見るしか無いですよね。ということで、4.19.2のfs/debugfs/file.cを見てみましょう。

staticint full_proxy_open(struct inode *inode, struct file *filp)
{
    struct dentry *dentry = F_DENTRY(filp);
    conststruct file_operations *real_fops = NULL;
    struct file_operations *proxy_fops = NULL;
    int r;

    r = debugfs_file_get(dentry);
    if (r)
        return r == -EIO ? -ENOENT : r;

    real_fops = debugfs_real_fops(filp);
    real_fops = fops_get(real_fops);
    if (!real_fops) {
        /* Huh? Module did not cleanup after itself at exit? */
        WARN(1, "debugfs file owner did not clean up at exit: %pd",
            dentry);
        r = -ENXIO;
        goto out;
    }

    proxy_fops = kzalloc(sizeof(*proxy_fops), GFP_KERNEL);
    if (!proxy_fops) {
        r = -ENOMEM;
        goto free_proxy;
    }
    __full_proxy_fops_init(proxy_fops, real_fops);
    replace_fops(filp, proxy_fops);

    if (real_fops->open) {
        r = real_fops->open(inode, filp);
        if (r) {
            replace_fops(filp, d_inode(dentry)->i_fop);
            goto free_proxy;
        } elseif (filp->f_op != proxy_fops) {
            /* No protection against file removal anymore. */
            WARN(1, "debugfs file owner replaced proxy fops: %pd",
                dentry);
            goto free_proxy;
        }
    }

    goto out;
free_proxy:
    kfree(proxy_fops);
    fops_put(real_fops);
out:
    debugfs_file_put(dentry);
    return r;
}

差が有りますね。。。これが差分です。

+        r = -EPERM;
+        if (debugfs_is_locked_down(inode, filp, real_fops))
+                goto out;
+

fedoraカーネルではreal_fops->openが設定されていないと -EPERMが返る仕様になっています。ということはディストリビューション側でパッチを当ててますよね。ってことで調べてみましょう。fedoraカーネルのgitリポジトリこちらです。カーネルと言うかカーネルパッケージのgitリポジトリです。

ブランチをf29に変えてパッチを調べるとefi-lockdown.patchに該当のコードが見つかります。このパッチファイルの1560行目からが該当する部分です。まさにありますね。

 
@@ -272,6 +296,10 @@ staticint full_proxy_open(struct inode *inode, struct file *filp)
        return r == -EIO ? -ENOENT : r;
 
    real_fops = debugfs_real_fops(filp);
+   r = -EPERM;
+   if (debugfs_is_locked_down(inode, filp, real_fops))
+       goto out;
+

ここまで分かったのでテストプログラムを修正しましょう。

修正

file_operations構造体のopen()を設定します。openの処理自体には特別な処理は不要なのでlinux/fs.hで宣言されているsimple_open()を使いましょう。

        .open = simple_open,

これで実行するとちゃんと動きました(∩´∀`)∩ワーイ

masami@kerntest:~/open-test$ sudo insmod ./open_test.ko
masami@kerntest:~/open-test$ uname -a
Linux kerntest 4.19.2-300.fc29.x86_64 #1 SMP Wed Nov 14 19:05:24 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
masami@kerntest:~/open-test$ sudo cat /sys/kernel/debug/open-test
hello, world!
masami@kerntest:~/open-test$ 

もちろんメインラインのカーネルでも動きますヽ(=´▽`=)ノ

masami@kerntest:~/open-test$ sudo insmod ./open_test.ko
masami@kerntest:~/open-test$ uname -a
Linux kerntest 4.20.0-rc3-test+ #8 SMP Fri Nov 23 10:15:41 JST 2018 x86_64 x86_64 x86_64 GNU/Linux
masami@kerntest:~/open-test$ sudo cat /sys/kernel/debug/open-test
hello, world!
masami@kerntest:~/open-test$ 

まとめ

gdbを使ったカーネルデバッグを説明しました。カーネルと言っても普通のcプログラムと変わらずにデバッグできるし、こわくないよーという感じではないでしょうか。 あと、ディストリビューションカーネルを使っているときはもしかしたらメインラインに入っていない機能が有る場合も有るので、使われているパッチにも気をつけないといけないですね。。。

( ´ー`)フゥー...

mockとpackageのgitリポジトリとリビルド

$
0
0

この記事はLinux Advent Calendarの19日目です。

概要

今回はsrpmをダウンロードしてきて何かをするのではなくて、パッケージのgitリポジトリからcloneしてきてビルドするときのメモです。パッケージのビルド方法としてはfedpkgを使うかmockを使うかの2通りがあります。両者の方法を見ていきましょう。

fedpkgの場合

masterブランチとかf29と言ったディストリビューションのバージョンのブランチをそのまま使わずに、ローカルにブランチを作って作業するとしましょう。こんな感じですね。

masami@saga:~/fedora-bash (master=)$ git checkout -b f29 origin/f29
Branch 'f29' set up to track remote branch 'f29' from 'origin'.
Switched to a new branch 'f29'
masami@saga:~/fedora-bash (f29=)$ git checkout -b build-test
Switched to a new branch 'build-test'

この場合、fedpkgで普通にmockbuildをするとエラーになります。これはローカルのブランチがリモートにも有ることを期待しているためです。で、--releaseオプションを使えと言われます。

masami@saga:~/fedora-bash (build-test)$ fedpkg mockbuild
Downloading bash-4.4.tar.gz
######################################################################## 100.0%
Could not execute mockbuild: Unable to find remote branch.  Use --release

--releaseオプションはmockbuildオプションのオプションではなくて、fedpkgのオプションです。ということでこのようにするとresults_bash/というディレクトリが出来て、その下にrpmパッケージが置かれます。

masami@saga:~/fedora-bash (build-test)$ fedpkg --release f29 mockbuild
warning: Macro expanded in comment on line 16: %{version}.tar.gz



warning: Macro expanded in comment on line 16: %{version}.tar.gz

Wrote: /home/masami/fedora-bash/bash-4.4.23-5.fc29.src.rpm
INFO: mock.py version 1.4.13 starting (python version = 3.7.1)...
Start: init plugins
〜略〜

mockの場合

mockを使う場合は一旦srpmを作ってからビルドします。specとpatch諸々が有るディレクトリを指定し、srpmパッケージをresultdirオプションで指定した場所に作ります。

masami@saga:~/fedora-bash (build-test %)$ mock -r /etc/mock/fedora-29-x86_64.cfg --buildsrpm --spec ./bash.spec --sources=. --resultdir=.
INFO: mock.py version 1.4.13 starting (python version = 3.7.1)...
Start: init plugins
INFO: selinux disabled
Finish: init plugins
〜略〜

そしてsrpmファイルをビルドしてrpmパッケージを作ります。

masami@saga:~/fedora-bash (build-test %)$ mock -r /etc/mock/fedora-29-x86_64.cfg --rebuild ./bash-4.4.23-5.fc29.src.rpm
INFO: mock.py version 1.4.13 starting (python version = 3.7.1)...
Start: init plugins
〜略〜

おまけ srpmを展開してgitリポジトリと同じ構造で扱う

rpmコマンドで~/rpmbuildにファイルを展開するのではなくてrpm2cpioとcpioで展開すればgitリポジトリと同じ構造で.specやpatch等を取り出せます。あとはmockの場合の方法でビルドできます。

masami@saga:~/tmp/bash$ rpm2cpio ~/fedora-bash/bash-4.4.23-5.fc29.src.rpm | cpio -iv
bash-2.02-security.patch
bash-2.03-paths.patch
bash-2.03-profile.patch
〜略〜
dot-bash_profile
dot-bashrc
18621 blocks
masami@saga:~/tmp/bash$ ls
./                            bash-3.2-ssh_source_bash.patch     bash-4.3-noecho.patch                 bash-4.4-patch-16.patch  bash-4.4-patch-4.patch                 bash-setlocale.patch
../                           bash-4.0-nobits.patch              bash-4.4-assignment-error.patch       bash-4.4-patch-17.patch  bash-4.4-patch-5.patch                 bash.spec
bash-2.02-security.patch      bash-4.1-broken_pipe.patch         bash-4.4-case-in-command-subst.patch  bash-4.4-patch-18.patch  bash-4.4-patch-6.patch                 bash-tty-tests.patch
bash-2.03-paths.patch         bash-4.1-defer-sigchld-trap.patch  bash-4.4-coverity.patch               bash-4.4-patch-19.patch  bash-4.4-patch-7.patch                 dot-bash_logout
bash-2.03-profile.patch       bash-4.1-examples.patch            bash-4.4-no-loadable-builtins.patch   bash-4.4-patch-1.patch   bash-4.4-patch-8.patch                 dot-bash_profile
bash-2.05a-interpreter.patch  bash-4.2-coverity.patch            bash-4.4-patch-10.patch               bash-4.4-patch-20.patch  bash-4.4-patch-9.patch                 dot-bashrc
bash-2.05b-debuginfo.patch    bash-4.2-manpage_trap.patch        bash-4.4-patch-11.patch               bash-4.4-patch-21.patch  bash-4.4.tar.gz
bash-2.05b-manso.patch        bash-4.2-rc2-logout.patch          bash-4.4-patch-12.patch               bash-4.4-patch-22.patch  bash-4.4-unset-nonblock-stdin.patch
bash-2.05b-pgrp_sync.patch    bash-4.2-size_type.patch           bash-4.4-patch-13.patch               bash-4.4-patch-23.patch  bash-4.5-test-modification-time.patch
bash-2.05b-xcc.patch          bash-4.3-man-ulimit.patch          bash-4.4-patch-14.patch               bash-4.4-patch-2.patch   bash-infotags.patch
bash-3.2-audit.patch          bash-4.3-memleak-lc_all.patch      bash-4.4-patch-15.patch               bash-4.4-patch-3.patch   bash-requires.patch

まとめ

mockやfedpkgを使う利点は~/rpmbuildを使わないのでファイルがゴチャゴチャにならずにすみます😃

RHEL 8 betaのsrpmをリビルドしてmockでshellでログインできるところまで作る

$
0
0

この記事はLinux Advent Calendarの13日目です。

いんとろ

Powering IT’s future while preserving the present: Introducing Red Hat Enterprise Linux 8 Betaキタ━━━━(゚∀゚)━━━━!!って感じですよね。

srpmも公開されています。Index of /redhat/rhel/rhel-8-beta/baseos/source/PackagesIndex of /redhat/rhel/rhel-8-beta/appstream/source/Packagesにあります。BaseOSとかAppstreamとは?といくところはIntroducing Application Streams in RHEL 8 - RHD Blogとかを参照してもらえればokかと思います。

今回はrhel8以外の環境でrhel8のsrpmをリビルドしてrhelクローン的なものを作って遊ぼうではないかというところになります。

ビルド環境

ホストはfedora 29でビルド環境としてはmockのfedora 28にしました。RHEL 8はfedora 28ベースらしい(8.0 BETA RELEASE NOTES)のでfedora 28でいいかーって感じです。

ちなみに、mockrpmパッケージをクリーンな環境でビルドするためのツールです。意味合い的にはdebianpbuilderに近いかも?mockはchrootの環境にsystemd-nspawnを使ってます。

ビルド手順

手順としてはこういう感じになります。最初はfedora 28の環境でパッケージをビルドして、それ以降はリビルドしたパッケージを使ってmock環境を作ってビルドしていくというブートストラップ方式です。

  1. mockに必要なパッケージをダウンロードしてくる
  2. 最初はfedora 28環境でrhel 8 betaのsrpmをビルドしてrpmパッケージとsrpmパッケージを作ります
  3. 1で作ったrpmパッケージでmock環境を作り、そこで1で作ったsrpmをビルドします
  4. 2で作ったrpmパッケージで2で作ったsrpmをリビルド

今回は2の途中までしか出来てません。

パッケージのビルド

stage 0

パッケージの確認

最初に最低限のビルド環境を作る必要があるので、この環境に必要なパッケージのsrpmをダウンロードします。必要なパッケージが何か調べる方法ですがmockを使いました。fedora 29に入ってるmockパッケージだとmock環境としてrhel 8 betaの環境があります。なので、この環境を作ってその時にインストールされるパッケージを確認しました。

masami@saga:~/codes/rhel_rebuild/stage0$ ls /etc/mock/
./                    default.cfg@         fedora-27-aarch64.cfg  fedora-28-ppc64.cfg    fedora-29-x86_64.cfg        fedora-rawhide-i386.cfg     mageia-cauldron-aarch64.cfg      rhelbeta-8-aarch64.cfg
../                   default.cfg.rpmnew@  fedora-27-armhfp.cfg   fedora-28-ppc64le.cfg  fedora-30-aarch64.cfg@      fedora-rawhide-ppc64.cfg    mageia-cauldron-armv7hl.cfg      rhelbeta-8-ppc64le.cfg
custom-1-aarch64.cfg  eol/                 fedora-27-i386.cfg     fedora-28-s390x.cfg    fedora-30-armhfp.cfg@       fedora-rawhide-ppc64le.cfg  mageia-cauldron-i586.cfg         rhelbeta-8-s390x.cfg
custom-1-armhfp.cfg   epel-6-i386.cfg      fedora-27-ppc64.cfg    fedora-28-x86_64.cfg   fedora-30-i386.cfg@         fedora-rawhide-s390x.cfg    mageia-cauldron-x86_64.cfg       rhelbeta-8-x86_64.cfg
custom-1-i386.cfg     epel-6-ppc64.cfg     fedora-27-ppc64le.cfg  fedora-29-aarch64.cfg  fedora-30-ppc64.cfg@        fedora-rawhide-x86_64.cfg   opensuse-leap-15.0-x86_64.cfg    site-defaults.cfg
custom-1-ppc64.cfg    epel-6-x86_64.cfg    fedora-27-s390x.cfg    fedora-29-armhfp.cfg   fedora-30-ppc64le.cfg@      logging.ini                 opensuse-tumbleweed-aarch64.cfg
custom-1-ppc64le.cfg  epel-7-aarch64.cfg   fedora-27-x86_64.cfg   fedora-29-i386.cfg     fedora-30-s390x.cfg@        mageia-6-armv5tl.cfg        opensuse-tumbleweed-i586.cfg
custom-1-s390.cfg     epel-7-ppc64.cfg     fedora-28-aarch64.cfg  fedora-29-ppc64.cfg    fedora-30-x86_64.cfg@       mageia-6-armv7hl.cfg        opensuse-tumbleweed-ppc64.cfg
custom-1-s390x.cfg    epel-7-ppc64le.cfg   fedora-28-armhfp.cfg   fedora-29-ppc64le.cfg  fedora-rawhide-aarch64.cfg  mageia-6-i586.cfg           opensuse-tumbleweed-ppc64le.cfg
custom-1-x86_64.cfg   epel-7-x86_64.cfg    fedora-28-i386.cfg     fedora-29-s390x.cfg    fedora-rawhide-armhfp.cfg   mageia-6-x86_64.cfg         opensuse-tumbleweed-x86_64.cfg

インストールされたパッケージ数は160パッケージほどでした。そして個々のrpmパッケージがそのsrpmパッケージから調べると123個ほどでした。

srpmのダウンロード

ということで、ここで必要なのはsrpmパッケージをダウンロードしてビルドするための準備をします。ダウンロードは以下のスクリプトで行いました。

#!/bin/bash

urls=$(cat ./rpm_list.txt)

rm -fr srpms
mkdir -p srpms/{baseos,appstream}

cd srpms

for url in $urls;
do
    name=$(basename $url)
    dl_dir="baseos"

    echo $url | grep appstream >/dev/null 2>&1
    if [ $? -eq 0 ]; then
       dl_dir="appstream"
    fi

    savefile="$dl_dir/$name"

    echo "[-]Download $name to $dl_dir"
    curl -L -o $savefile $url
done

rpm_list.txtは以下のようにsrpmパッケージのリンクを1行ずつ書いてるだけです。

http://downloads.redhat.com/redhat/rhel/rhel-8-beta/baseos/source/Packages/acl-2.2.53-1.el8.src.rpm
http://downloads.redhat.com/redhat/rhel/rhel-8-beta/baseos/source/Packages/attr-2.4.48-3.el8.src.rpm

そして次のスクリプトでダウンロードしたsrpmパッケージを展開して、個々のsrpmパッケージに含まれるファイルをgitで管理するようにしてます。

#!/bin/bash

pkgrepo="../pkgrepo"

rm -fr $pkgrepo
mkdir -p $pkgrepo/{baseos,appstream}

topdir=$(pwd)

setup_dir() {
    path=$1

    dir="srpms/$path"
    srpms=$(ls $dir)

    for srpm in $srpms;
    do
        spec=$(rpm -ql $dir/$srpm | grep '.spec$')
        name="${spec%.*}"
        echo $name

        pushd . >/dev/null 2>&1

        cd $pkgrepo/$path
        mkdir $name

        cd $name
        git init
        rpm2cpio ../../../stage0/srpms/$path/$srpm | cpio -iv
        git add .
        git commit -m "initial commit"

        popd >/dev/null 2>&1
    done

}

setup_dir "baseos"
setup_dir "appstream"

ここはmockとpackageのgitリポジトリとリビルド - φ(・・*)ゞ ウーン カーネルとか弄ったりのメモのおまけで紹介したことをやってます。

ここまでで各srpmパッケージについてspecとかパッチなんかをgitで管理できるようになりました。

stage 1

ビルド環境設定

次はパッケージをfedora 28のmock環境でビルドしていきます。最初にsrpmを作って次にrpmを作る流れです。この時にmockに渡すconfigファイルを自前で用意します。と言っても/etc/mockにあるfedora 28のファイルを名前を変えてコピーするだけなのでなくても良いんですが。それとmacros.distファイルを使います。これはそのままビルドするとディストリビューション名がfc28とかになってしまうのでこれを変更するためです。 macros.distはこんな感じです。

# dist macros.

%foobar              8
%dist                %{?distprefix}.fb8
%fb8                1

srpmの作成

srpmのリビルドはこんなスクリプトで行います。

#!/bin/bash

pkg_gitrepo="../pkg_gitrepo"
mockcfg="./foobar.cfg"
macrofile="./macros.dist"

pkgkind=("baseos" "appstream")

resultdir_root="./srpms"

if [ -d $resultdir_root ]; then
    rm -fr $resultdir_root
fi

mkdir -p $resultdir_root/{baseos,appstream}

for kind in ${pkgkind[@]};
do
    packages=$(echo $pkg_gitrepo/$kind/*)

    for pkgdir in ${packages[@]};
    do
        name=$(basename $pkgdir)
        resultdir="$resultdir_root/$kind/"

        echo "[-]$(date) Create $name srpm"
        mock -r $mockcfg --resultdir=$resultdir --macro-file=$macrofile --buildsrpm --spec $pkgdir/${name}.spec --sources $pkgdir >/dev/null 2>&1
        if [ $? -eq 0 ]; then
            echo "[-]$(date) Success build $name srpm"
        else
            echo "[*]$(date) Fail build $name srpm"
        fi
        echo "[-]$(date) End $name srpm"
    done
done

find srpms/ -name "*.log" | xargs rm -f

echo "[-]$(date) Done."

rpmパッケージの作成

そして作成したsrpmをビルドします。

#!/bin/bash

pkg_gitrepo="../pkg_gitrepo"
mockcfg="./foobar.cfg"
macrofile="./macros.dist"

pkgkind=("baseos" "appstream")

srpmsdir="./srpms"
resultdir_root="./rpms"

if [ -d $resultdir_root ]; then
    rm -fr $resultdir_root
fi

mkdir -p $resultdir_root/{baseos,appstream}

echo "[-]$(date) build start"

for kind in ${pkgkind[@]};
do
    packages=$(echo $srpmsdir/$kind/*)

    for pkg in ${packages[@]};
    do
        srcrpm=$(basename $pkg)

        spec=$(rpm -ql $pkg | grep '.spec$')
        pkgname="${spec%.*}"

        echo "[-]$(date) Build $pkgname start"

        resultdir="$resultdir_root/$kind/$pkgname"
        mkdir -p $resultdir

        mock -r $mockcfg --resultdir=$resultdir --macro-file=$macrofile --nocheck --rebuild $pkg >/dev/null 2>&1
        ls $resultdir/*.rpm >/dev/null 2>&1
        if [ $? -eq 0 ]; then
            echo "[-]$(date) Rebuild $pkgname success"
        else
            echo "[*]$(date) Rebuild $pkgname failed"
        fi
        echo "[-]$(date) Build $pkgname end"
    done
done

echo "[-]$(date) End"

これでビルドに成功したパッケージはヽ(=´▽`=)ノという感じで、失敗したものは原因を調べてspecファイルを修正するなどの作業が必要です。まあ。specファイルの修正があるのでgit管理できるようにしたんですね(ノω・)テヘ 単純にビルド成功させるためとしては5、6個のパッケージのspecファイルを修正したのと、いくつかのパッケージはrhel 8 betaのbinutilsが必要だったりしました。

binutilsの方はmockでビルドする前に--installオプションでリビルドしたbinutilsをインストールしてから--nocleanオプションを付けて事前に環境を綺麗にしないでビルドさせるようにしてパッケージのビルドを行いました。

こんな感じで全部のパッケージをビルドしました。

dnfのリポジトリ作成

createrepoコマンドでサクッと作りました。作り方としては、BaseOSとAppstreamは分ける必要が有るので分けてます。ディレクトリ構成としてはこんな感じにしました。repodata/はPackagesやsourcesの中に有る形です。

pkgrepo_for_stage2     ----    baseos    ----    x86_64    ----    Packages
                                     |                       |---     sources
                                     |---    appstream    ----      x86_64    ----    Packages
                                                                  |---       source

stage 2

mockの設定ファイル

stage 1で作ったパッケージを使った環境でmockを使えるようにします。ここでもやっとmock用の設定ファイルをちゃんと使うようになります。foobar.cfgとして以下のようにしました。パッケージグループは作ってないのでパッケージはベタに書いてます(´・ω・`)

config_opts['root'] = 'foobar8'
config_opts['target_arch'] = 'x86_64'
config_opts['legal_host_arches'] = ('x86_64',)
#config_opts['chroot_setup_cmd'] = 'install @buildsys-build'
config_opts['chroot_setup_cmd'] = 'install bash bzip2 coreutils cpio diffutils findutils gawk grep gzip info make patch redhat-release sed shadow-utils tar unzip util-linux which xz rpm binutils glibc-devel libgomp isl libmpc cpp'
config_opts['dist'] = 'fb8'  # only useful for --resultdir variable subst
config_opts['extra_chroot_dirs'] = [ '/run/lock', ]
config_opts['releasever'] = 'fb'
config_opts['package_manager'] = 'dnf'

config_opts['yum.conf'] = """
[main]
keepcache=1
debuglevel=2
reposdir=/dev/null
logfile=/var/log/yum.log
retries=20
obsoletes=1
gpgcheck=0
assumeyes=1
syslog_ident=mock
syslog_device=
install_weak_deps=0
metadata_expire=0
mdpolicy=group:primary
best=1

# repos

[foobar-base]
name=Foobar BaseOS
baseurl=file:///home/masami/rhel_rebuild/pkgrepo_for_stage2/baseos/x86_64/Packages
enabled=1
gpgcheck=0

[foobar-appstream]
name=Foobar Appstream
baseurl=file:///home/masami/rhel_rebuild/pkgrepo_for_stage2/appstream/x86_64/Packages
enabled=1
gpgcheck=0

[foobar-base-source]
name=Foobar BaseOS source
baseurl=file:///home/masami/rhel_rebuild/pkgrepo_for_stage2/baseos/source
enabled=0

[foobar-base-source]
name=Foobar BaseOS source
baseurl=file:///home/masami/rhel_rebuild/pkgrepo_for_stage2/appstream/source
enabled=0

mock環境にログイン

これを使ってmock環境にログインすることができます。

masami@rhel-build:~/rhel_rebuild/stage2$ mock -r ./foobar.cfg --shell /bin/bash
INFO: mock.py version 1.4.13 starting (python version = 3.7.1)...
Start: init plugins
INFO: selinux disabled
Finish: init plugins
Start: run
Start: chroot init
INFO: calling preinit hooks
INFO: enabled root cache
INFO: enabled dnf cache
Start: cleaning dnf metadata
Finish: cleaning dnf metadata
INFO: enabled HW Info plugin
Start: dnf install
Foobar Appstream                                                                                                                                                                    18 kB/s |  36 kB     00:02
Foobar BaseOS                                                                                                                                                                      491 kB/s | 1.0 MB     00:02
Dependencies resolved.
===================================================================================================================================================================================================================
 Package                                             Arch                                   Version                                                         Repository                                        Size
===================================================================================================================================================================================================================
Installing:
 isl                                                 x86_64                                 0.16.1-6.fb8                                                    foobar-appstream                                 841 k
 libmpc                                              x86_64                                 1.0.2-9.fb8                                                     foobar-appstream                                  57 k
 bash                                                x86_64                                 4.4.19-6.fb8                                                    foobar-base                                      1.5 M
 binutils                                            x86_64                                 2.30-49.fb8                                                     foobar-base                                      5.6 M
 bzip2                                               x86_64                                 1.0.6-26.fb8                                                    foobar-base                                       59 k
 coreutils                                           x86_64                                 8.30-4.fb8                                                      foobar-base                                      1.2 M
 cpio                                                x86_64                                 2.12-8.fb8                                                      foobar-base                                      264 k
 cpp                                                 x86_64                                 8.2.1-3.3.fb8                                                   foobar-base                                       10 M
 diffutils                                           x86_64                                 3.6-5.fb8                                                       foobar-base                                      358 k
 findutils                                           x86_64                                 1:4.6.0-19.fb8                                                  foobar-base                                      526 k
 gawk                                                x86_64                                 4.2.1-1.fb8                                                     foobar-base                                      1.1 M
 glibc-devel                                         x86_64                                 2.28-18.fb8                                                     foobar-base                                      1.0 M
 grep                                                x86_64                                 3.1-6.fb8                                                       foobar-base                                      272 k
 gzip                                                x86_64                                 1.9-4.fb8                                                       foobar-base                                      164 k
 info                                                x86_64                                 6.5-4.fb8                                                       foobar-base                                      197 k
 libgomp                                             x86_64                                 8.2.1-3.3.fb8                                                   foobar-base                                      187 k
 make                                                x86_64                                 1:4.2.1-9.fb8                                                   foobar-base                                      496 k
 patch                                               x86_64                                 2.7.6-7.fb8                                                     foobar-base                                      136 k
 redhat-release                                      x86_64                                 8.0-0.34.fb8                                                    foobar-base                                       44 k
 rpm                                                 x86_64                                 4.14.2-4.fb8                                                    foobar-base                                      534 k
 sed                                                 x86_64                                 4.5-1.fb8                                                       foobar-base                                      296 k
 shadow-utils                                        x86_64                                 2:4.6-4.fb8                                                     foobar-base                                      1.2 M
 tar                                                 x86_64                                 2:1.30-4.fb8                                                    foobar-base                                      837 k
 unzip                                               x86_64                                 6.0-38.fb8                                                      foobar-base                                      190 k
 util-linux                                          x86_64                                 2.32.1-6.fb8                                                    foobar-base                                      2.5 M
 which                                               x86_64                                 2.21-10.fb8                                                     foobar-base                                       47 k
 xz                                                  x86_64                                 5.2.4-2.fb8                                                     foobar-base                                      151 k
Installing dependencies:
 audit-libs                                          x86_64                                 3.0-0.5.20180831git0047a6c.fb8                                  foobar-base                                      114 k
 basesystem                                          noarch                                 11-5.fb8                                                        foobar-base                                      9.3 k
 bzip2-libs                                          x86_64                                 1.0.6-26.fb8                                                    foobar-base                                       47 k
 ca-certificates                                     noarch                                 2018.2.24-6.fb8                                                 foobar-base                                      393 k
 chkconfig                                           x86_64                                 1.11-1.fb8                                                      foobar-base                                      188 k
 coreutils-common                                    x86_64                                 8.30-4.fb8                                                      foobar-base                                      2.0 M
 cracklib                                            x86_64                                 2.9.6-14.fb8                                                    foobar-base                                       92 k
 crypto-policies                                     noarch                                 20181026-1.gitcc78cb7.fb8                                       foobar-base                                       48 k
 curl                                                x86_64                                 7.61.1-5.fb8                                                    foobar-base                                      350 k
 elfutils-libelf                                     x86_64                                 0.174-1.fb8                                                     foobar-base                                      208 k
 expat                                               x86_64                                 2.2.5-3.fb8                                                     foobar-base                                      109 k
 filesystem                                          x86_64                                 3.8-2.fb8                                                       foobar-base                                      1.1 M
 glibc                                               x86_64                                 2.28-18.fb8                                                     foobar-base                                      3.7 M
 glibc-all-langpacks                                 x86_64                                 2.28-18.fb8                                                     foobar-base                                       25 M
 glibc-common                                        x86_64                                 2.28-18.fb8                                                     foobar-base                                      796 k
 glibc-headers                                       x86_64                                 2.28-18.fb8                                                     foobar-base                                      460 k
 gmp                                                 x86_64                                 1:6.1.2-8.fb8                                                   foobar-base                                      318 k
 kernel-headers                                      x86_64                                 4.18.0-32.fb8                                                   foobar-base                                      1.3 M
 keyutils-libs                                       x86_64                                 1.5.10-6.fb8                                                    foobar-base                                       32 k
 krb5-libs                                           x86_64                                 1.16.1-19.fb8                                                   foobar-base                                      842 k
 libacl                                              x86_64                                 2.2.53-1.fb8                                                    foobar-base                                       34 k
 libarchive                                          x86_64                                 3.3.2-3.fb8                                                     foobar-base                                      356 k
 libattr                                             x86_64                                 2.4.48-3.fb8                                                    foobar-base                                       26 k
 libblkid                                            x86_64                                 2.32.1-6.fb8                                                    foobar-base                                      211 k
 libcap                                              x86_64                                 2.25-9.fb8                                                      foobar-base                                       55 k
 libcap-ng                                           x86_64                                 0.7.9-3.fb8                                                     foobar-base                                       32 k
 libcom_err                                          x86_64                                 1.44.3-1.fb8                                                    foobar-base                                       47 k
 libcurl-minimal                                     x86_64                                 7.61.1-5.fb8                                                    foobar-base                                      279 k
 libdb                                               x86_64                                 5.3.28-33.fb8                                                   foobar-base                                      757 k
 libdb-utils                                         x86_64                                 5.3.28-33.fb8                                                   foobar-base                                      147 k
 libfdisk                                            x86_64                                 2.32.1-6.fb8                                                    foobar-base                                      246 k
 libffi                                              x86_64                                 3.1-17.fb8                                                      foobar-base                                       35 k
 libgcc                                              x86_64                                 8.2.1-3.3.fb8                                                   foobar-base                                       75 k
 libgcrypt                                           x86_64                                 1.8.3-2.fb8                                                     foobar-base                                      457 k
 libgpg-error                                        x86_64                                 1.31-1.fb8                                                      foobar-base                                      240 k
 libmetalink                                         x86_64                                 0.1.3-7.fb8                                                     foobar-base                                       31 k
 libmount                                            x86_64                                 2.32.1-6.fb8                                                    foobar-base                                      228 k
 libnghttp2                                          x86_64                                 1.33.0-1.fb8                                                    foobar-base                                       76 k
 libnsl2                                             x86_64                                 1.2.0-2.20180605git4a062cf.fb8                                  foobar-base                                       56 k
 libpkgconf                                          x86_64                                 1.4.2-1.fb8                                                     foobar-base                                       33 k
 libpwquality                                        x86_64                                 1.4.0-8.fb8                                                     foobar-base                                      101 k
 libselinux                                          x86_64                                 2.8-5.fb8                                                       foobar-base                                      177 k
 libsemanage                                         x86_64                                 2.8-3.1.fb8                                                     foobar-base                                      160 k
 libsepol                                            x86_64                                 2.8-1.fb8                                                       foobar-base                                      337 k
 libsigsegv                                          x86_64                                 2.11-5.fb8                                                      foobar-base                                       29 k
 libsmartcols                                        x86_64                                 2.32.1-6.fb8                                                    foobar-base                                      171 k
 libstdc++                                           x86_64                                 8.2.1-3.3.fb8                                                   foobar-base                                      446 k
 libtasn1                                            x86_64                                 4.13-3.fb8                                                      foobar-base                                       75 k
 libtirpc                                            x86_64                                 1.1.4-3.fb8                                                     foobar-base                                      111 k
 libutempter                                         x86_64                                 1.1.6-14.fb8                                                    foobar-base                                       30 k
 libuuid                                             x86_64                                 2.32.1-6.fb8                                                    foobar-base                                       91 k
 libverto                                            x86_64                                 0.3.0-5.fb8                                                     foobar-base                                       23 k
 libxcrypt                                           x86_64                                 4.1.1-4.fb8                                                     foobar-base                                       72 k
 libxcrypt-devel                                     x86_64                                 4.1.1-4.fb8                                                     foobar-base                                       24 k
 libxml2                                             x86_64                                 2.9.7-5.fb8                                                     foobar-base                                      694 k
 lua-libs                                            x86_64                                 5.3.4-10.fb8                                                    foobar-base                                      117 k
 lz4-libs                                            x86_64                                 1.8.1.2-4.fb8                                                   foobar-base                                       54 k
 mpfr                                                x86_64                                 3.1.6-1.fb8                                                     foobar-base                                      220 k
 ncurses                                             x86_64                                 6.1-5.20180224.fb8                                              foobar-base                                      377 k
 ncurses-base                                        noarch                                 6.1-5.20180224.fb8                                              foobar-base                                       79 k
 ncurses-libs                                        x86_64                                 6.1-5.20180224.fb8                                              foobar-base                                      333 k
 openssl-libs                                        x86_64                                 1:1.1.1-6.fb8                                                   foobar-base                                      1.4 M
 p11-kit                                             x86_64                                 0.23.14-2.fb8                                                   foobar-base                                      270 k
 p11-kit-trust                                       x86_64                                 0.23.14-2.fb8                                                   foobar-base                                      137 k
 pam                                                 x86_64                                 1.3.1-3.fb8                                                     foobar-base                                      741 k
 pcre                                                x86_64                                 8.42-4.fb8                                                      foobar-base                                      207 k
 pcre2                                               x86_64                                 10.31-11.fb8                                                    foobar-base                                      237 k
 pkgconf                                             x86_64                                 1.4.2-1.fb8                                                     foobar-base                                       37 k
 pkgconf-m4                                          noarch                                 1.4.2-1.fb8                                                     foobar-base                                       16 k
 pkgconf-pkg-config                                  x86_64                                 1.4.2-1.fb8                                                     foobar-base                                       14 k
 popt                                                x86_64                                 1.16-14.fb8                                                     foobar-base                                       60 k
 readline                                            x86_64                                 7.0-10.fb8                                                      foobar-base                                      198 k
 rpm-libs                                            x86_64                                 4.14.2-4.fb8                                                    foobar-base                                      331 k
 rpm-plugin-selinux                                  x86_64                                 4.14.2-4.fb8                                                    foobar-base                                       69 k
 setup                                               noarch                                 2.12.2-1.fb8                                                    foobar-base                                      179 k
 systemd-libs                                        x86_64                                 239-8.fb8                                                       foobar-base                                      524 k
 tzdata                                              noarch                                 2018e-2.fb8                                                     foobar-base                                      458 k
 xz-libs                                             x86_64                                 5.2.4-2.fb8                                                     foobar-base                                       93 k
 zlib                                                x86_64                                 1.2.11-10.fb8                                                   foobar-base                                      100 k

Transaction Summary
===================================================================================================================================================================================================================
Install  106 Packages

Total size: 79 M
Installed size: 378 M
Downloading Packages:
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Running scriptlet: filesystem-3.8-2.fb8.x86_64                                                                                                                                                               1/1
  Preparing        :                                                                                                                                                                                           1/1
  Installing       : libgcc-8.2.1-3.3.fb8.x86_64                                                                                                                                                             1/106
  Running scriptlet: libgcc-8.2.1-3.3.fb8.x86_64                                                                                                                                                             1/106
  Installing       : tzdata-2018e-2.fb8.noarch                                                                                                                                                               2/106
  Installing       : redhat-release-8.0-0.34.fb8.x86_64                                                                                                                                                      3/106
  Installing       : setup-2.12.2-1.fb8.noarch                                                                                                                                                               4/106
  Running scriptlet: setup-2.12.2-1.fb8.noarch                                                                                                                                                               4/106
warning: /etc/hosts created as /etc/hosts.rpmnew

  Installing       : filesystem-3.8-2.fb8.x86_64                                                                                                                                                             5/106
  Installing       : basesystem-11-5.fb8.noarch                                                                                                                                                              6/106
  Installing       : pkgconf-m4-1.4.2-1.fb8.noarch                                                                                                                                                           7/106
  Installing       : ncurses-base-6.1-5.20180224.fb8.noarch                                                                                                                                                  8/106
  Installing       : pcre2-10.31-11.fb8.x86_64                                                                                                                                                               9/106
  Installing       : libselinux-2.8-5.fb8.x86_64                                                                                                                                                            10/106
  Installing       : ncurses-libs-6.1-5.20180224.fb8.x86_64                                                                                                                                                 11/106
  Installing       : glibc-all-langpacks-2.28-18.fb8.x86_64                                                                                                                                                 12/106
  Installing       : glibc-common-2.28-18.fb8.x86_64                                                                                                                                                        13/106
  Running scriptlet: glibc-2.28-18.fb8.x86_64                                                                                                                                                               14/106
  Installing       : glibc-2.28-18.fb8.x86_64                                                                                                                                                               14/106
  Running scriptlet: glibc-2.28-18.fb8.x86_64                                                                                                                                                               14/106
  Installing       : bash-4.4.19-6.fb8.x86_64                                                                                                                                                               15/106
  Running scriptlet: bash-4.4.19-6.fb8.x86_64                                                                                                                                                               15/106
  Installing       : libsepol-2.8-1.fb8.x86_64                                                                                                                                                              16/106
  Running scriptlet: libsepol-2.8-1.fb8.x86_64                                                                                                                                                              16/106
  Installing       : zlib-1.2.11-10.fb8.x86_64                                                                                                                                                              17/106
  Installing       : info-6.5-4.fb8.x86_64                                                                                                                                                                  18/106
  Installing       : bzip2-libs-1.0.6-26.fb8.x86_64                                                                                                                                                         19/106
  Installing       : xz-libs-5.2.4-2.fb8.x86_64                                                                                                                                                             20/106
  Installing       : gmp-1:6.1.2-8.fb8.x86_64                                                                                                                                                               21/106
  Running scriptlet: gmp-1:6.1.2-8.fb8.x86_64                                                                                                                                                               21/106
  Installing       : libcap-2.25-9.fb8.x86_64                                                                                                                                                               22/106
  Installing       : libdb-5.3.28-33.fb8.x86_64                                                                                                                                                             23/106
  Running scriptlet: libdb-5.3.28-33.fb8.x86_64                                                                                                                                                             23/106
  Installing       : libattr-2.4.48-3.fb8.x86_64                                                                                                                                                            24/106
  Installing       : libacl-2.2.53-1.fb8.x86_64                                                                                                                                                             25/106
  Installing       : sed-4.5-1.fb8.x86_64                                                                                                                                                                   26/106
  Running scriptlet: sed-4.5-1.fb8.x86_64                                                                                                                                                                   26/106
  Installing       : libuuid-2.32.1-6.fb8.x86_64                                                                                                                                                            27/106
  Running scriptlet: libuuid-2.32.1-6.fb8.x86_64                                                                                                                                                            27/106
  Installing       : libxcrypt-4.1.1-4.fb8.x86_64                                                                                                                                                           28/106
  Installing       : popt-1.16-14.fb8.x86_64                                                                                                                                                                29/106
  Installing       : mpfr-3.1.6-1.fb8.x86_64                                                                                                                                                                30/106
  Running scriptlet: mpfr-3.1.6-1.fb8.x86_64                                                                                                                                                                30/106
  Installing       : elfutils-libelf-0.174-1.fb8.x86_64                                                                                                                                                     31/106
  Installing       : libcom_err-1.44.3-1.fb8.x86_64                                                                                                                                                         32/106
  Running scriptlet: libcom_err-1.44.3-1.fb8.x86_64                                                                                                                                                         32/106
  Installing       : lua-libs-5.3.4-10.fb8.x86_64                                                                                                                                                           33/106
  Installing       : chkconfig-1.11-1.fb8.x86_64                                                                                                                                                            34/106
  Installing       : libcap-ng-0.7.9-3.fb8.x86_64                                                                                                                                                           35/106
  Installing       : audit-libs-3.0-0.5.20180831git0047a6c.fb8.x86_64                                                                                                                                       36/106
  Running scriptlet: audit-libs-3.0-0.5.20180831git0047a6c.fb8.x86_64                                                                                                                                       36/106
  Installing       : libffi-3.1-17.fb8.x86_64                                                                                                                                                               37/106
  Installing       : p11-kit-0.23.14-2.fb8.x86_64                                                                                                                                                           38/106
  Running scriptlet: p11-kit-0.23.14-2.fb8.x86_64                                                                                                                                                           38/106
  Installing       : lz4-libs-1.8.1.2-4.fb8.x86_64                                                                                                                                                          39/106
  Installing       : libsemanage-2.8-3.1.fb8.x86_64                                                                                                                                                         40/106
  Installing       : libmpc-1.0.2-9.fb8.x86_64                                                                                                                                                              41/106
  Running scriptlet: libmpc-1.0.2-9.fb8.x86_64                                                                                                                                                              41/106
  Installing       : libdb-utils-5.3.28-33.fb8.x86_64                                                                                                                                                       42/106
  Installing       : libxml2-2.9.7-5.fb8.x86_64                                                                                                                                                             43/106
  Installing       : coreutils-common-8.30-4.fb8.x86_64                                                                                                                                                     44/106
  Running scriptlet: coreutils-common-8.30-4.fb8.x86_64                                                                                                                                                     44/106
  Installing       : readline-7.0-10.fb8.x86_64                                                                                                                                                             45/106
  Running scriptlet: readline-7.0-10.fb8.x86_64                                                                                                                                                             45/106
  Installing       : expat-2.2.5-3.fb8.x86_64                                                                                                                                                               46/106
  Installing       : libmetalink-0.1.3-7.fb8.x86_64                                                                                                                                                         47/106
  Installing       : keyutils-libs-1.5.10-6.fb8.x86_64                                                                                                                                                      48/106
  Installing       : libgpg-error-1.31-1.fb8.x86_64                                                                                                                                                         49/106
  Installing       : libgcrypt-1.8.3-2.fb8.x86_64                                                                                                                                                           50/106
  Running scriptlet: libgcrypt-1.8.3-2.fb8.x86_64                                                                                                                                                           50/106
  Installing       : libnghttp2-1.33.0-1.fb8.x86_64                                                                                                                                                         51/106
  Installing       : libpkgconf-1.4.2-1.fb8.x86_64                                                                                                                                                          52/106
  Installing       : pkgconf-1.4.2-1.fb8.x86_64                                                                                                                                                             53/106
  Installing       : pkgconf-pkg-config-1.4.2-1.fb8.x86_64                                                                                                                                                  54/106
  Installing       : libsigsegv-2.11-5.fb8.x86_64                                                                                                                                                           55/106
  Installing       : gawk-4.2.1-1.fb8.x86_64                                                                                                                                                                56/106
  Installing       : libsmartcols-2.32.1-6.fb8.x86_64                                                                                                                                                       57/106
  Running scriptlet: libsmartcols-2.32.1-6.fb8.x86_64                                                                                                                                                       57/106
  Installing       : libstdc++-8.2.1-3.3.fb8.x86_64                                                                                                                                                         58/106
  Running scriptlet: libstdc++-8.2.1-3.3.fb8.x86_64                                                                                                                                                         58/106
  Installing       : libtasn1-4.13-3.fb8.x86_64                                                                                                                                                             59/106
  Running scriptlet: libtasn1-4.13-3.fb8.x86_64                                                                                                                                                             59/106
  Installing       : p11-kit-trust-0.23.14-2.fb8.x86_64                                                                                                                                                     60/106
  Running scriptlet: p11-kit-trust-0.23.14-2.fb8.x86_64                                                                                                                                                     60/106
  Installing       : libverto-0.3.0-5.fb8.x86_64                                                                                                                                                            61/106
  Installing       : ncurses-6.1-5.20180224.fb8.x86_64                                                                                                                                                      62/106
  Installing       : pcre-8.42-4.fb8.x86_64                                                                                                                                                                 63/106
  Installing       : grep-3.1-6.fb8.x86_64                                                                                                                                                                  64/106
  Running scriptlet: grep-3.1-6.fb8.x86_64                                                                                                                                                                  64/106
  Installing       : openssl-libs-1:1.1.1-6.fb8.x86_64                                                                                                                                                      65/106
  Running scriptlet: openssl-libs-1:1.1.1-6.fb8.x86_64                                                                                                                                                      65/106
  Installing       : coreutils-8.30-4.fb8.x86_64                                                                                                                                                            66/106
  Installing       : crypto-policies-20181026-1.gitcc78cb7.fb8.noarch                                                                                                                                       67/106
  Running scriptlet: crypto-policies-20181026-1.gitcc78cb7.fb8.noarch                                                                                                                                       67/106
  Running scriptlet: ca-certificates-2018.2.24-6.fb8.noarch                                                                                                                                                 68/106
  Installing       : ca-certificates-2018.2.24-6.fb8.noarch                                                                                                                                                 68/106
  Running scriptlet: ca-certificates-2018.2.24-6.fb8.noarch                                                                                                                                                 68/106
  Installing       : libblkid-2.32.1-6.fb8.x86_64                                                                                                                                                           69/106
  Running scriptlet: libblkid-2.32.1-6.fb8.x86_64                                                                                                                                                           69/106
  Installing       : libmount-2.32.1-6.fb8.x86_64                                                                                                                                                           70/106
  Running scriptlet: libmount-2.32.1-6.fb8.x86_64                                                                                                                                                           70/106
  Installing       : krb5-libs-1.16.1-19.fb8.x86_64                                                                                                                                                         71/106
  Installing       : libtirpc-1.1.4-3.fb8.x86_64                                                                                                                                                            72/106
  Running scriptlet: libtirpc-1.1.4-3.fb8.x86_64                                                                                                                                                            72/106
  Installing       : libnsl2-1.2.0-2.20180605git4a062cf.fb8.x86_64                                                                                                                                          73/106
  Running scriptlet: libnsl2-1.2.0-2.20180605git4a062cf.fb8.x86_64                                                                                                                                          73/106
  Installing       : libcurl-minimal-7.61.1-5.fb8.x86_64                                                                                                                                                    74/106
  Installing       : curl-7.61.1-5.fb8.x86_64                                                                                                                                                               75/106
  Installing       : systemd-libs-239-8.fb8.x86_64                                                                                                                                                          76/106
  Running scriptlet: systemd-libs-239-8.fb8.x86_64                                                                                                                                                          76/106
  Installing       : libfdisk-2.32.1-6.fb8.x86_64                                                                                                                                                           77/106
  Running scriptlet: libfdisk-2.32.1-6.fb8.x86_64                                                                                                                                                           77/106
  Installing       : gzip-1.9-4.fb8.x86_64                                                                                                                                                                  78/106
  Running scriptlet: gzip-1.9-4.fb8.x86_64                                                                                                                                                                  78/106
  Installing       : cracklib-2.9.6-14.fb8.x86_64                                                                                                                                                           79/106
  Installing       : libpwquality-1.4.0-8.fb8.x86_64                                                                                                                                                        80/106
  Installing       : pam-1.3.1-3.fb8.x86_64                                                                                                                                                                 81/106
  Running scriptlet: pam-1.3.1-3.fb8.x86_64                                                                                                                                                                 81/106
  Installing       : shadow-utils-2:4.6-4.fb8.x86_64                                                                                                                                                        82/106
  Running scriptlet: libutempter-1.1.6-14.fb8.x86_64                                                                                                                                                        83/106
  Installing       : libutempter-1.1.6-14.fb8.x86_64                                                                                                                                                        83/106
  Installing       : libarchive-3.3.2-3.fb8.x86_64                                                                                                                                                          84/106
  Installing       : rpm-4.14.2-4.fb8.x86_64                                                                                                                                                                85/106
  Installing       : rpm-libs-4.14.2-4.fb8.x86_64                                                                                                                                                           86/106
  Running scriptlet: rpm-libs-4.14.2-4.fb8.x86_64                                                                                                                                                           86/106
  Installing       : rpm-plugin-selinux-4.14.2-4.fb8.x86_64                                                                                                                                                 87/106
  Installing       : kernel-headers-4.18.0-32.fb8.x86_64                                                                                                                                                    88/106
  Running scriptlet: glibc-headers-2.28-18.fb8.x86_64                                                                                                                                                       89/106
  Installing       : glibc-headers-2.28-18.fb8.x86_64                                                                                                                                                       89/106
  Installing       : libxcrypt-devel-4.1.1-4.fb8.x86_64                                                                                                                                                     90/106
  Installing       : glibc-devel-2.28-18.fb8.x86_64                                                                                                                                                         91/106
  Running scriptlet: glibc-devel-2.28-18.fb8.x86_64                                                                                                                                                         91/106
  Installing       : util-linux-2.32.1-6.fb8.x86_64                                                                                                                                                         92/106
  Running scriptlet: util-linux-2.32.1-6.fb8.x86_64                                                                                                                                                         92/106
  Installing       : binutils-2.30-49.fb8.x86_64                                                                                                                                                            93/106
  Running scriptlet: binutils-2.30-49.fb8.x86_64                                                                                                                                                            93/106
  Installing       : xz-5.2.4-2.fb8.x86_64                                                                                                                                                                  94/106
  Installing       : cpp-8.2.1-3.3.fb8.x86_64                                                                                                                                                               95/106
  Running scriptlet: cpp-8.2.1-3.3.fb8.x86_64                                                                                                                                                               95/106
  Installing       : tar-2:1.30-4.fb8.x86_64                                                                                                                                                                96/106
  Running scriptlet: tar-2:1.30-4.fb8.x86_64                                                                                                                                                                96/106
  Installing       : patch-2.7.6-7.fb8.x86_64                                                                                                                                                               97/106
  Installing       : isl-0.16.1-6.fb8.x86_64                                                                                                                                                                98/106
  Running scriptlet: isl-0.16.1-6.fb8.x86_64                                                                                                                                                                98/106
  Installing       : bzip2-1.0.6-26.fb8.x86_64                                                                                                                                                              99/106
  Installing       : unzip-6.0-38.fb8.x86_64                                                                                                                                                               100/106
  Installing       : diffutils-3.6-5.fb8.x86_64                                                                                                                                                            101/106
  Running scriptlet: diffutils-3.6-5.fb8.x86_64                                                                                                                                                            101/106
  Installing       : findutils-1:4.6.0-19.fb8.x86_64                                                                                                                                                       102/106
  Running scriptlet: findutils-1:4.6.0-19.fb8.x86_64                                                                                                                                                       102/106
  Installing       : libgomp-8.2.1-3.3.fb8.x86_64                                                                                                                                                          103/106
  Running scriptlet: libgomp-8.2.1-3.3.fb8.x86_64                                                                                                                                                          103/106
  Installing       : make-1:4.2.1-9.fb8.x86_64                                                                                                                                                             104/106
  Running scriptlet: make-1:4.2.1-9.fb8.x86_64                                                                                                                                                             104/106
  Installing       : cpio-2.12-8.fb8.x86_64                                                                                                                                                                105/106
  Installing       : which-2.21-10.fb8.x86_64                                                                                                                                                              106/106
  Running scriptlet: filesystem-3.8-2.fb8.x86_64                                                                                                                                                           106/106
  Running scriptlet: glibc-all-langpacks-2.28-18.fb8.x86_64                                                                                                                                                106/106
  Running scriptlet: glibc-common-2.28-18.fb8.x86_64                                                                                                                                                       106/106
  Running scriptlet: info-6.5-4.fb8.x86_64                                                                                                                                                                 106/106
  Verifying        : isl-0.16.1-6.fb8.x86_64                                                                                                                                                                 1/106
  Verifying        : libmpc-1.0.2-9.fb8.x86_64                                                                                                                                                               2/106
  Verifying        : audit-libs-3.0-0.5.20180831git0047a6c.fb8.x86_64                                                                                                                                        3/106
  Verifying        : basesystem-11-5.fb8.noarch                                                                                                                                                              4/106
  Verifying        : bash-4.4.19-6.fb8.x86_64                                                                                                                                                                5/106
  Verifying        : binutils-2.30-49.fb8.x86_64                                                                                                                                                             6/106
  Verifying        : bzip2-1.0.6-26.fb8.x86_64                                                                                                                                                               7/106
  Verifying        : bzip2-libs-1.0.6-26.fb8.x86_64                                                                                                                                                          8/106
  Verifying        : ca-certificates-2018.2.24-6.fb8.noarch                                                                                                                                                  9/106
  Verifying        : chkconfig-1.11-1.fb8.x86_64                                                                                                                                                            10/106
  Verifying        : coreutils-8.30-4.fb8.x86_64                                                                                                                                                            11/106
  Verifying        : coreutils-common-8.30-4.fb8.x86_64                                                                                                                                                     12/106
  Verifying        : cpio-2.12-8.fb8.x86_64                                                                                                                                                                 13/106
  Verifying        : cpp-8.2.1-3.3.fb8.x86_64                                                                                                                                                               14/106
  Verifying        : cracklib-2.9.6-14.fb8.x86_64                                                                                                                                                           15/106
  Verifying        : crypto-policies-20181026-1.gitcc78cb7.fb8.noarch                                                                                                                                       16/106
  Verifying        : curl-7.61.1-5.fb8.x86_64                                                                                                                                                               17/106
  Verifying        : diffutils-3.6-5.fb8.x86_64                                                                                                                                                             18/106
  Verifying        : elfutils-libelf-0.174-1.fb8.x86_64                                                                                                                                                     19/106
  Verifying        : expat-2.2.5-3.fb8.x86_64                                                                                                                                                               20/106
  Verifying        : filesystem-3.8-2.fb8.x86_64                                                                                                                                                            21/106
  Verifying        : findutils-1:4.6.0-19.fb8.x86_64                                                                                                                                                        22/106
  Verifying        : gawk-4.2.1-1.fb8.x86_64                                                                                                                                                                23/106
  Verifying        : glibc-2.28-18.fb8.x86_64                                                                                                                                                               24/106
  Verifying        : glibc-all-langpacks-2.28-18.fb8.x86_64                                                                                                                                                 25/106
  Verifying        : glibc-common-2.28-18.fb8.x86_64                                                                                                                                                        26/106
  Verifying        : glibc-devel-2.28-18.fb8.x86_64                                                                                                                                                         27/106
  Verifying        : glibc-headers-2.28-18.fb8.x86_64                                                                                                                                                       28/106
  Verifying        : gmp-1:6.1.2-8.fb8.x86_64                                                                                                                                                               29/106
  Verifying        : grep-3.1-6.fb8.x86_64                                                                                                                                                                  30/106
  Verifying        : gzip-1.9-4.fb8.x86_64                                                                                                                                                                  31/106
  Verifying        : info-6.5-4.fb8.x86_64                                                                                                                                                                  32/106
  Verifying        : kernel-headers-4.18.0-32.fb8.x86_64                                                                                                                                                    33/106
  Verifying        : keyutils-libs-1.5.10-6.fb8.x86_64                                                                                                                                                      34/106
  Verifying        : krb5-libs-1.16.1-19.fb8.x86_64                                                                                                                                                         35/106
  Verifying        : libacl-2.2.53-1.fb8.x86_64                                                                                                                                                             36/106
  Verifying        : libarchive-3.3.2-3.fb8.x86_64                                                                                                                                                          37/106
  Verifying        : libattr-2.4.48-3.fb8.x86_64                                                                                                                                                            38/106
  Verifying        : libblkid-2.32.1-6.fb8.x86_64                                                                                                                                                           39/106
  Verifying        : libcap-2.25-9.fb8.x86_64                                                                                                                                                               40/106
  Verifying        : libcap-ng-0.7.9-3.fb8.x86_64                                                                                                                                                           41/106
  Verifying        : libcom_err-1.44.3-1.fb8.x86_64                                                                                                                                                         42/106
  Verifying        : libcurl-minimal-7.61.1-5.fb8.x86_64                                                                                                                                                    43/106
  Verifying        : libdb-5.3.28-33.fb8.x86_64                                                                                                                                                             44/106
  Verifying        : libdb-utils-5.3.28-33.fb8.x86_64                                                                                                                                                       45/106
  Verifying        : libfdisk-2.32.1-6.fb8.x86_64                                                                                                                                                           46/106
  Verifying        : libffi-3.1-17.fb8.x86_64                                                                                                                                                               47/106
  Verifying        : libgcc-8.2.1-3.3.fb8.x86_64                                                                                                                                                            48/106
  Verifying        : libgcrypt-1.8.3-2.fb8.x86_64                                                                                                                                                           49/106
  Verifying        : libgomp-8.2.1-3.3.fb8.x86_64                                                                                                                                                           50/106
  Verifying        : libgpg-error-1.31-1.fb8.x86_64                                                                                                                                                         51/106
  Verifying        : libmetalink-0.1.3-7.fb8.x86_64                                                                                                                                                         52/106
  Verifying        : libmount-2.32.1-6.fb8.x86_64                                                                                                                                                           53/106
  Verifying        : libnghttp2-1.33.0-1.fb8.x86_64                                                                                                                                                         54/106
  Verifying        : libnsl2-1.2.0-2.20180605git4a062cf.fb8.x86_64                                                                                                                                          55/106
  Verifying        : libpkgconf-1.4.2-1.fb8.x86_64                                                                                                                                                          56/106
  Verifying        : libpwquality-1.4.0-8.fb8.x86_64                                                                                                                                                        57/106
  Verifying        : libselinux-2.8-5.fb8.x86_64                                                                                                                                                            58/106
  Verifying        : libsemanage-2.8-3.1.fb8.x86_64                                                                                                                                                         59/106
  Verifying        : libsepol-2.8-1.fb8.x86_64                                                                                                                                                              60/106
  Verifying        : libsigsegv-2.11-5.fb8.x86_64                                                                                                                                                           61/106
  Verifying        : libsmartcols-2.32.1-6.fb8.x86_64                                                                                                                                                       62/106
  Verifying        : libstdc++-8.2.1-3.3.fb8.x86_64                                                                                                                                                         63/106
  Verifying        : libtasn1-4.13-3.fb8.x86_64                                                                                                                                                             64/106
  Verifying        : libtirpc-1.1.4-3.fb8.x86_64                                                                                                                                                            65/106
  Verifying        : libutempter-1.1.6-14.fb8.x86_64                                                                                                                                                        66/106
  Verifying        : libuuid-2.32.1-6.fb8.x86_64                                                                                                                                                            67/106
  Verifying        : libverto-0.3.0-5.fb8.x86_64                                                                                                                                                            68/106
  Verifying        : libxcrypt-4.1.1-4.fb8.x86_64                                                                                                                                                           69/106
  Verifying        : libxcrypt-devel-4.1.1-4.fb8.x86_64                                                                                                                                                     70/106
  Verifying        : libxml2-2.9.7-5.fb8.x86_64                                                                                                                                                             71/106
  Verifying        : lua-libs-5.3.4-10.fb8.x86_64                                                                                                                                                           72/106
  Verifying        : lz4-libs-1.8.1.2-4.fb8.x86_64                                                                                                                                                          73/106
  Verifying        : make-1:4.2.1-9.fb8.x86_64                                                                                                                                                              74/106
  Verifying        : mpfr-3.1.6-1.fb8.x86_64                                                                                                                                                                75/106
  Verifying        : ncurses-6.1-5.20180224.fb8.x86_64                                                                                                                                                      76/106
  Verifying        : ncurses-base-6.1-5.20180224.fb8.noarch                                                                                                                                                 77/106
  Verifying        : ncurses-libs-6.1-5.20180224.fb8.x86_64                                                                                                                                                 78/106
  Verifying        : openssl-libs-1:1.1.1-6.fb8.x86_64                                                                                                                                                      79/106
  Verifying        : p11-kit-0.23.14-2.fb8.x86_64                                                                                                                                                           80/106
  Verifying        : p11-kit-trust-0.23.14-2.fb8.x86_64                                                                                                                                                     81/106
  Verifying        : pam-1.3.1-3.fb8.x86_64                                                                                                                                                                 82/106
  Verifying        : patch-2.7.6-7.fb8.x86_64                                                                                                                                                               83/106
  Verifying        : pcre-8.42-4.fb8.x86_64                                                                                                                                                                 84/106
  Verifying        : pcre2-10.31-11.fb8.x86_64                                                                                                                                                              85/106
  Verifying        : pkgconf-1.4.2-1.fb8.x86_64                                                                                                                                                             86/106
  Verifying        : pkgconf-m4-1.4.2-1.fb8.noarch                                                                                                                                                          87/106
  Verifying        : pkgconf-pkg-config-1.4.2-1.fb8.x86_64                                                                                                                                                  88/106
  Verifying        : popt-1.16-14.fb8.x86_64                                                                                                                                                                89/106
  Verifying        : readline-7.0-10.fb8.x86_64                                                                                                                                                             90/106
  Verifying        : redhat-release-8.0-0.34.fb8.x86_64                                                                                                                                                     91/106
  Verifying        : rpm-4.14.2-4.fb8.x86_64                                                                                                                                                                92/106
  Verifying        : rpm-libs-4.14.2-4.fb8.x86_64                                                                                                                                                           93/106
  Verifying        : rpm-plugin-selinux-4.14.2-4.fb8.x86_64                                                                                                                                                 94/106
  Verifying        : sed-4.5-1.fb8.x86_64                                                                                                                                                                   95/106
  Verifying        : setup-2.12.2-1.fb8.noarch                                                                                                                                                              96/106
  Verifying        : shadow-utils-2:4.6-4.fb8.x86_64                                                                                                                                                        97/106
  Verifying        : systemd-libs-239-8.fb8.x86_64                                                                                                                                                          98/106
  Verifying        : tar-2:1.30-4.fb8.x86_64                                                                                                                                                                99/106
  Verifying        : tzdata-2018e-2.fb8.noarch                                                                                                                                                             100/106
  Verifying        : unzip-6.0-38.fb8.x86_64                                                                                                                                                               101/106
  Verifying        : util-linux-2.32.1-6.fb8.x86_64                                                                                                                                                        102/106
  Verifying        : which-2.21-10.fb8.x86_64                                                                                                                                                              103/106
  Verifying        : xz-5.2.4-2.fb8.x86_64                                                                                                                                                                 104/106
  Verifying        : xz-libs-5.2.4-2.fb8.x86_64                                                                                                                                                            105/106
  Verifying        : zlib-1.2.11-10.fb8.x86_64                                                                                                                                                             106/106

Installed:
  isl-0.16.1-6.fb8.x86_64                      libmpc-1.0.2-9.fb8.x86_64                           bash-4.4.19-6.fb8.x86_64                               binutils-2.30-49.fb8.x86_64
  bzip2-1.0.6-26.fb8.x86_64                    coreutils-8.30-4.fb8.x86_64                         cpio-2.12-8.fb8.x86_64                                 cpp-8.2.1-3.3.fb8.x86_64
  diffutils-3.6-5.fb8.x86_64                   findutils-1:4.6.0-19.fb8.x86_64                     gawk-4.2.1-1.fb8.x86_64                                glibc-devel-2.28-18.fb8.x86_64
  grep-3.1-6.fb8.x86_64                        gzip-1.9-4.fb8.x86_64                               info-6.5-4.fb8.x86_64                                  libgomp-8.2.1-3.3.fb8.x86_64
  make-1:4.2.1-9.fb8.x86_64                    patch-2.7.6-7.fb8.x86_64                            redhat-release-8.0-0.34.fb8.x86_64                     rpm-4.14.2-4.fb8.x86_64
  sed-4.5-1.fb8.x86_64                         shadow-utils-2:4.6-4.fb8.x86_64                     tar-2:1.30-4.fb8.x86_64                                unzip-6.0-38.fb8.x86_64
  util-linux-2.32.1-6.fb8.x86_64               which-2.21-10.fb8.x86_64                            xz-5.2.4-2.fb8.x86_64                                  audit-libs-3.0-0.5.20180831git0047a6c.fb8.x86_64
  basesystem-11-5.fb8.noarch                   bzip2-libs-1.0.6-26.fb8.x86_64                      ca-certificates-2018.2.24-6.fb8.noarch                 chkconfig-1.11-1.fb8.x86_64
  coreutils-common-8.30-4.fb8.x86_64           cracklib-2.9.6-14.fb8.x86_64                        crypto-policies-20181026-1.gitcc78cb7.fb8.noarch       curl-7.61.1-5.fb8.x86_64
  elfutils-libelf-0.174-1.fb8.x86_64           expat-2.2.5-3.fb8.x86_64                            filesystem-3.8-2.fb8.x86_64                            glibc-2.28-18.fb8.x86_64
  glibc-all-langpacks-2.28-18.fb8.x86_64       glibc-common-2.28-18.fb8.x86_64                     glibc-headers-2.28-18.fb8.x86_64                       gmp-1:6.1.2-8.fb8.x86_64
  kernel-headers-4.18.0-32.fb8.x86_64          keyutils-libs-1.5.10-6.fb8.x86_64                   krb5-libs-1.16.1-19.fb8.x86_64                         libacl-2.2.53-1.fb8.x86_64
  libarchive-3.3.2-3.fb8.x86_64                libattr-2.4.48-3.fb8.x86_64                         libblkid-2.32.1-6.fb8.x86_64                           libcap-2.25-9.fb8.x86_64
  libcap-ng-0.7.9-3.fb8.x86_64                 libcom_err-1.44.3-1.fb8.x86_64                      libcurl-minimal-7.61.1-5.fb8.x86_64                    libdb-5.3.28-33.fb8.x86_64
  libdb-utils-5.3.28-33.fb8.x86_64             libfdisk-2.32.1-6.fb8.x86_64                        libffi-3.1-17.fb8.x86_64                               libgcc-8.2.1-3.3.fb8.x86_64
  libgcrypt-1.8.3-2.fb8.x86_64                 libgpg-error-1.31-1.fb8.x86_64                      libmetalink-0.1.3-7.fb8.x86_64                         libmount-2.32.1-6.fb8.x86_64
  libnghttp2-1.33.0-1.fb8.x86_64               libnsl2-1.2.0-2.20180605git4a062cf.fb8.x86_64       libpkgconf-1.4.2-1.fb8.x86_64                          libpwquality-1.4.0-8.fb8.x86_64
  libselinux-2.8-5.fb8.x86_64                  libsemanage-2.8-3.1.fb8.x86_64                      libsepol-2.8-1.fb8.x86_64                              libsigsegv-2.11-5.fb8.x86_64
  libsmartcols-2.32.1-6.fb8.x86_64             libstdc++-8.2.1-3.3.fb8.x86_64                      libtasn1-4.13-3.fb8.x86_64                             libtirpc-1.1.4-3.fb8.x86_64
  libutempter-1.1.6-14.fb8.x86_64              libuuid-2.32.1-6.fb8.x86_64                         libverto-0.3.0-5.fb8.x86_64                            libxcrypt-4.1.1-4.fb8.x86_64
  libxcrypt-devel-4.1.1-4.fb8.x86_64           libxml2-2.9.7-5.fb8.x86_64                          lua-libs-5.3.4-10.fb8.x86_64                           lz4-libs-1.8.1.2-4.fb8.x86_64
  mpfr-3.1.6-1.fb8.x86_64                      ncurses-6.1-5.20180224.fb8.x86_64                   ncurses-base-6.1-5.20180224.fb8.noarch                 ncurses-libs-6.1-5.20180224.fb8.x86_64
  openssl-libs-1:1.1.1-6.fb8.x86_64            p11-kit-0.23.14-2.fb8.x86_64                        p11-kit-trust-0.23.14-2.fb8.x86_64                     pam-1.3.1-3.fb8.x86_64
  pcre-8.42-4.fb8.x86_64                       pcre2-10.31-11.fb8.x86_64                           pkgconf-1.4.2-1.fb8.x86_64                             pkgconf-m4-1.4.2-1.fb8.noarch
  pkgconf-pkg-config-1.4.2-1.fb8.x86_64        popt-1.16-14.fb8.x86_64                             readline-7.0-10.fb8.x86_64                             rpm-libs-4.14.2-4.fb8.x86_64
  rpm-plugin-selinux-4.14.2-4.fb8.x86_64       setup-2.12.2-1.fb8.noarch                           systemd-libs-239-8.fb8.x86_64                          tzdata-2018e-2.fb8.noarch
  xz-libs-5.2.4-2.fb8.x86_64                   zlib-1.2.11-10.fb8.x86_64

Complete!
Finish: dnf install
Start: creating root cache
Finish: creating root cache
Finish: chroot init
INFO: Installed packages:
Start: shell
[root@990c9a5364794a4788e69f8b4eb784ff /]#

ビルド環境としてのmock

ちょっと依存関係の解決が必要でまだ解決してないので綺麗なビルド環境としては使えません(´・ω・`) 

Error: 
 Problem: conflicting requests
  - nothing provides libgcc_s.so.1 needed by gcc-8.2.1-3.3.fb8.x86_64
ERROR: Command failed: 
 # /usr/bin/dnf --installroot /var/lib/mock/foobar8/root/ --releasever fb --disableplugin=local --setopt=deltarpm=False install bash bzip2 coreutils cpio diffutils findutils gawk grep gzip info make patch redhat-release sed shadow-utils tar unzip util-linux which xz rpm binutils glibc-devel libgomp isl libmpc cpp gcc
Foobar Appstream                                                                                                                                                                   3.0 kB/s | 3.0 kB     00:01    
Foobar BaseOS                                                                                                                                                                      3.0 kB/s | 3.0 kB     00:01    
Error: 
 Problem: conflicting requests
  - nothing provides libgcc_s.so.1 needed by gcc-8.2.1-3.3.fb8.x86_64

まとめ

RHELクローン的な物を作る遊びでした。段階を踏んで自分自身で自分をビルドしていくというブートストラップ方式はコンパイラ的な感じですね。

Linuxカーネルソースに付属のscripts/の探索

$
0
0

この記事はLinux Advent Calendar 2018の12日目の記事です。

カーネルソースコードに含まれるscripts/を探索してみます。カーネルのビルド中で使うようなものもあるし、それ以外の時に使うものもあります。今回は後者の方を探してみましょう。

diffconfig

ファイルはsrcipts/diffconfigです。カーネルの.configのdiffを見やすくするツールです。

普通にdiffを取るとこんな感じです。

masami@saga:~$ diff -u /boot/config-4.19.9-300.fc29.x86_64 /boot/config-4.19.12-301.fc29.x86_64
--- /boot/config-4.19.9-300.fc29.x86_64 2018-12-14 02:44:50.000000000 +0900
+++ /boot/config-4.19.12-301.fc29.x86_64        2018-12-24 11:20:56.000000000 +0900
@@ -1,10 +1,10 @@
 #
 # Automatically generated file; DO NOT EDIT.
-# Linux/x86_64 4.19.9-300.fc29.x86_64 Kernel Configuration
+# Linux/x86_64 4.19.12-301.fc29.x86_64 Kernel Configuration
 #
 
 #
-# Compiler: gcc (GCC) 8.2.1 20181105 (Red Hat 8.2.1-5)
+# Compiler: gcc (GCC) 8.2.1 20181215 (Red Hat 8.2.1-6)
 #
 CONFIG_CC_IS_GCC=y
 CONFIG_GCC_VERSION=80201
@@ -20,7 +20,7 @@
 # CONFIG_COMPILE_TEST is not set
 CONFIG_LOCALVERSION=""
 # CONFIG_LOCALVERSION_AUTO is not set
-CONFIG_BUILD_SALT="4.19.9-300.fc29.x86_64"
+CONFIG_BUILD_SALT="4.19.12-301.fc29.x86_64"
 CONFIG_HAVE_KERNEL_GZIP=y
 CONFIG_HAVE_KERNEL_BZIP2=y
 CONFIG_HAVE_KERNEL_LZMA=y
@@ -93,6 +93,7 @@
 CONFIG_VIRT_CPU_ACCOUNTING=y
 CONFIG_VIRT_CPU_ACCOUNTING_GEN=y
 CONFIG_IRQ_TIME_ACCOUNTING=y
+CONFIG_HAVE_SCHED_AVG_IRQ=y
 CONFIG_BSD_PROCESS_ACCT=y
 CONFIG_BSD_PROCESS_ACCT_V3=y
 CONFIG_TASKSTATS=y
@@ -4655,7 +4656,7 @@
 # CONFIG_DVB_MMAP is not set
 CONFIG_DVB_NET=y
 CONFIG_TTPCI_EEPROM=m
-CONFIG_DVB_MAX_ADAPTERS=8
+CONFIG_DVB_MAX_ADAPTERS=16
 CONFIG_DVB_DYNAMIC_MINORS=y
 # CONFIG_DVB_DEMUX_SECTION_LOSS_LOG is not set
 # CONFIG_DVB_ULE_DEBUG is not set

diifconfigを使うとこのようになります。

masami@saga:~$ ./linux-kernel/scripts/diffconfig /boot/config-4.19.9-300.fc29.x86_64 /boot/config-4.19.12-301.fc29.x86_64
 BUILD_SALT "4.19.9-300.fc29.x86_64" -> "4.19.12-301.fc29.x86_64"
 DVB_MAX_ADAPTERS 8 -> 16
+HAVE_SCHED_AVG_IRQ y

通常のdiffと違って何がどう変わったのかが見やすくなりますね。

objdiff

ファイルはscripts/objdiffです。これはobjectファイル間のdiffを取ります。カーネル以外でも使えます。

例えば、コミット間で以下のようなファイルの変更が有った場合、

masami@saga:~/codes/objdiff-test (test %)$ git diff master a.c
diff --git a/a.c b/a.c
index ab39f2e..a0068b8 100644
--- a/a.c
+++ b/a.c
@@ -7,7 +7,7 @@ struct test {
 int main(int argc, char **argv)
 {
        struct test t = {
-               .s = "hello",
+               .s = "hello\n",
        };
 
        printf("%s\n", t.s);

こんな感じになります。

masami@saga:~/codes/objdiff-test (test %)$ ~/linux-kernel/scripts/objdiff diff
which: no colordiff in (/usr/share/Modules/bin:/usr/lib64/ccache:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/home/masami/bin:/home/masami/.gem/ruby/2.2.0/bin:/home/masami/go/bin:/home/masami/ltp:/home/masami/ltp/bin:/home/masami/.local/bin:/home/masami/bin:/home/masami/bin:/home/masami/.gem/ruby/2.2.0/bin:/home/masami/go/bin:/home/masami/ltp:/home/masami/ltp/bin:/home/masami/.local/bin:/home/masami/bin)
diff -Nurd /home/masami/codes/objdiff-test/.tmp_objdiff/b5b839d/a.dis /home/masami/codes/objdiff-test/.tmp_objdiff/374a3c2/a.dis
--- /home/masami/codes/objdiff-test/.tmp_objdiff/b5b839d/a.dis  2018-12-30 23:36:28.063937470 +0900
+++ /home/masami/codes/objdiff-test/.tmp_objdiff/374a3c2/a.dis  2018-12-30 23:37:13.345071254 +0900
@@ -10,8 +10,8 @@
 :      48 81 ec 10 01 00 00    sub    $0x110,%rsp
 :      89 bd fc fe ff ff       mov    %edi,-0x104(%rbp)
 :      48 89 b5 f0 fe ff ff    mov    %rsi,-0x110(%rbp)
-:      48 b8 68 65 6c 6c 6f    movabs $0x6f6c6c6568,%rax
-:      00 00 00 
+:      48 b8 68 65 6c 6c 6f    movabs $0xa6f6c6c6568,%rax
+:      0a 00 00 
 :      ba 00 00 00 00          mov    $0x0,%edx
 :      48 89 85 00 ff ff ff    mov    %rax,-0x100(%rbp)
 :      48 89 95 08 ff ff ff    mov    %rdx,-0xf8(%rbp)
Binary files /home/masami/codes/objdiff-test/.tmp_objdiff/b5b839d/a.stripped and /home/masami/codes/objdiff-test/.tmp_objdiff/374a3c2/a.stripped differ

bootgraph.pl

ファイルはscripts/bootgraph.plです。 カーネルの起動時にprintk.time=1とinitcall_debugをカーネルコマンドラインオプションに付けて起動する必要があります。dmesgの経過時間のところから何にどれだけ時間を使ったかを見る感じですね。

全体像はこんな感じです。

f:id:masami256:20181230224632p:plain
boot graph

拡大するとこうなってます。

f:id:masami256:20181230225324p:plain
bootgraph2

show_delta

ファイルはscripts/show_deltaです。 これも実行時間の計測ですね。前回のprintkの時刻から今回までの時間を表示してくれます。

('[0.280670 < 0.003444 >] pci 0000:00:06.0: reg 0x20: [io  0xc0a0-0xc0bf]\n',)
('[0.281820 < 0.001150 >] pci 0000:00:06.1: [8086:2935] type 00 class 0x0c0300\n',)
('[0.306576 < 0.000002 >] initcall xen_setup_shutdown_event+0x0/0x30 returned -19 after 0 usecs\n',)
('[0.307587 < 0.000000 >] calling  power_supply_class_init+0x0/0x40 @ 1\n',)
('[0.309641 < 0.000000 >] NetLabel:  domain hash size = 128\n',)
('[0.309642 < 0.000001 >] NetLabel:  protocols = UNLABELED CIPSOv4 CALIPSO\n',)
('[0.359181 < 0.000003 >] initcall proc_version_init+0x0/0x22 returned 0 after 1 usecs\n',)
('[0.359707 < 0.000090 >] pnp 00:02: Plug and Play ACPI device, IDs PNP0f13 (active)\n',)
('[0.365880 < 0.000002 >] calling  thermal_init+0x0/0xe1 @ 1\n',)
('[0.370580 < 0.000040 >] initcall intel_pmc_ipc_init+0x0/0x5f returned 0 after 37 usecs\n',)
('[0.370701 < 0.000006 >] initcall ipv4_offload_init+0x0/0x74 returned 0 after 0 usecs\n',)
('[0.890552 < 0.000001 >] calling  crypto_module_init+0x0/0x11 @ 1\n',)

faddr2line

ファイルはscripts/faddr2lineです。oopsにある関数名+オフセット/関数サイズからそれがどのファイルの何行目かを調べることができます。自作したカーネルモジュールでは使えなかったけど。。

こんな風に使えます。

masami@kerntest:~/a2l$ ~/linux-kernel/scripts/faddr2line ~/linux-kernel/vmlinux do_init_module+0x22/0x210
do_init_module+0x22/0x210:
do_init_module at kernel/module.c:3436

decode_stacktrace.sh

ファイルはscripts/decode_stacktrace.shです。カーネルoopsを読み込んでデコードしてくれます。使い方はlinux-3.16で入ったdecode_stacktrace.shを試してみる - φ(・・*)ゞ ウーン カーネルとか弄ったりのメモを参照してください。

decodecode

ファイルはscripts/decodecodeです。decode_stacktrace.shと似たような感じです。使い方はlinuxカーネルデバッグめも decodecodeでoopsの機械語列を逆アセンブル - φ(・・*)ゞ ウーン カーネルとか弄ったりのメモを参照してください。

ver_linux

ファイルはscripts/ver_linuxです。カーネル、ビルドとか諸々のツール類の情報表示します。

masami@saga:~/linux-kernel (test %)$ ./scripts/ver_linux 
If some fields are empty or look unusual you may have an old version.
Compare to the current minimal requirements in Documentation/Changes.

Linux saga 4.19.12-301.fc29.x86_64 #1 SMP Mon Dec 24 01:58:57 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

GNU Make                4.2.1
Binutils                2.31.1
Util-linux              2.32.1
Mount                   2.32.1
Module-init-tools       25
E2fsprogs               1.44.3
Xfsprogs                4.17.0
Quota-tools             4.04
PPP                     2.4.7
Nfs-utils               2.3.3
Linux C Library         2.28
Dynamic linker (ldd)    2.28
Linux C++ Library       6.0.25
Procps                  3.3.15
Net-tools               2.10
Kbd                     2.0.4
Console-tools           2.0.4
Sh-utils                8.30
Udev                    239
Wireless-tools          29
Modules Loaded          binfmt_misc bridge coretemp crc32c_intel crc32_pclmul crct10dif_pclmul devlink drm drm_kms_helper e1000e ebtable_filter ebtable_nat ebtables fat fuse ghash_clmulni_intel hid_logitech_dj hid_logitech_hidpp i2c_algo_bit i2c_i801 intel_cstate intel_powerclamp intel_rapl intel_rapl_perf intel_uncore intel_wmi_thunderbolt ip6table_filter ip6table_mangle ip6table_nat ip6table_raw ip6_tables ip6table_security ip6t_REJECT ip6t_rpfilter ip_set iptable_mangle iptable_nat iptable_raw iptable_security ipt_MASQUERADE irqbypass iTCO_vendor_support iTCO_wdt kvm kvm_intel libcrc32c llc lpc_ich mei mei_me mxm_wmi nf_conntrack nf_conntrack_broadcast nf_conntrack_netbios_ns nf_defrag_ipv4 nf_defrag_ipv6 nf_nat nf_nat_ipv4 nf_nat_ipv6 nfnetlink nf_reject_ipv6 nouveau pcc_cpufreq snd snd_hda_codec snd_hda_codec_ca0132 snd_hda_codec_hdmi snd_hda_core snd_hda_intel snd_hwdep snd_pcm snd_seq snd_seq_device snd_seq_dummy snd_timer soundcore stp sunrpc tap ttm tun uas usb_storage vfat vhost vhost_net video wmi x86_pkg_temp_thermal xfs xt_CHECKSUM xt_conntrack xt_CT

spelling.txt

ファイルはscripts/spelling.txtです。このファイルは単体で使うと言うか、checkpatch.plでスペルチェックに使っています。ファイルの書式はこんな感じで、左側がよく有る間違いで右側が正解です。

abov||above

まとめ

他にもスクリプトは色々有ります。たとえばscripts/gdbカーネルgdbデバッグする時のスクリプトで.gdbinitで add-auto-load-safe-path /home/masami/codes/slmb/scripts/gdb/vmlinux-gdb.pyという感じに読み込ませます。

ということで、なんとなくscripts/を探索してみました( ´ー`)フゥー...

FedoraのRISC-V portを試す

$
0
0

FedoraRISC-VポートはPorting Fedora to RISC-Vで記事になってて気になってたのと、RISC-V原典オープンアーキテクチャのススメを買ったしarch/riscvを読んでみようかな〜ということでqemuで動かしてみました。

(´-`).。oO(FedoraRISC-V関連の情報はArchitectures/RISC-V - Fedora Project Wikiに集まるんだと思います。

qemuのセットアップ

FedoraのドキュメントとしてはArchitectures/RISC-V/Installing - Fedora Project Wikiだと思うんですが、ナイトリービルドのサーバが繋がらなくなってました。ということで、QEMUDocumentation/Platforms/RISCV - QEMUを参考にしました。Fedoraqemurisc-vが使えるのでqemu-system-riscvパッケージをインストールするだけでOKです。

あとはドキュメントの通りでできます。

boot

起動もドキュメントの通りにやればOKです。こんな感じでログインプロンプトがでます。

f:id:masami256:20181231134107p:plain
riscv

初期状態でsshdが動いていて、rootでのsshも可能になっています。

RISC-V原典  オープンアーキテクチャのススメ

RISC-V原典 オープンアーキテクチャのススメ

Viewing all 191 articles
Browse latest View live