netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net] netlink: pad nla_memcpy dest buffer with zeroes
@ 2015-03-29 14:05 Jiri Benc
  2015-03-30 11:31 ` Thomas Graf
  2015-03-31 18:07 ` David Miller
  0 siblings, 2 replies; 3+ messages in thread
From: Jiri Benc @ 2015-03-29 14:05 UTC (permalink / raw)
  To: netdev; +Cc: Thomas Graf

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>
---

Alternatively, we may audit all callers of nla_memcpy; at least
nf_nat_ipv6_nlattr_to_range, ip_vs_genl_parse_service,
ieee802154_add_iface, ieee802154_llsec_parse_key and vxlan_nla_get_addr seem
possible to suffer from this by a quick glance. However, the notion of
"shorter attribute is understood as padded by zeroes" seems sensible to me.
---
 lib/nlattr.c | 2 ++
 1 file changed, 2 insertions(+)

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;
 }
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-03-31 18:07 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-03-29 14:05 [PATCH net] netlink: pad nla_memcpy dest buffer with zeroes Jiri Benc
2015-03-30 11:31 ` Thomas Graf
2015-03-31 18:07 ` David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).