Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3589273pxb; Mon, 24 Jan 2022 12:58:10 -0800 (PST) X-Google-Smtp-Source: ABdhPJyh7x6hc1vnP7amQBBDHB9X3aH5IchZJ5Q6nxaYVEIf7ODRfZ67PbNIqu8LNmjNQz2s0i9z X-Received: by 2002:a17:90a:a395:: with SMTP id x21mr174944pjp.32.1643057890826; Mon, 24 Jan 2022 12:58:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643057890; cv=none; d=google.com; s=arc-20160816; b=g1NDPAaruJFIcY6E+soQtdDkYZvmjWZRuCapfUuP9o7m9+oEoJY4cYIIPKcqWxIhoX Q4LaFpLzrIj/h6o+zQeeEbiG37M7JLAd+zB0jcFH4zzwnqV/pUWOdXTGJ+DojrjcOorV NpojAW9E7RTlKVzIWQUa8v3s6zhT8AUZdaDNydCLWIK0yGGWuqWWnZcgNByfuW6STe+e D8m28p+zjOHMY5RKOa6Eqbhtq3UYGubTh9qnXf4BxirMr/DpbFnE1kmJa5nKkyOYvFkx Zs5NM+MEX9Z1IXCjvDAFZn50v5tydRaPhPlE8dU90jxc8pqErqk/iMEEgg7uJB91Pkjm Kwlg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=bYQRKLSqQZEcZWVmm+v0c5pMzGKP93Xg8tIGWuX0Zzs=; b=Bs6s7fZ39SlOOhKIMX/9ZE2noqX2aRwlYC6PawKYUBob2v0dJ2y+FFIGtPVmqRFPSA FnIzD/HTdvfw0Je+gQ8nHseKjT2Bo97DXdLq1WUMgCnjRVoGkgxjVawLnGDTHcBfUAao 0bJInFyrxL7it5O04mB+N8LiY7EySp4zOI8uMTRisqyDVylOPqYe5/BjV2UeGoI3R2t7 gGf+1okN9iWxzQzEziBqUnTuvBtTUoNGB0Nymhymi93zMbelTggt0NjeHC0DvRU5F/yd JY2cTqsB+YggXzVVYOd2S7eu+VJxZgDS5YoUXkcen5jW68HquwZO28FMhhJSp/fHTSHG YJiw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=o4ZYnh75; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id pj10si372807pjb.125.2022.01.24.12.57.57; Mon, 24 Jan 2022 12:58:10 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=o4ZYnh75; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242993AbiAXUTP (ORCPT + 99 others); Mon, 24 Jan 2022 15:19:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59292 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349343AbiAXUCF (ORCPT ); Mon, 24 Jan 2022 15:02:05 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E7D14C068085; Mon, 24 Jan 2022 11:28:56 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 843D96148B; Mon, 24 Jan 2022 19:28:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 74B1CC340E5; Mon, 24 Jan 2022 19:28:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643052535; bh=7TEbViqa5qzpkns3ce5kg4p4DVWtQcObvdBdTHY3K1Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=o4ZYnh75VhWTcKiYCnSh8rZGXsUXJZtUa4hVlzsy4BgbqJ9wl8EolXd2LJGc0UTih qoOyXp0g6LHAlBX6rUSOV3YFSMmHvTIr6pgQx5S5s0+p4pe7zANqRrCyhW1mtWyQiF om06ZU8zN3r+DI5uUG90K0k7hX1XB7ure4+oRNyY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Antony Antony , Steffen Klassert , Sasha Levin Subject: [PATCH 5.4 090/320] xfrm: state and policy should fail if XFRMA_IF_ID 0 Date: Mon, 24 Jan 2022 19:41:14 +0100 Message-Id: <20220124183956.800549443@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124183953.750177707@linuxfoundation.org> References: <20220124183953.750177707@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Antony Antony [ Upstream commit 68ac0f3810e76a853b5f7b90601a05c3048b8b54 ] xfrm ineterface does not allow xfrm if_id = 0 fail to create or update xfrm state and policy. With this commit: ip xfrm policy add src 192.0.2.1 dst 192.0.2.2 dir out if_id 0 RTNETLINK answers: Invalid argument ip xfrm state add src 192.0.2.1 dst 192.0.2.2 proto esp spi 1 \ reqid 1 mode tunnel aead 'rfc4106(gcm(aes))' \ 0x1111111111111111111111111111111111111111 96 if_id 0 RTNETLINK answers: Invalid argument v1->v2 change: - add Fixes: tag Fixes: 9f8550e4bd9d ("xfrm: fix disable_xfrm sysctl when used on xfrm interfaces") Signed-off-by: Antony Antony Signed-off-by: Steffen Klassert Signed-off-by: Sasha Levin --- net/xfrm/xfrm_user.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/net/xfrm/xfrm_user.c b/net/xfrm/xfrm_user.c index ddcf569d852f7..42ff32700d68b 100644 --- a/net/xfrm/xfrm_user.c +++ b/net/xfrm/xfrm_user.c @@ -621,8 +621,13 @@ static struct xfrm_state *xfrm_state_construct(struct net *net, xfrm_smark_init(attrs, &x->props.smark); - if (attrs[XFRMA_IF_ID]) + if (attrs[XFRMA_IF_ID]) { x->if_id = nla_get_u32(attrs[XFRMA_IF_ID]); + if (!x->if_id) { + err = -EINVAL; + goto error; + } + } err = __xfrm_init_state(x, false, attrs[XFRMA_OFFLOAD_DEV]); if (err) @@ -1328,8 +1333,13 @@ static int xfrm_alloc_userspi(struct sk_buff *skb, struct nlmsghdr *nlh, mark = xfrm_mark_get(attrs, &m); - if (attrs[XFRMA_IF_ID]) + if (attrs[XFRMA_IF_ID]) { if_id = nla_get_u32(attrs[XFRMA_IF_ID]); + if (!if_id) { + err = -EINVAL; + goto out_noput; + } + } if (p->info.seq) { x = xfrm_find_acq_byseq(net, mark, p->info.seq); @@ -1631,8 +1641,13 @@ static struct xfrm_policy *xfrm_policy_construct(struct net *net, struct xfrm_us xfrm_mark_get(attrs, &xp->mark); - if (attrs[XFRMA_IF_ID]) + if (attrs[XFRMA_IF_ID]) { xp->if_id = nla_get_u32(attrs[XFRMA_IF_ID]); + if (!xp->if_id) { + err = -EINVAL; + goto error; + } + } return xp; error: -- 2.34.1