Skip to content

Commit 4c0939a

Browse files
mkubecekshemminger
authored andcommitted
ip xfrm: use correct key length for netlink message
When SA is added manually using "ip xfrm state add", xfrm_state_modify() uses alg_key_len field of struct xfrm_algo for the length of key passed to kernel in the netlink message. However alg_key_len is bit length of the key while we need byte length here. This is usually harmless as kernel ignores the excess data but when the bit length of the key exceeds 512 (XFRM_ALGO_KEY_BUF_SIZE), it can result in buffer overflow. We can simply divide by 8 here as the only place setting alg_key_len is in xfrm_algo_parse() where it is always set to a multiple of 8 (and there are already multiple places using "algo->alg_key_len / 8"). Signed-off-by: Michal Kubecek <mkubecek@suse.cz>
1 parent 7345125 commit 4c0939a

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

ip/xfrm_state.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,7 @@ static int xfrm_state_modify(int cmd, unsigned int flags, int argc, char **argv)
539539

540540
xfrm_algo_parse((void *)&alg, type, name, key,
541541
buf, sizeof(alg.buf));
542-
len += alg.u.alg.alg_key_len;
542+
len += alg.u.alg.alg_key_len / 8;
543543

544544
addattr_l(&req.n, sizeof(req.buf), type,
545545
(void *)&alg, len);

0 commit comments

Comments
 (0)