Skip to contentSkip to conversation

xfrm/compat: prevent potential spectre v1 gadget in xfrm_xlate32_attr()

PATCH Applied Eric Dumazet 3 participants 3 messages Jan 20, 2023 – Jan 24, 2023

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

PATCH 1/1 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 5106f4a8acff ("xfrm/compat: Add 32=>64-bit messages translator")
Cc Dmitry Safonov <[email protected]>
Cc Steffen Klassert <[email protected]>
---
 net/xfrm/xfrm_compat.c | 2 ++
 1 file changed, 2 insertions(+)
net/xfrm/xfrm_compat.c +2 -0
index a0f62fa02e06e0aa97901aaf226dc84895f6a8ec..46bb239e4f06d56abbf3deecd89ac26625efb560 100644
@@ -5,6 +5,7 @@
  * Based on code and translator idea by: Florian Westphal <[email protected]>
  */
 #include <linux/compat.h>
+#include <linux/nospec.h>
 #include <linux/xfrm.h>
 #include <net/xfrm.h>
 
@@ -437,6 +438,7 @@ static int xfrm_xlate32_attr(void *dst, const struct nlattr *nla,
 		NL_SET_ERR_MSG(extack, "Bad attribute");
 		return -EOPNOTSUPP;
 	}
+	type = array_index_nospec(type, XFRMA_MAX + 1);
 	if (nla_len(nla) < compat_policy[type].len) {
 		NL_SET_ERR_MSG(extack, "Attribute bad length");
 		return -EOPNOTSUPP;
Signature · 1 line
2.39.1.405.gd4c25cc71f-goog
Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 lines · Eric Dumazet
  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) {
Quoted 7 lines

array_index_nospec() can be used to prevent leaking content of kernel memory to malicious users.

Fixes 5106f4a8acff ("xfrm/compat: Add 32=>64-bit messages translator")
Cc Dmitry Safonov <[email protected]>
Cc Steffen Klassert <[email protected]>

Thanks, Eric!

Quoted 24 lines
---
 net/xfrm/xfrm_compat.c | 2 ++
 1 file changed, 2 insertions(+)
net/xfrm/xfrm_compat.c +2 -0
index a0f62fa02e06e0aa97901aaf226dc84895f6a8ec..46bb239e4f06d56abbf3deecd89ac26625efb560 100644
@@ -5,6 +5,7 @@
  * Based on code and translator idea by: Florian Westphal <[email protected]>
  */
 #include <linux/compat.h>
+#include <linux/nospec.h>
 #include <linux/xfrm.h>
 #include <net/xfrm.h>
 
@@ -437,6 +438,7 @@ static int xfrm_xlate32_attr(void *dst, const struct nlattr *nla,
 		NL_SET_ERR_MSG(extack, "Bad attribute");
 		return -EOPNOTSUPP;
 	}
+	type = array_index_nospec(type, XFRMA_MAX + 1);
 	if (nla_len(nla) < compat_policy[type].len) {
 		NL_SET_ERR_MSG(extack, "Attribute bad length");
 		return -EOPNOTSUPP;
Signature · 1 line
          Dmitry
maintainer Applied
#2 lore raw
In reply to Eric Dumazet
Quoted 11 lines · Eric Dumazet
  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) {
Quoted 7 lines

array_index_nospec() can be used to prevent leaking content of kernel memory to malicious users.

Fixes 5106f4a8acff ("xfrm/compat: Add 32=>64-bit messages translator")
Cc Dmitry Safonov <[email protected]>
Cc Steffen Klassert <[email protected]>

Applied to the ipsec tree, thanks a lot Eric!