Commit e5444d24 authored by Sabrina Dubroca's avatar Sabrina Dubroca Committed by Wen Zhiwei
Browse files

xfrm: validate new SA's prefixlen using SA family when sel.family is unset

stable inclusion
from stable-v6.6.59
commit 7d9868180bd1e4cf37e7c5067362658971162366
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/IB3ENL

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=7d9868180bd1e4cf37e7c5067362658971162366



--------------------------------

[ Upstream commit 3f0ab59e6537c6a8f9e1b355b48f9c05a76e8563 ]

This expands the validation introduced in commit 07bf7908 ("xfrm:
Validate address prefix lengths in the xfrm selector.")

syzbot created an SA with
    usersa.sel.family = AF_UNSPEC
    usersa.sel.prefixlen_s = 128
    usersa.family = AF_INET

Because of the AF_UNSPEC selector, verify_newsa_info doesn't put
limits on prefixlen_{s,d}. But then copy_from_user_state sets
x->sel.family to usersa.family (AF_INET). Do the same conversion in
verify_newsa_info before validating prefixlen_{s,d}, since that's how
prefixlen is going to be used later on.

Reported-by: default avatar <syzbot+cc39f136925517aed571@syzkaller.appspotmail.com>
Fixes: 1da177e4 ("Linux-2.6.12-rc2")
Signed-off-by: default avatarSabrina Dubroca <sd@queasysnail.net>
Signed-off-by: default avatarSteffen Klassert <steffen.klassert@secunet.com>
Signed-off-by: default avatarAntony Antony <antony.antony@secunet.com>
Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
Signed-off-by: default avatarWen Zhiwei <wenzhiwei@kylinos.cn>
parent 1a0204e6
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -176,6 +176,7 @@ static int verify_newsa_info(struct xfrm_usersa_info *p,
			     struct netlink_ext_ack *extack)
{
	int err;
	u16 family = p->sel.family;

	err = -EINVAL;
	switch (p->family) {
@@ -196,7 +197,10 @@ static int verify_newsa_info(struct xfrm_usersa_info *p,
		goto out;
	}

	switch (p->sel.family) {
	if (!family && !(p->flags & XFRM_STATE_AF_UNSPEC))
		family = p->family;

	switch (family) {
	case AF_UNSPEC:
		break;