[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <1444159429-4788-4-git-send-email-cmetcalf@ezchip.com>
Date: Tue, 6 Oct 2015 15:23:49 -0400
From: Chris Metcalf <cmetcalf@...hip.com>
To: Michael Cree <mcree@...on.net.nz>,
Matt Turner <mattst88@...il.com>,
Michael Ellerman <mpe@...erman.id.au>,
Yoshinori Sato <ysato@...rs.sourceforge.jp>,
Alexey Dobriyan <adobriyan@...il.com>,
"Rasmus Villemoes" <linux@...musvillemoes.dk>,
Ingo Molnar <mingo@...nel.org>,
"Linus Torvalds" <torvalds@...ux-foundation.org>,
Peter Zijlstra <a.p.zijlstra@...llo.nl>,
Thomas Gleixner <tglx@...utronix.de>,
"H. Peter Anvin" <hpa@...or.com>, Borislav Petkov <bp@...en8.de>,
<linux-alpha@...r.kernel.org>,
Linux Kernel Mailing List <linux-kernel@...r.kernel.org>
CC: Chris Metcalf <cmetcalf@...hip.com>
Subject: [PATCH v2 3/3] strscpy: zero any trailing garbage bytes in the destination
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: Chris Metcalf <cmetcalf@...hip.com>
---
lib/string.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/lib/string.c b/lib/string.c
index 8dbb7b1eab50..84775ba873b9 100644
--- a/lib/string.c
+++ b/lib/string.c
@@ -203,12 +203,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);
--
2.1.2
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists