Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp1783970pxp; Mon, 7 Mar 2022 02:13:41 -0800 (PST) X-Google-Smtp-Source: ABdhPJz+o4dkg1jvyFwsgbwpZanhqJJ9SakHGAWHd5q5TRB9QQhEJhjm6c3vOwzn4DmNVwRsDAWl X-Received: by 2002:a17:906:2486:b0:6cf:ced9:e4cc with SMTP id e6-20020a170906248600b006cfced9e4ccmr8630223ejb.201.1646647897221; Mon, 07 Mar 2022 02:11:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646647897; cv=none; d=google.com; s=arc-20160816; b=jFTXsxs077Yqfmyi4MoQ3i0eWL1N5UlAYSEQw9/mS/0qE+93NjHLqe2BUrwd6i4Zuz 4jnZfS7TX1qEEphPbyFgupND6lRpUBGS43ERkPDXRx8/glIrknKVPYudui2MGMclGKnh dVbk++skQkKGW5QG2r4sBPPNm8IAS6Lgfwk94WjsDNmN8O4TIgfmiWM5tcVF/FWV1Zjb 3CxITR6UPaK1Wf8NRwqMwPXFkcjUxxD5wWiwUAr/ZFPvbLXHA1AFGzbzEtTu5HffQ61Q Y7fl4QZwWeaUkwkZGRf47uV5JK9BkVx3z+0Dpo9mgzyYxYLsIf+XLC9Xq6kPdKHZ6Tj6 xUtw== 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=75NYyg2MzDh7JHqOjbkZr264VB2c7/ztlKtroNnveXE=; b=ELOrG9BWi5OgMjX7clwCVRZkuK3+YuFYTfZ/XmetrSG5utGYCyTPH8qnQ1xUHr0D9+ KieXIeVlk8TiJZXzl4uL4cMpmwWaaAKBi4MjCoKbIz0h2oO0Zf49UuEgOTovNUksfRvf OFpAaemxucx4BWuukY0Bs9lEsPzI9D8OD1utrYaox8i6A9ZAswGbzSDxpuRb7TUvEYFo hsS9AjChW+j4nSYFmlQDXTu31kFJJnrPqrkuaxzpMbii38FZIislw7XGLdpq/Xvsz8Io ARiD60nvA/4OmvnaPMsE49i1VXlxlBzPyGyKJD4Ffnn0khwrcjBI+piDtqVOWCSEY8UX ylEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=eivyfovu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i21-20020a05640242d500b00412c5f554a7si10936327edc.554.2022.03.07.02.11.14; Mon, 07 Mar 2022 02:11:37 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=eivyfovu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S237678AbiCGJgs (ORCPT + 99 others); Mon, 7 Mar 2022 04:36:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36080 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238394AbiCGJ3J (ORCPT ); Mon, 7 Mar 2022 04:29:09 -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 CDFFA66CBF; Mon, 7 Mar 2022 01:27:17 -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 B5577B810B9; Mon, 7 Mar 2022 09:26:45 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E6F8CC340E9; Mon, 7 Mar 2022 09:26:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1646645204; bh=skb8VFSxszaHC1cX8xxG98ShO75j/DooKPFIUjJJWxg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eivyfovurKWDKPOv3OepYGQs6ELeQ/UbBkt4fzjfR+KxbAlWrmNqwKnMtVfNve19O YsyZjMQ8J4rkIYzuO8het7W7wnZFWOhuowyKnC87CtAb9toRPdum392qQUHXE0sa6J ljzvOHfwqfFd/H1OD9/OspPHlhLtaC8U5V43SaTI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Leon Romanovsky , Steffen Klassert Subject: [PATCH 5.4 20/64] xfrm: enforce validity of offload input flags Date: Mon, 7 Mar 2022 10:18:53 +0100 Message-Id: <20220307091639.720028048@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220307091639.136830784@linuxfoundation.org> References: <20220307091639.136830784@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Leon Romanovsky commit 7c76ecd9c99b6e9a771d813ab1aa7fa428b3ade1 upstream. struct xfrm_user_offload has flags variable that received user input, but kernel didn't check if valid bits were provided. It caused a situation where not sanitized input was forwarded directly to the drivers. For example, XFRM_OFFLOAD_IPV6 define that was exposed, was used by strongswan, but not implemented in the kernel at all. As a solution, check and sanitize input flags to forward XFRM_OFFLOAD_INBOUND to the drivers. Fixes: d77e38e612a0 ("xfrm: Add an IPsec hardware offloading API") Signed-off-by: Leon Romanovsky Signed-off-by: Steffen Klassert Signed-off-by: Greg Kroah-Hartman --- include/uapi/linux/xfrm.h | 6 ++++++ net/xfrm/xfrm_device.c | 6 +++++- 2 files changed, 11 insertions(+), 1 deletion(-) --- a/include/uapi/linux/xfrm.h +++ b/include/uapi/linux/xfrm.h @@ -504,6 +504,12 @@ struct xfrm_user_offload { int ifindex; __u8 flags; }; +/* This flag was exposed without any kernel code that supporting it. + * Unfortunately, strongswan has the code that uses sets this flag, + * which makes impossible to reuse this bit. + * + * So leave it here to make sure that it won't be reused by mistake. + */ #define XFRM_OFFLOAD_IPV6 1 #define XFRM_OFFLOAD_INBOUND 2 --- a/net/xfrm/xfrm_device.c +++ b/net/xfrm/xfrm_device.c @@ -206,6 +206,9 @@ int xfrm_dev_state_add(struct net *net, if (x->encap || x->tfcpad) return -EINVAL; + if (xuo->flags & ~(XFRM_OFFLOAD_IPV6 | XFRM_OFFLOAD_INBOUND)) + return -EINVAL; + dev = dev_get_by_index(net, xuo->ifindex); if (!dev) { if (!(xuo->flags & XFRM_OFFLOAD_INBOUND)) { @@ -243,7 +246,8 @@ int xfrm_dev_state_add(struct net *net, xso->dev = dev; xso->num_exthdrs = 1; - xso->flags = xuo->flags; + /* Don't forward bit that is not implemented */ + xso->flags = xuo->flags & ~XFRM_OFFLOAD_IPV6; err = dev->xfrmdev_ops->xdo_dev_state_add(x); if (err) {