Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp6814360rwn; Tue, 13 Sep 2022 09:19:33 -0700 (PDT) X-Google-Smtp-Source: AMsMyM722yGdBBcqfq35b+ZTz2C5icPiSlufYyqdOnwCFVIbGKi8WCtaVpne9OC2tzrJwshjm7rb X-Received: by 2002:a17:90b:3b41:b0:202:ec53:edfa with SMTP id ot1-20020a17090b3b4100b00202ec53edfamr92994pjb.136.1663085972748; Tue, 13 Sep 2022 09:19:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663085972; cv=none; d=google.com; s=arc-20160816; b=nfqKMib8HtR/vEL0wjXfHJP31FhaOxz+aWrPPkpiTtBnAHZgDuLq+kciS/hxNG6hPq 3flPZcCEktfoaqxgka0yYv86J2BrLy1PR8MMZ8oaSgOtar2JXWv6brF+j/QT4syLMuC4 XRc4bM2OClXvnh2xQbffJR4lz5zOrFqsdtToZidtFB1TEfs2lu379G4MUeKR3CTcLVaY yFyX3zt/XVBJP2pOz4u2OBmGhP5n6kHhDM0yxIGnV/clafpuWWuC6+Bf9qMRTjcjjb+n RPZeydaIOcvyxjExUDZdN/L709fM4g8FyseYTvl08G3UEQmOmp4D1zRhmrjNyr3msu8R BOGg== 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=KLqMpckOLnaVTlOFnWZHSfD1WhYdjpFaLpQCIiw69BY=; b=ZZfTPdkA1vXOI/SwP0DxbaTnUTlo+6vTa+wsSJSRYP6NQtPDajBeauLouo6bTBSdep AcXlE9VvGRK+dleQTLyodReMZx1669Z7k7aLtyZJ84hD4432p/dSOOO8EV8CmY6uvsnE Xda8IHsCEJvpvnpYWDB/+wZ7ezZftnSGeoo0vevaLqIYmxdS79xn+lNrtUIEjdPd99di pHobT6/ezRJdr1n3xwg+fWjVvFZCs2J4bZnPMvCkWYvUIR6hfdLvm49ewBa57NF6r40y Sm7pcP6GbLHtirHKhItF9cGVZvH6VsjE2DYRKnIOr3HMRtazgSGXmoEXSDyU5nzmtv5D ibUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ckpchdgB; 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 rm12-20020a17090b3ecc00b001fa55447988si1960470pjb.40.2022.09.13.09.19.20; Tue, 13 Sep 2022 09:19:32 -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=ckpchdgB; 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 S235168AbiIMPF0 (ORCPT + 99 others); Tue, 13 Sep 2022 11:05:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42166 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235190AbiIMPDe (ORCPT ); Tue, 13 Sep 2022 11:03:34 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C7CF818B2C; Tue, 13 Sep 2022 07:29:46 -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 ams.source.kernel.org (Postfix) with ESMTPS id 784D1B80F9F; Tue, 13 Sep 2022 14:29:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AEE56C433D7; Tue, 13 Sep 2022 14:29:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1663079357; bh=p3SMMbn2Tb4NHP6ArfUjJDVojEujjaVbyoVdQcuOtGk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ckpchdgBHDwPnGXUb3mNyHKhjI19nZftaTtjqrUmm7GmVctGN02hVrNxR16MBD/O8 cWckzXQmY0eddWc6N0HSGNTUNkjRSItkkqhTlJ3KKlzIIh543f3CZ5nCFMe8PkRgDo 4l1RcB7prr1gJ6r9w3MKpkOnf4H3K1YcTLQye0/A= 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.4 102/108] ipv6: sr: fix out-of-bounds read when setting HMAC data. Date: Tue, 13 Sep 2022 16:07:13 +0200 Message-Id: <20220913140358.001088178@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220913140353.549108748@linuxfoundation.org> References: <20220913140353.549108748@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 75421a472d25a..f5c448c276fef 100644 --- a/net/ipv6/seg6.c +++ b/net/ipv6/seg6.c @@ -125,6 +125,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