Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp1797837pxp; Mon, 7 Mar 2022 02:34:48 -0800 (PST) X-Google-Smtp-Source: ABdhPJzH0GLA0aCA7jYhfx1/2YGz+RHqy1z2Q7VGoum0qtb+UL/DQB9V9FDPA7mC7PtjBKOHH1HC X-Received: by 2002:a17:90a:c302:b0:1bd:14ff:15 with SMTP id g2-20020a17090ac30200b001bd14ff0015mr23856302pjt.19.1646649288627; Mon, 07 Mar 2022 02:34:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646649288; cv=none; d=google.com; s=arc-20160816; b=qJqmQ/H8AZ7p1ZeNEihPvf7Xz302Yts6ypsQfY+87We0mbdMvxYLV8lb0LTsha8xAv Y4k2rNKGAq52HM3ayWauKRuBWdo2VZWj3hxqCoLcwilMBlQvFYm5Nyqcju6cmikwa3Yv 3ZoXq+f7IYi459JZEXbtuYPngR/JHbM5UAm+9em6L8uIIEEi3psHhKN+I8sTNXz24c7v j7eLD6hIZrqJ7noeyeU0d6qhID/bVaWDrZFusdXHTR4AFl/6J4/0WMD7SEhImgbmtytF fDwvrAJJaT6NjXH2Jk3pxg81DUDTs6jwbPU5qCvv8JFs5R11twvABGPPAXvjPMuzCD7E zWHw== 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=zmRSKFFPEzg/u8E1D5UYfaZWT1B5ScoUN6ZVzOf1D6c=; b=dcZFrQIUG9fBJ3eoqWwVDs49DTozookJdsxSLYhSHFlJX4tsCiYptnnEKZu0OrU/N2 x5f/WfpGlzTP+yfQsdaCkBFQOw0HAxZXvaCk4kfGh2qn3+1YesFZ0+KiaDrJf0HclsR9 pQ+9uEOLdTrwBhS4RcgHNk8Sgl9pQ/jP3h0xFHyS9w4DRN2o81OJH9GW0ZxdURFH5OQK e1TNcbJhXdnjERMbEFcFUgG8gQHqlCQT0Hn1GYkeV3BDNOqyrLke2/HQduywyi57Tnch 6xHicXbjeoPDLHWTeZ7l5VAfmurip9BaGUEF39rMjhHl+L+CiIHVLHCkwnfeAQthmivU EQGg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=jzwhSfkm; 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 mq8-20020a17090b380800b001bd33ae2c4bsi8032014pjb.6.2022.03.07.02.34.34; Mon, 07 Mar 2022 02:34:48 -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=jzwhSfkm; 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 S239573AbiCGKHl (ORCPT + 99 others); Mon, 7 Mar 2022 05:07:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53380 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239310AbiCGJta (ORCPT ); Mon, 7 Mar 2022 04:49:30 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E154547AD3; Mon, 7 Mar 2022 01:43:02 -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 DAD9AB810D2; Mon, 7 Mar 2022 09:42:58 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 10C3AC340F5; Mon, 7 Mar 2022 09:42:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1646646177; bh=Oo8c0T73WwRUB0tlUJ77/gdoT2ejqRUeLYuZyye5QNA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jzwhSfkmtMNEBnpG7LHUujw17z3viWwRF6rUYWIx/B78rrFC4v5AFnlrs1G6nyv+o p8DNAvl8eAW9Qco9NXwRHm0nLjSNBgFppLeFzWZ+sx7Cusefv6mFLOK80WbnpYBIO/ AvLJzkI+8NDaCH7gsWu1K5kvHBiaHLjl7nVVkfyw= 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.15 157/262] xfrm: enforce validity of offload input flags Date: Mon, 7 Mar 2022 10:18:21 +0100 Message-Id: <20220307091706.866568881@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220307091702.378509770@linuxfoundation.org> References: <20220307091702.378509770@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 @@ -511,6 +511,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 @@ -223,6 +223,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)) { @@ -261,7 +264,8 @@ int xfrm_dev_state_add(struct net *net, xso->dev = dev; xso->real_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) {