Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 588b2464 authored by Chris Metcalf's avatar Chris Metcalf Committed by Greg Kroah-Hartman
Browse files

strscpy: zero any trailing garbage bytes in the destination



commit 990486c8af044f89bddfbde1d1cf9fde449bedbf upstream.

It's possible that the destination can be shadowed in userspace
(as, for example, the perf buffers are now).  So we should take
care not to leak data that could be inspected by userspace.

Signed-off-by: default avatarChris Metcalf <cmetcalf@ezchip.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent a7191e90
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -211,12 +211,13 @@ ssize_t strscpy(char *dest, const char *src, size_t count)
		unsigned long c, data;

		c = *(unsigned long *)(src+res);
		*(unsigned long *)(dest+res) = c;
		if (has_zero(c, &data, &constants)) {
			data = prep_zero_mask(c, data, &constants);
			data = create_zero_mask(data);
			*(unsigned long *)(dest+res) = c & zero_bytemask(data);
			return res + find_zero(data);
		}
		*(unsigned long *)(dest+res) = c;
		res += sizeof(unsigned long);
		count -= sizeof(unsigned long);
		max -= sizeof(unsigned long);