Skip to content

Commit 171d449

Browse files
lxinklassert
authored andcommitted
xfrm: fix uctx len check in verify_sec_ctx_len
It's not sufficient to do 'uctx->len != (sizeof(struct xfrm_user_sec_ctx) + uctx->ctx_len)' check only, as uctx->len may be greater than nla_len(rt), in which case it will cause slab-out-of-bounds when accessing uctx->ctx_str later. This patch is to fix it by return -EINVAL when uctx->len > nla_len(rt). Fixes: df71837 ("[LSM-IPSec]: Security association restriction.") Signed-off-by: Xin Long <[email protected]> Signed-off-by: Steffen Klassert <[email protected]>
1 parent f1ed102 commit 171d449

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

net/xfrm/xfrm_user.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,8 @@ static inline int verify_sec_ctx_len(struct nlattr **attrs)
110110
return 0;
111111

112112
uctx = nla_data(rt);
113-
if (uctx->len != (sizeof(struct xfrm_user_sec_ctx) + uctx->ctx_len))
113+
if (uctx->len > nla_len(rt) ||
114+
uctx->len != (sizeof(struct xfrm_user_sec_ctx) + uctx->ctx_len))
114115
return -EINVAL;
115116

116117
return 0;

0 commit comments

Comments
 (0)