netlink: prevent potential spectre v1 gadgets
[ Upstream commitf0950402e8
] 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:bfa83a9e03
("[NETLINK]: Type-safe netlink messages/attributes interface") Signed-off-by: Eric Dumazet <edumazet@google.com> Link: https://lore.kernel.org/r/20230119110150.2678537-1-edumazet@google.com Signed-off-by: Jakub Kicinski <kuba@kernel.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
parent
122d3a0ee4
commit
992e4ff711
|
@ -10,6 +10,7 @@
|
||||||
#include <linux/kernel.h>
|
#include <linux/kernel.h>
|
||||||
#include <linux/errno.h>
|
#include <linux/errno.h>
|
||||||
#include <linux/jiffies.h>
|
#include <linux/jiffies.h>
|
||||||
|
#include <linux/nospec.h>
|
||||||
#include <linux/skbuff.h>
|
#include <linux/skbuff.h>
|
||||||
#include <linux/string.h>
|
#include <linux/string.h>
|
||||||
#include <linux/types.h>
|
#include <linux/types.h>
|
||||||
|
@ -381,6 +382,7 @@ static int validate_nla(const struct nlattr *nla, int maxtype,
|
||||||
if (type <= 0 || type > maxtype)
|
if (type <= 0 || type > maxtype)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
type = array_index_nospec(type, maxtype + 1);
|
||||||
pt = &policy[type];
|
pt = &policy[type];
|
||||||
|
|
||||||
BUG_ON(pt->type > NLA_TYPE_MAX);
|
BUG_ON(pt->type > NLA_TYPE_MAX);
|
||||||
|
@ -596,6 +598,7 @@ static int __nla_validate_parse(const struct nlattr *head, int len, int maxtype,
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
type = array_index_nospec(type, maxtype + 1);
|
||||||
if (policy) {
|
if (policy) {
|
||||||
int err = validate_nla(nla, maxtype, policy,
|
int err = validate_nla(nla, maxtype, policy,
|
||||||
validate, extack, depth);
|
validate, extack, depth);
|
||||||
|
|
Loading…
Reference in New Issue