ktrace: Zero request structures when populating the pool

Otherwise uninitialized pad bytes may be copied into the ktrace log
file.

Reported by:	KMSAN
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
This commit is contained in:
Mark Johnston 2021-07-23 10:29:53 -04:00
parent 9666cda976
commit 5c18bf9d5f

View File

@ -219,7 +219,8 @@ ktrace_init(void *dummy)
sx_init(&ktrace_sx, "ktrace_sx"); sx_init(&ktrace_sx, "ktrace_sx");
STAILQ_INIT(&ktr_free); STAILQ_INIT(&ktr_free);
for (i = 0; i < ktr_requestpool; i++) { for (i = 0; i < ktr_requestpool; i++) {
req = malloc(sizeof(struct ktr_request), M_KTRACE, M_WAITOK); req = malloc(sizeof(struct ktr_request), M_KTRACE, M_WAITOK |
M_ZERO);
STAILQ_INSERT_HEAD(&ktr_free, req, ktr_list); STAILQ_INSERT_HEAD(&ktr_free, req, ktr_list);
} }
} }
@ -285,7 +286,7 @@ ktrace_resize_pool(u_int oldsize, u_int newsize)
STAILQ_INIT(&ktr_new); STAILQ_INIT(&ktr_new);
while (bound-- > 0) { while (bound-- > 0) {
req = malloc(sizeof(struct ktr_request), M_KTRACE, req = malloc(sizeof(struct ktr_request), M_KTRACE,
M_WAITOK); M_WAITOK | M_ZERO);
STAILQ_INSERT_HEAD(&ktr_new, req, ktr_list); STAILQ_INSERT_HEAD(&ktr_new, req, ktr_list);
} }
mtx_lock(&ktrace_mtx); mtx_lock(&ktrace_mtx);