提交 bfacdf7e 编写于 作者: E Eric Dumazet 提交者: sanglipeng

netlink: prevent potential spectre v1 gadgets

stable inclusion
from stable-v5.10.166
commit 539ca5dcbc91134bbe2c45677811c31d8b030d2d
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/I7TH9O

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=539ca5dcbc91134bbe2c45677811c31d8b030d2d

--------------------------------

[ Upstream commit f0950402 ]

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: bfa83a9e ("[NETLINK]: Type-safe netlink messages/attributes interface")
Signed-off-by: NEric Dumazet <edumazet@google.com>
Link: https://lore.kernel.org/r/20230119110150.2678537-1-edumazet@google.comSigned-off-by: NJakub Kicinski <kuba@kernel.org>
Signed-off-by: NSasha Levin <sashal@kernel.org>
Signed-off-by: Nsanglipeng <sanglipeng1@jd.com>
上级 557b8476
...@@ -10,6 +10,7 @@ ...@@ -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>
...@@ -369,6 +370,7 @@ static int validate_nla(const struct nlattr *nla, int maxtype, ...@@ -369,6 +370,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);
...@@ -584,6 +586,7 @@ static int __nla_validate_parse(const struct nlattr *head, int len, int maxtype, ...@@ -584,6 +586,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);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册