Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp6819160rwn; Tue, 13 Sep 2022 09:23:09 -0700 (PDT) X-Google-Smtp-Source: AA6agR66z2TMa30DLJniWLbtVuWgAXqZfV9/4KAf/Y0itP+KfBii+UFRcYiJK8OteL7x8o3YUDFu X-Received: by 2002:a17:902:e94c:b0:171:3df0:c886 with SMTP id b12-20020a170902e94c00b001713df0c886mr33090429pll.39.1663086189698; Tue, 13 Sep 2022 09:23:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663086189; cv=none; d=google.com; s=arc-20160816; b=eYkkNK59xH/UD48SuBJqpO/5p8iwcprwVLvbI5cSZeshcfYMWRsoI+wvc9PfpWmiwB FAnwonRF+JpXVJiDy3Vog0mCd3SE2TMN5HSOFpdqbBi66oeNhVCOEqjmWTUgqYzTjUu+ BiCjI3C6+O65kTGBzMPGOOzoHTDjZqP7BOK91Fh8ex90ZQHa4RYInk3OPL4glsFbjwLG ZwiAyvOthGhBL1ctEXiY+j/ruX35DyBSsfTx0eJsomHyGE6ZGg6+uQyJFnQCXRFeS7HF JMmFml/iGz64hNrd5IBEmoV2h+WTXNfqxoUdd+iBla3vUPCtB9hpuyI7f5+8XyCUrk5g 4s7Q== 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=jBXLBBSYMrRBSohyYX8JRuX9SbhY8a+b9qPxHPFshLg=; b=mNejsLMVP0/bCrspEdqCgMsvDeLAA+CuHLkphAei3Eed6AJdVQaJd0qd/EisL3N2+F ntQcdfDe8BDK/GRdCVLjujBC3+ci8PT5KMTc2XVapNjXNHYsowGFlQ1wXzXnYi+MvgXd qJhwhh8yKPPa3Vrf1pkyCJ8YCj9QtTECb/sqVT/qHgdDmoek+0TWlwJcDGFE9C9bCyYP ZrLvg23ub66FCNnz1X8hV+N4ub0z8LzUEF3axHUZ1CigxDJ/BthoHW+KOWFwvUvHtZQn XUEl0q1Ak6ewOIGIEVj3d5DoPqjor1qCHUvFs+SmEsYgjX1CPzC/0q0sz90eU9j7zicQ MeJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Xlyw0TV4; 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 21-20020a630015000000b004395afacb7csi701775pga.214.2022.09.13.09.22.57; Tue, 13 Sep 2022 09:23:09 -0700 (PDT) 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=Xlyw0TV4; 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 S230496AbiIMOkQ (ORCPT + 99 others); Tue, 13 Sep 2022 10:40:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41934 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234339AbiIMOh3 (ORCPT ); Tue, 13 Sep 2022 10:37:29 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C608A6B8F1; Tue, 13 Sep 2022 07:20:32 -0700 (PDT) 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 91CDB614D5; Tue, 13 Sep 2022 14:20:02 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9A161C433D6; Tue, 13 Sep 2022 14:20:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1663078802; bh=1+F6PgY2/+sVO0lv3naVynzM8gOaXgIPLfy9D+Pq0mc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Xlyw0TV4I9yXXGhxRriU3hmFywVotTMA4wsf7S0+Xl2KBRYMXosotSKlDPdt3uubd cNNDlvaR4saxQfsYwvTGL7+Axapc7+rjM1kU1lW135x6SQs26d3QSmEPtaEOUHjC4M xoDb+2dlCgTqAV5UvfiaCkHrELbigLY26greIHLQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Lucas Leong , David Lebrun , "David S. Miller" , Sasha Levin Subject: [PATCH 5.15 087/121] ipv6: sr: fix out-of-bounds read when setting HMAC data. Date: Tue, 13 Sep 2022 16:04:38 +0200 Message-Id: <20220913140401.105749657@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220913140357.323297659@linuxfoundation.org> References: <20220913140357.323297659@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 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: David Lebrun [ Upstream commit 84a53580c5d2138c7361c7c3eea5b31827e63b35 ] The SRv6 layer allows defining HMAC data that can later be used to sign IPv6 Segment Routing Headers. This configuration is realised via netlink through four attributes: SEG6_ATTR_HMACKEYID, SEG6_ATTR_SECRET, SEG6_ATTR_SECRETLEN and SEG6_ATTR_ALGID. Because the SECRETLEN attribute is decoupled from the actual length of the SECRET attribute, it is possible to provide invalid combinations (e.g., secret = "", secretlen = 64). This case is not checked in the code and with an appropriately crafted netlink message, an out-of-bounds read of up to 64 bytes (max secret length) can occur past the skb end pointer and into skb_shared_info: Breakpoint 1, seg6_genl_sethmac (skb=, info=) at net/ipv6/seg6.c:208 208 memcpy(hinfo->secret, secret, slen); (gdb) bt #0 seg6_genl_sethmac (skb=, info=) at net/ipv6/seg6.c:208 #1 0xffffffff81e012e9 in genl_family_rcv_msg_doit (skb=skb@entry=0xffff88800b1f9f00, nlh=nlh@entry=0xffff88800b1b7600, extack=extack@entry=0xffffc90000ba7af0, ops=ops@entry=0xffffc90000ba7a80, hdrlen=4, net=0xffffffff84237580 , family=, family=) at net/netlink/genetlink.c:731 #2 0xffffffff81e01435 in genl_family_rcv_msg (extack=0xffffc90000ba7af0, nlh=0xffff88800b1b7600, skb=0xffff88800b1f9f00, family=0xffffffff82fef6c0 ) at net/netlink/genetlink.c:775 #3 genl_rcv_msg (skb=0xffff88800b1f9f00, nlh=0xffff88800b1b7600, extack=0xffffc90000ba7af0) at net/netlink/genetlink.c:792 #4 0xffffffff81dfffc3 in netlink_rcv_skb (skb=skb@entry=0xffff88800b1f9f00, cb=cb@entry=0xffffffff81e01350 ) at net/netlink/af_netlink.c:2501 #5 0xffffffff81e00919 in genl_rcv (skb=0xffff88800b1f9f00) at net/netlink/genetlink.c:803 #6 0xffffffff81dff6ae in netlink_unicast_kernel (ssk=0xffff888010eec800, skb=0xffff88800b1f9f00, sk=0xffff888004aed000) at net/netlink/af_netlink.c:1319 #7 netlink_unicast (ssk=ssk@entry=0xffff888010eec800, skb=skb@entry=0xffff88800b1f9f00, portid=portid@entry=0, nonblock=) at net/netlink/af_netlink.c:1345 #8 0xffffffff81dff9a4 in netlink_sendmsg (sock=, msg=0xffffc90000ba7e48, len=) at net/netlink/af_netlink.c:1921 ... (gdb) p/x ((struct sk_buff *)0xffff88800b1f9f00)->head + ((struct sk_buff *)0xffff88800b1f9f00)->end $1 = 0xffff88800b1b76c0 (gdb) p/x secret $2 = 0xffff88800b1b76c0 (gdb) p slen $3 = 64 '@' The OOB data can then be read back from userspace by dumping HMAC state. This commit fixes this by ensuring SECRETLEN cannot exceed the actual length of SECRET. Reported-by: Lucas Leong Tested: verified that EINVAL is correctly returned when secretlen > len(secret) Fixes: 4f4853dc1c9c1 ("ipv6: sr: implement API to control SR HMAC structure") Signed-off-by: David Lebrun Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- net/ipv6/seg6.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/net/ipv6/seg6.c b/net/ipv6/seg6.c index fa6b64c95d3ae..0c7c6fc16c3c3 100644 --- a/net/ipv6/seg6.c +++ b/net/ipv6/seg6.c @@ -191,6 +191,11 @@ static int seg6_genl_sethmac(struct sk_buff *skb, struct genl_info *info) goto out_unlock; } + if (slen > nla_len(info->attrs[SEG6_ATTR_SECRET])) { + err = -EINVAL; + goto out_unlock; + } + if (hinfo) { err = seg6_hmac_info_del(net, hmackeyid); if (err) -- 2.35.1