hc
2024-10-22 8ac6c7a54ed1b98d142dce24b11c6de6a1e239a5
kernel/net/xfrm/xfrm_compat.c
....@@ -5,6 +5,7 @@
55 * Based on code and translator idea by: Florian Westphal <fw@strlen.de>
66 */
77 #include <linux/compat.h>
8
+#include <linux/nospec.h>
89 #include <linux/xfrm.h>
910 #include <net/xfrm.h>
1011
....@@ -107,7 +108,7 @@
107108 [XFRMA_ALG_COMP] = { .len = sizeof(struct xfrm_algo) },
108109 [XFRMA_ENCAP] = { .len = sizeof(struct xfrm_encap_tmpl) },
109110 [XFRMA_TMPL] = { .len = sizeof(struct xfrm_user_tmpl) },
110
- [XFRMA_SEC_CTX] = { .len = sizeof(struct xfrm_sec_ctx) },
111
+ [XFRMA_SEC_CTX] = { .len = sizeof(struct xfrm_user_sec_ctx) },
111112 [XFRMA_LTIME_VAL] = { .len = sizeof(struct xfrm_lifetime_cur) },
112113 [XFRMA_REPLAY_VAL] = { .len = sizeof(struct xfrm_replay_state) },
113114 [XFRMA_REPLAY_THRESH] = { .type = NLA_U32 },
....@@ -300,7 +301,7 @@
300301 nla_for_each_attr(nla, attrs, len, remaining) {
301302 int err;
302303
303
- switch (type) {
304
+ switch (nlh_src->nlmsg_type) {
304305 case XFRM_MSG_NEWSPDINFO:
305306 err = xfrm_nla_cpy(dst, nla, nla_len(nla));
306307 break;
....@@ -435,6 +436,7 @@
435436 NL_SET_ERR_MSG(extack, "Bad attribute");
436437 return -EOPNOTSUPP;
437438 }
439
+ type = array_index_nospec(type, XFRMA_MAX + 1);
438440 if (nla_len(nla) < compat_policy[type].len) {
439441 NL_SET_ERR_MSG(extack, "Attribute bad length");
440442 return -EOPNOTSUPP;