From patchwork Fri Dec 31 00:36:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Ahern X-Patchwork-Id: 12701744 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7B2A0C433FE for ; Fri, 31 Dec 2021 00:36:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242385AbhLaAgq (ORCPT ); Thu, 30 Dec 2021 19:36:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60116 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242376AbhLaAgo (ORCPT ); Thu, 30 Dec 2021 19:36:44 -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 26176C06173F for ; Thu, 30 Dec 2021 16:36:44 -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 3F64A61767 for ; Fri, 31 Dec 2021 00:36:41 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E738CC36AED; Fri, 31 Dec 2021 00:36:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1640911000; bh=SADsJkcvRyqA8lYJUXxAYJpuycgbiWK2zcclMETF26I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aZtvrGFAh/yIcY0GyN5J+ctfPwmo3rH03J7fpbGt8cS+A+tcGsJshD/6MK+q63KAb sqQX/89Bglbpu6eEWsQFO2g34106XFgJAN0IjJnJeBSnx0Cvx7uarrvm/KGe8W1fHY 8eg4zUXIb5Zv1xtqzgQcKD82aYDtHgIJ/xbOxGSVeUWgQr9KxIdcQWCaqiyH9zaJ6m zPkcPmh6EQK/wO634ZOTthjCAJN60ZLraoW2iUtwLjKC1+QVhyNjo6uSXLIbp7WWVq yygOumYQvW5Q+m9R8M9HVmpCIn2K/PyVMF61GJdiMAFtw7paOJa2mtGgn38sqZm8Yt E8foQFHlf3IbQ== From: David Ahern To: netdev@vger.kernel.org Cc: idosch@idosch.org, David Ahern , syzbot+d4b9a2851cc3ce998741@syzkaller.appspotmail.com, Thomas Graf Subject: [PATCH net 1/5] ipv4: Check attribute length for RTA_GATEWAY in multipath route Date: Thu, 30 Dec 2021 17:36:31 -0700 Message-Id: <20211231003635.91219-2-dsahern@kernel.org> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20211231003635.91219-1-dsahern@kernel.org> References: <20211231003635.91219-1-dsahern@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org syzbot reported uninit-value: ============================================================ BUG: KMSAN: uninit-value in fib_get_nhs+0xac4/0x1f80 net/ipv4/fib_semantics.c:708 fib_get_nhs+0xac4/0x1f80 net/ipv4/fib_semantics.c:708 fib_create_info+0x2411/0x4870 net/ipv4/fib_semantics.c:1453 fib_table_insert+0x45c/0x3a10 net/ipv4/fib_trie.c:1224 inet_rtm_newroute+0x289/0x420 net/ipv4/fib_frontend.c:886 Add helper to validate RTA_GATEWAY length before using the attribute. Fixes: 4e902c57417c ("[IPv4]: FIB configuration using struct fib_config") Reported-by: syzbot+d4b9a2851cc3ce998741@syzkaller.appspotmail.com Signed-off-by: David Ahern Cc: Thomas Graf --- net/ipv4/fib_semantics.c | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c index fde7797b5806..f1caa2c1c041 100644 --- a/net/ipv4/fib_semantics.c +++ b/net/ipv4/fib_semantics.c @@ -662,6 +662,19 @@ static int fib_count_nexthops(struct rtnexthop *rtnh, int remaining, return nhs; } +static int fib_gw_from_attr(__be32 *gw, struct nlattr *nla, + struct netlink_ext_ack *extack) +{ + if (nla_len(nla) < sizeof(*gw)) { + NL_SET_ERR_MSG(extack, "Invalid IPv4 address in RTA_GATEWAY"); + return -EINVAL; + } + + *gw = nla_get_in_addr(nla); + + return 0; +} + /* only called when fib_nh is integrated into fib_info */ static int fib_get_nhs(struct fib_info *fi, struct rtnexthop *rtnh, int remaining, struct fib_config *cfg, @@ -704,7 +717,11 @@ static int fib_get_nhs(struct fib_info *fi, struct rtnexthop *rtnh, return -EINVAL; } if (nla) { - fib_cfg.fc_gw4 = nla_get_in_addr(nla); + ret = fib_gw_from_attr(&fib_cfg.fc_gw4, nla, + extack); + if (ret) + goto errout; + if (fib_cfg.fc_gw4) fib_cfg.fc_gw_family = AF_INET; } else if (nlav) { @@ -902,6 +919,7 @@ int fib_nh_match(struct net *net, struct fib_config *cfg, struct fib_info *fi, attrlen = rtnh_attrlen(rtnh); if (attrlen > 0) { struct nlattr *nla, *nlav, *attrs = rtnh_attrs(rtnh); + int err; nla = nla_find(attrs, attrlen, RTA_GATEWAY); nlav = nla_find(attrs, attrlen, RTA_VIA); @@ -912,12 +930,17 @@ int fib_nh_match(struct net *net, struct fib_config *cfg, struct fib_info *fi, } if (nla) { + __be32 gw; + + err = fib_gw_from_attr(&gw, nla, extack); + if (err) + return err; + if (nh->fib_nh_gw_family != AF_INET || - nla_get_in_addr(nla) != nh->fib_nh_gw4) + gw != nh->fib_nh_gw4) return 1; } else if (nlav) { struct fib_config cfg2; - int err; err = fib_gw_from_via(&cfg2, nlav, extack); if (err) From patchwork Fri Dec 31 00:36:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Ahern X-Patchwork-Id: 12701742 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5957FC4332F for ; Fri, 31 Dec 2021 00:36:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242384AbhLaAgp (ORCPT ); Thu, 30 Dec 2021 19:36:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60112 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242373AbhLaAgo (ORCPT ); Thu, 30 Dec 2021 19:36:44 -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 1BF5BC061574 for ; Thu, 30 Dec 2021 16:36:44 -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 0A5F461702 for ; Fri, 31 Dec 2021 00:36:42 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E3FCFC36AEC; Fri, 31 Dec 2021 00:36:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1640911001; bh=FkM2kTZooDmAT+imxE0vorlpfxtNhXDGVhVk06kN5K0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jzE0k56ZzvRr780UwCsf6yRhdaCo9EDkCUllqO+w8fdKZUSCHkFKHDpcZgt9iVGdV tCGr3DuzRwc0l8iMgwz4RS+94pbIr53gHrczH5mNsmljQSu1+8Stu++rdAnmAX4sXr NmeojMp1P8Ncvyt2gU4YQ6eErU3OSetGLChM9kgXyD4ZzsVwUTie17qwFit+RxQX4d YByG478Iy39CbXjKkFbtG6v4T2OU9u0YwHNX2bZA9xNjgpptoVMgPyxcFAtelHzaOm QLpSmmnMAuT5UaO/gSJinnroKm3YM5seYbStlqX1uMstYxcOwa+S0VqoCyrvqTbrBA QSQUBckSwy8Fg== From: David Ahern To: netdev@vger.kernel.org Cc: idosch@idosch.org, David Ahern Subject: [PATCH net 2/5] ipv4: Check attribute length for RTA_FLOW in multipath route Date: Thu, 30 Dec 2021 17:36:32 -0700 Message-Id: <20211231003635.91219-3-dsahern@kernel.org> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20211231003635.91219-1-dsahern@kernel.org> References: <20211231003635.91219-1-dsahern@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Make sure RTA_FLOW is at least 4B before using. Fixes: 4e902c57417c ("[IPv4]: FIB configuration using struct fib_config") Signed-off-by: David Ahern --- net/ipv4/fib_semantics.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c index f1caa2c1c041..36bc429f1635 100644 --- a/net/ipv4/fib_semantics.c +++ b/net/ipv4/fib_semantics.c @@ -731,8 +731,13 @@ static int fib_get_nhs(struct fib_info *fi, struct rtnexthop *rtnh, } nla = nla_find(attrs, attrlen, RTA_FLOW); - if (nla) + if (nla) { + if (nla_len(nla) < sizeof(u32)) { + NL_SET_ERR_MSG(extack, "Invalid RTA_FLOW"); + return -EINVAL; + } fib_cfg.fc_flow = nla_get_u32(nla); + } fib_cfg.fc_encap = nla_find(attrs, attrlen, RTA_ENCAP); nla = nla_find(attrs, attrlen, RTA_ENCAP_TYPE); @@ -963,8 +968,14 @@ int fib_nh_match(struct net *net, struct fib_config *cfg, struct fib_info *fi, #ifdef CONFIG_IP_ROUTE_CLASSID nla = nla_find(attrs, attrlen, RTA_FLOW); - if (nla && nla_get_u32(nla) != nh->nh_tclassid) - return 1; + if (nla) { + if (nla_len(nla) < sizeof(u32)) { + NL_SET_ERR_MSG(extack, "Invalid RTA_FLOW"); + return -EINVAL; + } + if (nla_get_u32(nla) != nh->nh_tclassid) + return 1; + } #endif } From patchwork Fri Dec 31 00:36:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Ahern X-Patchwork-Id: 12701740 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3D016C433EF for ; Fri, 31 Dec 2021 00:36:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242379AbhLaAgo (ORCPT ); Thu, 30 Dec 2021 19:36:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60114 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242375AbhLaAgo (ORCPT ); Thu, 30 Dec 2021 19:36:44 -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 216BBC06173E for ; Thu, 30 Dec 2021 16:36:44 -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 E12FC6176C for ; Fri, 31 Dec 2021 00:36:42 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B3410C36AEA; Fri, 31 Dec 2021 00:36:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1640911002; bh=bDBXM+NHGraNqtKnX/tgY3lhc10v0kGbQBjowg0ItGg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IuYfqjENEZ6P+hF15ocid3IXInkRI2BdjAJOuMBfMGjRGz06h68LmJ6gSnbuFW6/7 qbl3VOf4KwYcuCkgIEaJSqDi7TDV+2USYhdYJLBeAvGs18XOjb1YQ++YGmJs13Tt9K Z2999ILPjGS7wZoG9hp2IqsAolvCOm4cXGa3XAqlWV9g1A7doWRWFnPfb+pd2tGKS9 xz4+SvYZj4nU2lzg4zaDNpNqMtTPgO/3CEvJDVwvnRyCgqGK2Eiefhlrsfjbts/MpA ujffruJ9BCbYBS8YjJPuuDlIEeKQ+bM8jr/PCBUeHSSRliBJcbKEXZaRRw3iRpjK+S 27cRrheokPQzA== From: David Ahern To: netdev@vger.kernel.org Cc: idosch@idosch.org, David Ahern , Nicolas Dichtel Subject: [PATCH net 3/5] ipv6: Check attribute length for RTA_GATEWAY in multipath route Date: Thu, 30 Dec 2021 17:36:33 -0700 Message-Id: <20211231003635.91219-4-dsahern@kernel.org> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20211231003635.91219-1-dsahern@kernel.org> References: <20211231003635.91219-1-dsahern@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Commit referenced in the Fixes tag used nla_memcpy for RTA_GATEWAY as does the current nla_get_in6_addr. nla_memcpy protects against accessing memory greater than what is in the attribute, but there is no check requiring the attribute to have an IPv6 address. Add it. Fixes: 51ebd3181572 ("ipv6: add support of equal cost multipath (ECMP)") Signed-off-by: David Ahern Cc: Nicolas Dichtel --- net/ipv6/route.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/net/ipv6/route.c b/net/ipv6/route.c index 42d60c76d30a..d16599c225b8 100644 --- a/net/ipv6/route.c +++ b/net/ipv6/route.c @@ -5224,6 +5224,19 @@ static bool ip6_route_mpath_should_notify(const struct fib6_info *rt) return should_notify; } +static int fib6_gw_from_attr(struct in6_addr *gw, struct nlattr *nla, + struct netlink_ext_ack *extack) +{ + if (nla_len(nla) < sizeof(*gw)) { + NL_SET_ERR_MSG(extack, "Invalid IPv6 address in RTA_GATEWAY"); + return -EINVAL; + } + + *gw = nla_get_in6_addr(nla); + + return 0; +} + static int ip6_route_multipath_add(struct fib6_config *cfg, struct netlink_ext_ack *extack) { @@ -5264,7 +5277,13 @@ static int ip6_route_multipath_add(struct fib6_config *cfg, nla = nla_find(attrs, attrlen, RTA_GATEWAY); if (nla) { - r_cfg.fc_gateway = nla_get_in6_addr(nla); + int ret; + + ret = fib6_gw_from_attr(&r_cfg.fc_gateway, nla, + extack); + if (ret) + return ret; + r_cfg.fc_flags |= RTF_GATEWAY; } r_cfg.fc_encap = nla_find(attrs, attrlen, RTA_ENCAP); From patchwork Fri Dec 31 00:36:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Ahern X-Patchwork-Id: 12701741 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 493CEC433F5 for ; Fri, 31 Dec 2021 00:36:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242381AbhLaAgo (ORCPT ); Thu, 30 Dec 2021 19:36:44 -0500 Received: from dfw.source.kernel.org ([139.178.84.217]:58348 "EHLO dfw.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233018AbhLaAgo (ORCPT ); Thu, 30 Dec 2021 19:36:44 -0500 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 CED3F61772 for ; Fri, 31 Dec 2021 00:36:43 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 97C72C36AEC; Fri, 31 Dec 2021 00:36:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1640911003; bh=deIr3FoAlbA96ie3jUkKI8/XCel534VYawwRtJPtuHQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uE93gRhL/bwJzCcv4Y5lYjPP/Se+piX5iR8eWVxkocD5zOKaoZhmUYwW8zaRn1yjS 9lvMiEwFgo28ZySNBVZD5P4GkyV4bawO+2NqbT6KczWW+dPleSW1OY/1vox2UyLeKm 5Nnkrss1XEl5o0SzV+MIikArOT5tUhC6QJLomvIOoCslhl3KUdU63ug5ez7T9UQAkW B0I8QARdDLjLjp5JIXLLAVjAXwI2wlereKzIjMmrZvSZVtGECWbJe06ReCfd/bQlHM KPbkVbAXGSlyHNNm8gpqR8+XgFk2Y1Weeirq+K9jKd/b7fUbK9LJtX+9OhLfG9MeJS 3N7CzPiNOIZuw== From: David Ahern To: netdev@vger.kernel.org Cc: idosch@idosch.org, David Ahern , Roopa Prabhu Subject: [PATCH net 4/5] ipv6: Check attribute length for RTA_GATEWAY when deleting multipath route Date: Thu, 30 Dec 2021 17:36:34 -0700 Message-Id: <20211231003635.91219-5-dsahern@kernel.org> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20211231003635.91219-1-dsahern@kernel.org> References: <20211231003635.91219-1-dsahern@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Make sure RTA_GATEWAY for IPv6 multipath route has enough bytes to hold an IPv6 address. Fixes: 6b9ea5a64ed5 ("ipv6: fix multipath route replace error recovery") Signed-off-by: David Ahern Cc: Roopa Prabhu --- net/ipv6/route.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/net/ipv6/route.c b/net/ipv6/route.c index d16599c225b8..b311c0bc9983 100644 --- a/net/ipv6/route.c +++ b/net/ipv6/route.c @@ -5453,7 +5453,11 @@ static int ip6_route_multipath_del(struct fib6_config *cfg, nla = nla_find(attrs, attrlen, RTA_GATEWAY); if (nla) { - nla_memcpy(&r_cfg.fc_gateway, nla, 16); + err = fib6_gw_from_attr(&r_cfg.fc_gateway, nla, + extack); + if (err) + return err; + r_cfg.fc_flags |= RTF_GATEWAY; } } From patchwork Fri Dec 31 00:36:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Ahern X-Patchwork-Id: 12701745 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 579A8C433F5 for ; Fri, 31 Dec 2021 00:36:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242389AbhLaAgr (ORCPT ); Thu, 30 Dec 2021 19:36:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60120 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233018AbhLaAgp (ORCPT ); Thu, 30 Dec 2021 19:36:45 -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 0701AC06173E for ; Thu, 30 Dec 2021 16:36:45 -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 9B52961767 for ; Fri, 31 Dec 2021 00:36:44 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 84E4CC36AEB; Fri, 31 Dec 2021 00:36:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1640911004; bh=Bgnu5dlqLnOvVfWBqEybGWtgNNr1hYyoPme7431h2xo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HrrjUiuc6aFpsVyvUNbc0vSaCYhif1tO0iaPvUfkiVmZ/7uTipz0FX5aT3zzWVW8a BBHvYipuIbwo0Fo3/sLjVAkNBGHp+cMN4iUjwMJogTfBMmGMF8XjtyvPBwjtp9R4jC Y9+sIPwepFeM5x91fFLbVobTj84J4j6Xpqg/1MsMR7PgLmJHWBgdOeYtjbCKgfT0/5 89hdzmtkupc0zCcA9tNCPmbygQ23Z80RUtaU/897mgT7q5G+VjBqB8BwEz25pw8AE0 2ptNNB7j4Jtq1zNs2wzNRukaVTgMG2MSv/1drO8QYH38W+xL/uLPWBvgaDCT4VqziE f7l5RufildhgQ== From: David Ahern To: netdev@vger.kernel.org Cc: idosch@idosch.org, David Ahern Subject: [PATCH net 5/5] lwtunnel: Validate RTA_ENCAP_TYPE attribute length Date: Thu, 30 Dec 2021 17:36:35 -0700 Message-Id: <20211231003635.91219-6-dsahern@kernel.org> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20211231003635.91219-1-dsahern@kernel.org> References: <20211231003635.91219-1-dsahern@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org lwtunnel_valid_encap_type_attr is used to validate encap attributes within a multipath route. Add length validation checking to the type. lwtunnel_valid_encap_type_attr is called converting attributes to fib{6,}_config struct which means it is used before fib_get_nhs, ip6_route_multipath_add, and ip6_route_multipath_del - other locations that use rtnh_ok and then nla_get_u16 on RTA_ENCAP_TYPE attribute. Fixes: 9ed59592e3e3 ("lwtunnel: fix autoload of lwt modules") Signed-off-by: David Ahern --- net/core/lwtunnel.c | 4 ++++ net/ipv4/fib_semantics.c | 3 +++ net/ipv6/route.c | 4 ++++ 3 files changed, 11 insertions(+) diff --git a/net/core/lwtunnel.c b/net/core/lwtunnel.c index 2820aca2173a..9ccd64e8a666 100644 --- a/net/core/lwtunnel.c +++ b/net/core/lwtunnel.c @@ -197,6 +197,10 @@ int lwtunnel_valid_encap_type_attr(struct nlattr *attr, int remaining, nla_entype = nla_find(attrs, attrlen, RTA_ENCAP_TYPE); if (nla_entype) { + if (nla_len(nla_entype) < sizeof(u16)) { + NL_SET_ERR_MSG(extack, "Invalid RTA_ENCAP_TYPE"); + return -EINVAL; + } encap_type = nla_get_u16(nla_entype); if (lwtunnel_valid_encap_type(encap_type, diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c index 36bc429f1635..92c29ab3d042 100644 --- a/net/ipv4/fib_semantics.c +++ b/net/ipv4/fib_semantics.c @@ -740,6 +740,9 @@ static int fib_get_nhs(struct fib_info *fi, struct rtnexthop *rtnh, } fib_cfg.fc_encap = nla_find(attrs, attrlen, RTA_ENCAP); + /* RTA_ENCAP_TYPE length checked in + * lwtunnel_valid_encap_type_attr + */ nla = nla_find(attrs, attrlen, RTA_ENCAP_TYPE); if (nla) fib_cfg.fc_encap_type = nla_get_u16(nla); diff --git a/net/ipv6/route.c b/net/ipv6/route.c index b311c0bc9983..d2ff8a7e1709 100644 --- a/net/ipv6/route.c +++ b/net/ipv6/route.c @@ -5287,6 +5287,10 @@ static int ip6_route_multipath_add(struct fib6_config *cfg, r_cfg.fc_flags |= RTF_GATEWAY; } r_cfg.fc_encap = nla_find(attrs, attrlen, RTA_ENCAP); + + /* RTA_ENCAP_TYPE length checked in + * lwtunnel_valid_encap_type_attr + */ nla = nla_find(attrs, attrlen, RTA_ENCAP_TYPE); if (nla) r_cfg.fc_encap_type = nla_get_u16(nla);