Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp6782217rwn; Tue, 13 Sep 2022 08:58:19 -0700 (PDT) X-Google-Smtp-Source: AA6agR76FbEy5KWzLecpp97MQE2R0c3BieUXwj/uMBpdjg/YjGuRVnUe+5u23y/yhA1J7azSHuMq X-Received: by 2002:a17:907:1c93:b0:77e:f9a2:6fca with SMTP id nb19-20020a1709071c9300b0077ef9a26fcamr5516562ejc.320.1663084698806; Tue, 13 Sep 2022 08:58:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663084698; cv=none; d=google.com; s=arc-20160816; b=GPrwfKFVMhhfQBjSVZq26MUzzbsQf839fAhVZYHBuHRO0xK/AW4UIJGzjZtgESwwYl JcqCSPaXHgVuezMkNwcz87wcAs2HxDQvrkS66o/vYLMuQ7CkhZUZLgd62+kTpZDtwb2Y hNdfeCNFFlhoS+soAOH3Ag/STzTCTFjc+mKBPT6HjBRrDGik2Mlt4Zjv3KRosLnVBI/A 97w2d/GZu377bWjCNqIWbiYKQln0agArw1amycaCEhwX5QDHRCrazCOOVc3RAcLN/Yug NRGe+OR/Wik6b2OYwhLhtFNBmcPQUeRloT4nhKnKCoL5qCpIvkNlFief6qRdB28yiblL 1ZvQ== 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=BQL3j4zS/wb3wa9jP8IZMp22IQr+5Ui7EMHdSxY5I0Q=; b=mVC04cvFsxu5fr2bn4C5/Mw3vjkiB4zShrc9IUcys5i1ehJuwJaoVhbvPXu7QRXbsY hhZYel/2ZA5ZZTfhPwKoaKfYCbWUUx6BQ/9zbhaUM/ywJkYxyZm4BahUW69c6emfadCx N4Xn5eGpNUNwE+5uIcpa8qCawbeCYgMdaCOKpN8mT2Jh+PTld3C0haJL9539pihDbkf8 D3PCKN3HwEWvv74vVcMgDZngS1cYG5FF4wyaM7k9NOshqUtb4eCAUl+EiXOjH/F9DpEm H1ac1QblHm6hh5KKeDbg37spuGptJ+O+QRreurlZwXR8in97iIUwvnrKzwivQpR2zlwa 4xIw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=inyzrq5z; 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 ne18-20020a1709077b9200b0076f23cf9c76si9017775ejc.195.2022.09.13.08.57.50; Tue, 13 Sep 2022 08:58:18 -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=inyzrq5z; 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 S234709AbiIMPju (ORCPT + 99 others); Tue, 13 Sep 2022 11:39:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52554 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236751AbiIMPiz (ORCPT ); Tue, 13 Sep 2022 11:38:55 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 38C061D312; Tue, 13 Sep 2022 07:44:51 -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 301ED614E8; Tue, 13 Sep 2022 14:32:47 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 37A84C433D6; Tue, 13 Sep 2022 14:32:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1663079566; bh=tX03YbG5xQzb4/Y3x2p/k5J6xQjGknZ9Qh7bB8dvKcY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=inyzrq5z1xoGVXK/ketVINcy5lTh+6DmimwNH+S1Xf0+UQDcldb5mdeXdhuSuYzw5 2wQbWkk/wCUStxWJ77UGW2lD3oZHTNY4dph/muZ36PvGfuCdneaixwKHdscsDI5h+6 HQFg8OvLRM9kK1GZ1AF7BaMOjNMiKwc8f5fwYqLU= 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 4.19 69/79] ipv6: sr: fix out-of-bounds read when setting HMAC data. Date: Tue, 13 Sep 2022 16:07:27 +0200 Message-Id: <20220913140352.232989050@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220913140348.835121645@linuxfoundation.org> References: <20220913140348.835121645@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 9b2f272ca1649..89d55770ac74b 100644 --- a/net/ipv6/seg6.c +++ b/net/ipv6/seg6.c @@ -130,6 +130,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