aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Johnston <markj@FreeBSD.org>2021-05-12 13:42:44 +0000
committerMark Johnston <markj@FreeBSD.org>2021-05-19 13:32:18 +0000
commit4a6c5c8f592f320bd72616836239b765f042b323 (patch)
treee2e8f6cabeb5b70a5c3437dc681b6e4aa3e1e22b
parent178633e28291d2e4168e51e6d970c25bca43bc1e (diff)
downloadsrc-4a6c5c8f592f320bd72616836239b765f042b323.tar.gz
src-4a6c5c8f592f320bd72616836239b765f042b323.zip
swap_pager: Zero swap info before exporting to userspace
Otherwise padding bytes are leaked. Reported by: KMSAN Sponsored by: The FreeBSD Foundation (cherry picked from commit 06d1fd9f42fa9c060fad8f3a71fcaada3baaf200)
-rw-r--r--sys/vm/swap_pager.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/sys/vm/swap_pager.c b/sys/vm/swap_pager.c
index 888df04741b4..f7cde181a7c4 100644
--- a/sys/vm/swap_pager.c
+++ b/sys/vm/swap_pager.c
@@ -2668,11 +2668,14 @@ sysctl_vm_swap_info(SYSCTL_HANDLER_ARGS)
if (arg2 != 1) /* name length */
return (EINVAL);
+
+ memset(&xs, 0, sizeof(xs));
error = swap_dev_info(*(int *)arg1, &xs, NULL, 0);
if (error != 0)
return (error);
#if defined(__amd64__) && defined(COMPAT_FREEBSD32)
if (req->oldlen == sizeof(xs32)) {
+ memset(&xs32, 0, sizeof(xs32));
xs32.xsw_version = XSWDEV_VERSION;
xs32.xsw_dev1 = xs.xsw_dev;
xs32.xsw_dev2 = xs.xsw_dev >> 32;
@@ -2685,6 +2688,7 @@ sysctl_vm_swap_info(SYSCTL_HANDLER_ARGS)
#endif
#if defined(COMPAT_FREEBSD11)
if (req->oldlen == sizeof(xs11)) {
+ memset(&xs11, 0, sizeof(xs11));
xs11.xsw_version = XSWDEV_VERSION_11;
xs11.xsw_dev = xs.xsw_dev; /* truncation */
xs11.xsw_flags = xs.xsw_flags;