]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
netlink: pad nla_memcpy dest buffer with zeroes
authorJiri Benc <jbenc@redhat.com>
Sun, 29 Mar 2015 14:05:28 +0000 (16:05 +0200)
committerDavid S. Miller <davem@davemloft.net>
Tue, 31 Mar 2015 18:07:24 +0000 (14:07 -0400)
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 <jbenc@redhat.com>
Acked-by: Thomas Graf <tgraf@suug.ch>
Signed-off-by: David S. Miller <davem@davemloft.net>
lib/nlattr.c

index 76a1b59523ab05907403f4f9bd5dc547fca1bcab..f5907d23272d48562c69b911e5a0a619e3f4c180 100644 (file)
@@ -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;
 }