Skip to contentSkip to conversation

netlink: validate NLA_MSECS length

PATCH Applied Johannes Berg 2 participants 2 messages Nov 3, 2011 – Nov 4, 2011

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 netlink: validate NLA_MSECS length

From: Johannes Berg <[email protected]>

L2TP for example uses NLA_MSECS like this:
policy:
[L2TP_ATTR_RECV_TIMEOUT] = { .type = NLA_MSECS, },
code:

        if (info->attrs[L2TP_ATTR_RECV_TIMEOUT])
                cfg.reorder_timeout = nla_get_msecs(info->attrs[L2TP_ATTR_RECV_TIMEOUT]);

As nla_get_msecs() is essentially nla_get_u64() plus the conversion to a HZ-based value, this will not properly reject attributes from userspace that aren't long enough and might overrun the message.

Add NLA_MSECS to the attribute minlen array to check the size properly.

---
 lib/nlattr.c |    1 +
 1 file changed, 1 insertion(+)
lib/nlattr.c +1 -0
@@ -20,6 +20,7 @@ static const u16 nla_attr_minlen[NLA_TYP
 	[NLA_U16]	= sizeof(u16),
 	[NLA_U32]	= sizeof(u32),
 	[NLA_U64]	= sizeof(u64),
+	[NLA_MSECS]	= sizeof(u64),
 	[NLA_NESTED]	= NLA_HDRLEN,
 };
 
maintainer Applied
#1 lore raw

From: Johannes Berg <[email protected]>
Date: Thu, 03 Nov 2011 11:07:32 +0100

Quoted 14 lines

From: Johannes Berg <[email protected]>

L2TP for example uses NLA_MSECS like this:
policy:
[L2TP_ATTR_RECV_TIMEOUT] = { .type = NLA_MSECS, },
code:

        if (info->attrs[L2TP_ATTR_RECV_TIMEOUT])
                cfg.reorder_timeout = nla_get_msecs(info->attrs[L2TP_ATTR_RECV_TIMEOUT]);

As nla_get_msecs() is essentially nla_get_u64() plus the conversion to a HZ-based value, this will not properly reject attributes from userspace that aren't long enough and might overrun the message.

Quoted 6 lines

Add NLA_MSECS to the attribute minlen array to check the size properly.

Applied, thanks!