Skip to contentSkip to conversation

x86/mtrr: Don't copy uninitialized gentry fields back to userspace

tip:x86/urgent tip-bot for Colin Ian King 1 participant 1 message Dec 18, 2018 1 message not in the archive x86

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw
Commit-ID:  32043fa065b51e0b1433e48d118821c71b5cd65d
Gitweb:     https://git.kernel.org/tip/32043fa065b51e0b1433e48d118821c71b5cd65d
Author:     Colin Ian King <[email protected]>
AuthorDate: Tue, 18 Dec 2018 17:29:56 +0000
Committer:  Thomas Gleixner <[email protected]>
CommitDate: Wed, 19 Dec 2018 00:00:16 +0100

x86/mtrr: Don't copy uninitialized gentry fields back to userspace

Currently the copy_to_user of data in the gentry struct is copying uninitiaized data in field _pad from the stack to userspace.

Fix this by explicitly memset'ing gentry to zero, this also will zero any compiler added padding fields that may be in struct (currently there are none).

Detected by CoverityScan, CID#200783 ("Uninitialized scalar variable")

Fixes b263b31e8ad6 ("x86, mtrr: Use explicit sizing and padding for the 64-bit ioctls")
---
 arch/x86/kernel/cpu/mtrr/if.c | 2 ++
 1 file changed, 2 insertions(+)
arch/x86/kernel/cpu/mtrr/if.c +2 -0
index 2e173d47b450..4d36dcc1cf87 100644
@@ -165,6 +165,8 @@ mtrr_ioctl(struct file *file, unsigned int cmd, unsigned long __arg)
 	struct mtrr_gentry gentry;
 	void __user *arg = (void __user *) __arg;
 
+	memset(&gentry, 0, sizeof(gentry));
+
 	switch (cmd) {
 	case MTRRIOC_ADD_ENTRY:
 	case MTRRIOC_SET_ENTRY: