From: Jiri Benc Date: Sun, 29 Mar 2015 14:05:28 +0000 (+0200) Subject: netlink: pad nla_memcpy dest buffer with zeroes X-Git-Url: http://git.lede-project.org./?a=commitdiff_plain;h=5899f0478528b59ea9ced201eacb3e56ca406c39;p=openwrt%2Fstaging%2Fblogic.git netlink: pad nla_memcpy dest buffer with zeroes This is especially important in cases where the kernel allocs a new structure and expects a field to be set from a netlink attribute. If such attribute is shorter than expected, the rest of the field is left containing previous data. When such field is read back by the user space, kernel memory content is leaked. Signed-off-by: Jiri Benc Acked-by: Thomas Graf Signed-off-by: David S. Miller --- diff --git a/lib/nlattr.c b/lib/nlattr.c index 76a1b59523ab..f5907d23272d 100644 --- a/lib/nlattr.c +++ b/lib/nlattr.c @@ -279,6 +279,8 @@ int nla_memcpy(void *dest, const struct nlattr *src, int count) int minlen = min_t(int, count, nla_len(src)); memcpy(dest, nla_data(src), minlen); + if (count > minlen) + memset(dest + minlen, 0, count - minlen); return minlen; }