Skip to contentSkip to conversation

Patch "swapfile: fix memory corruption via malformed swapfile" has been added to the 4.4-stable tree

PATCH [email protected] 1 participant 1 message Nov 15, 2016

Subsystems (3)
lore
Share & tools
lore

[email protected]

author maintainer Applied
#0 lore raw

This is a note to let you know that I've just added the patch titled

swapfile: fix memory corruption via malformed swapfile

to the 4.4-stable tree which can be found at:
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
swapfile-fix-memory-corruption-via-malformed-swapfile.patch
and it can be found in the queue-4.4 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree, please let <[email protected]> know about it.

Quoted 1 line

From dd111be69114cc867f8e826284559bfbc1c40e37 Mon Sep 17 00:00:00 2001

From: Jann Horn <[email protected]>
Date: Thu, 10 Nov 2016 10:46:19 -0800
Subject: swapfile: fix memory corruption via malformed swapfile

From: Jann Horn <[email protected]>

commit dd111be69114cc867f8e826284559bfbc1c40e37 upstream.

When root activates a swap partition whose header has the wrong endianness, nr_badpages elements of badpages are swabbed before nr_badpages has been checked, leading to a buffer overrun of up to 8GB.

This normally is not a security issue because it can only be exploited by root (more specifically, a process with CAP_SYS_ADMIN or the ability to modify a swap file/partition), and such a process can already e.g. modify swapped-out memory of any other userspace process on the system.

---
 mm/swapfile.c |    2 ++
 1 file changed, 2 insertions(+)
mm/swapfile.c +2 -0
@@ -2225,6 +2225,8 @@ static unsigned long read_swap_header(st
 		swab32s(&swap_header->info.version);
 		swab32s(&swap_header->info.last_page);
 		swab32s(&swap_header->info.nr_badpages);
+		if (swap_header->info.nr_badpages > MAX_SWAP_BADPAGES)
+			return 0;
 		for (i = 0; i < swap_header->info.nr_badpages; i++)
 			swab32s(&swap_header->info.badpages[i]);
 	}

Patches currently in stable-queue which might be from [email protected] are

queue-4.4/swapfile-fix-memory-corruption-via-malformed-swapfile.patch