[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: acardide?



>ちなみに, 純粋に alignment の問題とすれば, 以前の kernel でも,
>userland program からしかるべき alignment の buffer に raw device から 
>i/o したら, 同じように buffer の後が壊れるんでしょうか.

おもしろそうなので試してみました。壊れますねー。
12月中旬のカーネルでも、最新のカーネルでも同様です。
4n でないアドレスの場合には壊れないのが新たな発見でした。


#include <unistd.h>

#define roundup(x, y) ((((x)+((y)-1))/(y))*(y))

int fd;
char buf[1024];
char backup[1024];

main()
{
        int off;

        fd = open("/dev/rwd0c", 0);
        if (fd < 0)
                err(0, "open");

        read(fd, backup, 512);
        for (off = 0; off <= 64; off++)
                f(off);
}

f(off)
        int off;
{
        int i;
        char *p = (char *)roundup((long)buf, 32) + off;

        memset(buf, 0xaa, 1024);

        lseek(fd, 0, 0);
        read(fd, p, 512);
        if (bcmp(p, backup, 512) != 0)
                abort();

        printf("p = %p, off = %d: ", p, off);

        for (i = 0; i < 16; i++)
                printf("%02x ", p[512 + i]);
        printf("\n");
}

実行結果 (0xaaでない部分は再現しません)
p = 0x1824fc0, off = 0: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa 
p = 0x1824fc1, off = 1: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa 
p = 0x1824fc2, off = 2: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa 
p = 0x1824fc3, off = 3: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa 
p = 0x1824fc4, off = 4: 18 91 01 03 00 00 00 00 08 91 01 03 00 00 00 00 
p = 0x1824fc5, off = 5: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa 
p = 0x1824fc6, off = 6: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa 
p = 0x1824fc7, off = 7: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa 
p = 0x1824fc8, off = 8: 00 00 00 00 10 91 01 03 00 00 00 00 c8 01 00 80 
p = 0x1824fc9, off = 9: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa 
p = 0x1824fca, off = 10: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa 
p = 0x1824fcb, off = 11: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa 
p = 0x1824fcc, off = 12: 48 90 01 03 00 00 00 00 cc 01 00 80 00 00 00 00 
p = 0x1824fcd, off = 13: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa 
p = 0x1824fce, off = 14: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa 
p = 0x1824fcf, off = 15: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa 
p = 0x1824fd0, off = 16: 00 00 00 00 d0 01 00 80 00 00 00 00 00 00 e3 02 
p = 0x1824fd1, off = 17: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa 
p = 0x1824fd2, off = 18: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa 
p = 0x1824fd3, off = 19: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa 
p = 0x1824fd4, off = 20: 00 90 01 03 00 00 00 00 60 90 01 03 aa aa aa aa 
p = 0x1824fd5, off = 21: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa 
p = 0x1824fd6, off = 22: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa 
p = 0x1824fd7, off = 23: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa 
p = 0x1824fd8, off = 24: 00 00 00 00 00 00 e3 02 aa aa aa aa aa aa aa aa 
p = 0x1824fd9, off = 25: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa 
p = 0x1824fda, off = 26: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa 
p = 0x1824fdb, off = 27: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa 
p = 0x1824fdc, off = 28: 00 90 01 03 aa aa aa aa aa aa aa aa aa aa aa aa 
p = 0x1824fdd, off = 29: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa 
p = 0x1824fde, off = 30: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa 
p = 0x1824fdf, off = 31: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa 
p = 0x1824fe0, off = 32: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa 
p = 0x1824fe1, off = 33: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa 
p = 0x1824fe2, off = 34: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa 
p = 0x1824fe3, off = 35: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa 
p = 0x1824fe4, off = 36: 38 91 01 03 00 00 00 00 28 91 01 03 00 00 00 00 
p = 0x1824fe5, off = 37: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa 
p = 0x1824fe6, off = 38: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa 
p = 0x1824fe7, off = 39: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa 
p = 0x1824fe8, off = 40: 00 00 00 00 30 91 01 03 00 00 00 00 e8 01 00 80 
p = 0x1824fe9, off = 41: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa 
p = 0x1824fea, off = 42: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa 
p = 0x1824feb, off = 43: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa 
p = 0x1824fec, off = 44: 68 90 01 03 00 00 00 00 ec 01 00 80 00 00 00 00 
p = 0x1824fed, off = 45: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa 
p = 0x1824fee, off = 46: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa 
p = 0x1824fef, off = 47: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa 
p = 0x1824ff0, off = 48: 00 00 00 00 f0 01 00 80 00 00 00 00 00 00 e3 02 
p = 0x1824ff1, off = 49: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa 
p = 0x1824ff2, off = 50: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa 
p = 0x1824ff3, off = 51: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa 
p = 0x1824ff4, off = 52: 00 90 01 03 00 00 00 00 80 90 01 03 aa aa aa aa 
p = 0x1824ff5, off = 53: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa 
p = 0x1824ff6, off = 54: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa 
p = 0x1824ff7, off = 55: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa 
p = 0x1824ff8, off = 56: 00 00 00 00 80 90 01 03 aa aa aa aa aa aa aa aa 
p = 0x1824ff9, off = 57: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa 
p = 0x1824ffa, off = 58: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa 
p = 0x1824ffb, off = 59: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa 
p = 0x1824ffc, off = 60: 00 90 01 03 aa aa aa aa aa aa aa aa aa aa aa aa 
p = 0x1824ffd, off = 61: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa 
p = 0x1824ffe, off = 62: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa 
p = 0x1824fff, off = 63: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa 
p = 0x1825000, off = 64: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa