看板 FB_security 關於我們 聯絡資訊
Dag-Erling Sm=C3=B8rgrav <des@des.no> writes: > If you give me a couple of days, I'll try to come up with a patch that > collects and stores attach times during boot so we can gather and > analyse real data. Here's the patch, as a superset of Pawel's. The output looks like this: des@crashbox ~% sysctl -b hw.attachtimes| hexdump -C 00000000 72 61 6d 30 00 00 00 00 00 00 00 00 00 00 00 00 |ram0..........= ...| 00000010 00 00 00 00 00 00 00 00 00 00 00 00 00 01 24 53 |..............= $S| 00000020 63 70 75 30 00 00 00 00 00 00 00 00 00 00 00 00 |cpu0..........= ...| 00000030 00 00 00 00 00 00 00 00 00 00 00 00 01 4d 6c cb |.............M= l.| 00000040 63 70 75 31 00 00 00 00 00 00 00 00 00 00 00 00 |cpu1..........= ...| 00000050 00 00 00 00 00 00 00 00 00 00 00 00 01 4d da b6 |.............M= ...| 00000060 61 74 74 69 6d 65 72 30 00 00 00 00 00 00 00 00 |attimer0......= ...| 00000070 00 00 00 00 00 00 00 00 00 00 00 00 04 59 70 8f |.............Y= p.| [...] where the first 24 bytes of each record contain the device name (dev->nameunit) and the last eight bytes contain d(cyclecount) for device_attach() as a big-endian uint64_t. DES --=20 Dag-Erling Sm=C3=B8rgrav - des@des.no Index: sys/dev/random/randomdev_soft.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- sys/dev/random/randomdev_soft.c (revision 240914) +++ sys/dev/random/randomdev_soft.c (working copy) @@ -303,7 +303,7 @@ KASSERT(origin =3D=3D RANDOM_START || origin =3D=3D RANDOM_WRITE || origin =3D=3D RANDOM_KEYBOARD || origin =3D=3D RANDOM_MOUSE || origin =3D=3D RANDOM_NET || origin =3D=3D RANDOM_INTERRUPT || - origin =3D=3D RANDOM_PURE, + origin =3D=3D RANDOM_PURE || origin =3D=3D RANDOM_DEVICE, ("random_harvest_internal: origin %d invalid\n", origin)); =20 /* Lockless read to avoid lock operations if fifo is full. */ Index: sys/sys/random.h =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- sys/sys/random.h (revision 240914) +++ sys/sys/random.h (working copy) @@ -45,6 +45,7 @@ RANDOM_NET, RANDOM_INTERRUPT, RANDOM_PURE, + RANDOM_DEVICE, ENTROPYSOURCE }; void random_harvest(void *, u_int, u_int, u_int, enum esource); Index: sys/kern/subr_bus.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- sys/kern/subr_bus.c (revision 240914) +++ sys/kern/subr_bus.c (working copy) @@ -31,6 +31,7 @@ =20 #include <sys/param.h> #include <sys/conf.h> +#include <sys/endian.h> #include <sys/filio.h> #include <sys/lock.h> #include <sys/kernel.h> @@ -44,6 +45,7 @@ #include <sys/condvar.h> #include <sys/queue.h> #include <machine/bus.h> +#include <sys/random.h> #include <sys/rman.h> #include <sys/selinfo.h> #include <sys/signalvar.h> @@ -53,6 +55,7 @@ #include <sys/bus.h> #include <sys/interrupt.h> =20 +#include <machine/cpu.h> #include <machine/stdarg.h> =20 #include <vm/uma.h> @@ -60,6 +63,16 @@ SYSCTL_NODE(_hw, OID_AUTO, bus, CTLFLAG_RW, NULL, NULL); SYSCTL_NODE(, OID_AUTO, dev, CTLFLAG_RW, NULL, NULL); =20 +#define MAXNATTACHTIMES 128 +static struct attachtime { + char name[24]; + uint64_t delta; +} attachtimes[MAXNATTACHTIMES]; +static int nattachtimes; +SYSCTL_OPAQUE(_hw, OID_AUTO, attachtimes, CTLFLAG_RD, + &attachtimes, sizeof(attachtimes), "S,attachtimes", + "time spent in device_attach()"); + /* * Used to attach drivers to devclasses. */ @@ -2760,8 +2773,10 @@ int device_attach(device_t dev) { + uint64_t attachtime; int error; =20 + attachtime =3D get_cyclecount(); device_sysctl_init(dev); if (!device_is_quiet(dev)) device_print_child(dev->parent, dev); @@ -2784,6 +2799,15 @@ dev->state =3D DS_ATTACHED; dev->flags &=3D ~DF_DONENOMATCH; devadded(dev); + attachtime =3D get_cyclecount() - attachtime; + if (nattachtimes < MAXNATTACHTIMES) { + strlcpy(attachtimes[nattachtimes].name, dev->nameunit, + sizeof(attachtimes[nattachtimes])); + attachtimes[nattachtimes].delta =3D htobe64(attachtime); + ++nattachtimes; + } + random_harvest(&attachtime, sizeof(attachtime), 4, 0, RANDOM_DEVICE); + return (0); } =20 _______________________________________________ freebsd-security@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-security To unsubscribe, send any mail to "freebsd-security-unsubscribe@freebsd.org"