Skip to content

Commit 41b74e9

Browse files
Eric Dumazetgregkh
Eric Dumazet
authored andcommitted
netlink: prevent potential spectre v1 gadgets
[ Upstream commit f095040 ] Most netlink attributes are parsed and validated from __nla_validate_parse() or validate_nla() u16 type = nla_type(nla); if (type == 0 || type > maxtype) { /* error or continue */ } @type is then used as an array index and can be used as a Spectre v1 gadget. array_index_nospec() can be used to prevent leaking content of kernel memory to malicious users. This should take care of vast majority of netlink uses, but an audit is needed to take care of others where validation is not yet centralized in core netlink functions. Fixes: bfa83a9 ("[NETLINK]: Type-safe netlink messages/attributes interface") Signed-off-by: Eric Dumazet <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent 2f29d78 commit 41b74e9

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

lib/nlattr.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <linux/kernel.h>
1111
#include <linux/errno.h>
1212
#include <linux/jiffies.h>
13+
#include <linux/nospec.h>
1314
#include <linux/skbuff.h>
1415
#include <linux/string.h>
1516
#include <linux/types.h>
@@ -369,6 +370,7 @@ static int validate_nla(const struct nlattr *nla, int maxtype,
369370
if (type <= 0 || type > maxtype)
370371
return 0;
371372

373+
type = array_index_nospec(type, maxtype + 1);
372374
pt = &policy[type];
373375

374376
BUG_ON(pt->type > NLA_TYPE_MAX);
@@ -584,6 +586,7 @@ static int __nla_validate_parse(const struct nlattr *head, int len, int maxtype,
584586
}
585587
continue;
586588
}
589+
type = array_index_nospec(type, maxtype + 1);
587590
if (policy) {
588591
int err = validate_nla(nla, maxtype, policy,
589592
validate, extack, depth);

0 commit comments

Comments
 (0)