*addrp = nla_data(rt);
 }
 
-static inline int verify_sec_ctx_len(struct nlattr **attrs)
+static inline int verify_sec_ctx_len(struct nlattr **attrs, struct netlink_ext_ack *extack)
 {
        struct nlattr *rt = attrs[XFRMA_SEC_CTX];
        struct xfrm_user_sec_ctx *uctx;
 
        uctx = nla_data(rt);
        if (uctx->len > nla_len(rt) ||
-           uctx->len != (sizeof(struct xfrm_user_sec_ctx) + uctx->ctx_len))
+           uctx->len != (sizeof(struct xfrm_user_sec_ctx) + uctx->ctx_len)) {
+               NL_SET_ERR_MSG(extack, "Invalid security context length");
                return -EINVAL;
+       }
 
        return 0;
 }
                goto out;
        if ((err = verify_one_alg(attrs, XFRMA_ALG_COMP)))
                goto out;
-       if ((err = verify_sec_ctx_len(attrs)))
+       if ((err = verify_sec_ctx_len(attrs, NULL)))
                goto out;
        if ((err = verify_replay(p, attrs)))
                goto out;
        err = verify_newpolicy_info(p, extack);
        if (err)
                return err;
-       err = verify_sec_ctx_len(attrs);
+       err = verify_sec_ctx_len(attrs, extack);
        if (err)
                return err;
 
                struct nlattr *rt = attrs[XFRMA_SEC_CTX];
                struct xfrm_sec_ctx *ctx;
 
-               err = verify_sec_ctx_len(attrs);
+               err = verify_sec_ctx_len(attrs, extack);
                if (err)
                        return err;
 
                struct nlattr *rt = attrs[XFRMA_SEC_CTX];
                struct xfrm_sec_ctx *ctx;
 
-               err = verify_sec_ctx_len(attrs);
+               err = verify_sec_ctx_len(attrs, extack);
                if (err)
                        return err;
 
        err = verify_newpolicy_info(&ua->policy, extack);
        if (err)
                goto free_state;
-       err = verify_sec_ctx_len(attrs);
+       err = verify_sec_ctx_len(attrs, extack);
        if (err)
                goto free_state;