Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3661552pxb; Mon, 24 Jan 2022 14:44:41 -0800 (PST) X-Google-Smtp-Source: ABdhPJypRz8DEEcrglZBCQp86UCkrDvo8hVoZuS9ItKP8Rugnj7kn9XreE0697pkFS3DH94OVc9y X-Received: by 2002:a17:902:7009:b0:14b:ce9:80b0 with SMTP id y9-20020a170902700900b0014b0ce980b0mr15989598plk.97.1643064281206; Mon, 24 Jan 2022 14:44:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643064281; cv=none; d=google.com; s=arc-20160816; b=GaTZ4HPZEDwZT5CAGl+4Op0YAF+OXE3aadXs9Cu8Ag+cl5ph5uQ2+/BcMtck2EyVwr qBZyBnWj3OaRm84UYoeKWVWRuGhdGpFkz3NOSsWfF2ft9t2Mn/XEm0kJcHkSpXk9EG7j v0U5D5LQISd6hkMvPkBMHDsOILjpmHzzrdzSt1OBauJr0RIjqMFPQfPKGLg1cr5dWU+4 JA6p8Tw9JuZhEsJVFs/l8LzyhAXyY4LCZR7CPjc/QJlwsPnhiBc6SUMKA6Mdn0n0LnfQ 3Imv4YGS9yVqpYxijvu41csisIzXs6xKzBXCKh2pQK3PsM/j/7ONut0Oq+KqwS+4dfuF 9xKQ== 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=VITkf9QTS0YFdwpkWXx5liZ4IZ2ttlmew33km9Jg3Rc=; b=TL8ojza+uzfXl1EcYgXK1XD5oh7z3f/3dmvB5OtNcRtswOGfhBgOY5PlawvLxWX3QT NWLSL/mh6QGHwNJ4Y9s/6qypDDV6ERhTgIL+0JvJRfaQDI9onzd7w4ggJ8ewozwTCK2o tNZG03Om9/U54uVMsH64AYSs9jXiE5bmh73g3wvYYAezwpMqsYULZbGKOoDHKVZnIcCI bnVLEdkeKXGmvZYScErYx6SEBkUIPI/NbWLokSvndSUFP3EsHbZqIZRTSowi8lZCOuax Pv9mXrG3B4+nyHSC1J8CNe26QqS+RxwFAtyewtMV0UeUWfS5x7E5sQEVrqRCIx8p3CI0 Cy+w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=xnC70p8S; 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 y28si14285086pgl.759.2022.01.24.14.44.29; Mon, 24 Jan 2022 14:44:41 -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=xnC70p8S; 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 S1383323AbiAXWnN (ORCPT + 99 others); Mon, 24 Jan 2022 17:43:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55274 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1456529AbiAXVj3 (ORCPT ); Mon, 24 Jan 2022 16:39:29 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 74889C0613A2; Mon, 24 Jan 2022 12:24:34 -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 ams.source.kernel.org (Postfix) with ESMTPS id EB06BB811F9; Mon, 24 Jan 2022 20:24:32 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2F452C340E5; Mon, 24 Jan 2022 20:24:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643055871; bh=WXG9DE4l41tkq1K1dZtis6c/+68uvRHriGktdbzlswM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xnC70p8SzntVtehnCq3SxWPWmdNRlk+7TaFV9/NqYrn/X2URjQVZwvm7vUcJ42P7o tIeWhjHTUiRL160rMSl4qQrTSpCY0m4Lz1E16dZFJwaBsJ3cgEJEVcvhDGrZKlaV/3 kyMbGFI1jYChKAJYzbtNku1G3ykZ7tZ3kXhM0UV0= 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.15 260/846] xfrm: state and policy should fail if XFRMA_IF_ID 0 Date: Mon, 24 Jan 2022 19:36:17 +0100 Message-Id: <20220124184109.892793038@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124184100.867127425@linuxfoundation.org> References: <20220124184100.867127425@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 11574314de09f..5ad7530f65457 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) @@ -1413,8 +1418,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); @@ -1727,8 +1737,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