Skip to content

Commit b6ee896

Browse files
edumazetklassert
authored andcommitted
xfrm/compat: prevent potential spectre v1 gadget in xfrm_xlate32_attr()
int type = nla_type(nla); if (type > XFRMA_MAX) { return -EOPNOTSUPP; } @type is then used as an array index and can be used as a Spectre v1 gadget. if (nla_len(nla) < compat_policy[type].len) { array_index_nospec() can be used to prevent leaking content of kernel memory to malicious users. Fixes: 5106f4a ("xfrm/compat: Add 32=>64-bit messages translator") Signed-off-by: Eric Dumazet <[email protected]> Cc: Dmitry Safonov <[email protected]> Cc: Steffen Klassert <[email protected]> Reviewed-by: Dmitry Safonov <[email protected]> Signed-off-by: Steffen Klassert <[email protected]>
1 parent eb6c59b commit b6ee896

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

net/xfrm/xfrm_compat.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* Based on code and translator idea by: Florian Westphal <[email protected]>
66
*/
77
#include <linux/compat.h>
8+
#include <linux/nospec.h>
89
#include <linux/xfrm.h>
910
#include <net/xfrm.h>
1011

@@ -437,6 +438,7 @@ static int xfrm_xlate32_attr(void *dst, const struct nlattr *nla,
437438
NL_SET_ERR_MSG(extack, "Bad attribute");
438439
return -EOPNOTSUPP;
439440
}
441+
type = array_index_nospec(type, XFRMA_MAX + 1);
440442
if (nla_len(nla) < compat_policy[type].len) {
441443
NL_SET_ERR_MSG(extack, "Attribute bad length");
442444
return -EOPNOTSUPP;

0 commit comments

Comments
 (0)