Skip to content

Commit 2722cd8

Browse files
Florian WestphalSasha Levin
authored andcommitted
xfrm_user: uncoditionally validate esn replay attribute struct
[ Upstream commit d97ca5d ] The sanity test added in ecd7918 can be bypassed, validation only occurs if XFRM_STATE_ESN flag is set, but rest of code doesn't care and just checks if the attribute itself is present. So always validate. Alternative is to reject if we have the attribute without the flag but that would change abi. Reported-by: [email protected] Cc: Mathias Krause <[email protected]> Fixes: ecd7918 ("xfrm_user: ensure user supplied esn replay window is valid") Fixes: d8647b7 ("xfrm: Add user interface for esn and big anti-replay windows") Signed-off-by: Florian Westphal <[email protected]> Signed-off-by: Steffen Klassert <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent 9e07b5d commit 2722cd8

File tree

1 file changed

+8
-13
lines changed

1 file changed

+8
-13
lines changed

net/xfrm/xfrm_user.c

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -120,22 +120,17 @@ static inline int verify_replay(struct xfrm_usersa_info *p,
120120
struct nlattr *rt = attrs[XFRMA_REPLAY_ESN_VAL];
121121
struct xfrm_replay_state_esn *rs;
122122

123-
if (p->flags & XFRM_STATE_ESN) {
124-
if (!rt)
125-
return -EINVAL;
123+
if (!rt)
124+
return (p->flags & XFRM_STATE_ESN) ? -EINVAL : 0;
126125

127-
rs = nla_data(rt);
126+
rs = nla_data(rt);
128127

129-
if (rs->bmp_len > XFRMA_REPLAY_ESN_MAX / sizeof(rs->bmp[0]) / 8)
130-
return -EINVAL;
131-
132-
if (nla_len(rt) < xfrm_replay_state_esn_len(rs) &&
133-
nla_len(rt) != sizeof(*rs))
134-
return -EINVAL;
135-
}
128+
if (rs->bmp_len > XFRMA_REPLAY_ESN_MAX / sizeof(rs->bmp[0]) / 8)
129+
return -EINVAL;
136130

137-
if (!rt)
138-
return 0;
131+
if (nla_len(rt) < xfrm_replay_state_esn_len(rs) &&
132+
nla_len(rt) != sizeof(*rs))
133+
return -EINVAL;
139134

140135
/* As only ESP and AH support ESN feature. */
141136
if ((p->id.proto != IPPROTO_ESP) && (p->id.proto != IPPROTO_AH))

0 commit comments

Comments
 (0)