Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp6778591rwn; Tue, 13 Sep 2022 08:55:11 -0700 (PDT) X-Google-Smtp-Source: AA6agR4E36ve0NIHH3/5Ssik/my6aj9mBpP/KDOr4rWNNmkbgZvGQonslYf3+1Izih3rusJahtUK X-Received: by 2002:a17:907:6297:b0:72f:9aad:fcb with SMTP id nd23-20020a170907629700b0072f9aad0fcbmr22303252ejc.161.1663084511146; Tue, 13 Sep 2022 08:55:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663084511; cv=none; d=google.com; s=arc-20160816; b=z2rzFrZ1BxSxa4CGdX9AZhHeUmEuIKa+svwEyPDA/prYgh42AfJuixkOwuQaw9PI0p o+RrzupmcnOPfJ3rgUxsILd8ZvxdK8SFx50l04SAdSJfVwRjyZTsX/84E8GmoLj6ofvH 0bGuVIo5pElEOpAESSvJ5CPchCL2PmVHw0YEO0NwxEL6+QA9GcqEXIGIZHJj0890O7V0 azyTMslP6wr+VwxOVrichmhHlxamLCcBUOYphrui9qK1tDMRP8Ffxx2id0T13OgDmyeO /M0dlm/mWKKNRPvqvbG5WjKvw59ybV7PgfieZq8QRHvfhD9S+p9gvkLDF59t00gokOhU hFlQ== 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=mdW6FyoGx2BSun2hih9lU3oVw0uYVCugKfH4DjAVZ78=; b=weKEsfCIJmeoL2VoxRPRU7T6TY4DW/HgE5Di94pjCQweR8TrJzgtq5gHWt8FLLjLre 9wuoNQXzl7g1wVAU5Na+ImcBWKq5LlIwPD/GZcCXcYWvxmBkI2LK31tiQcP/c+y/OM9w CweXkFjz4TllCSi2k3t8GIhHsadxaY5N8XqVWPeJZjNNKYeiCVy7n0fV8F70nNteBuc1 tCRQ3o4FLrR0CU6Daz7VgWi+RTY9m3qnXyt5wW2FK5bnj05dlWSOlJZi+WbG7te0IIXC GM44Sp4ibOoKiQNpKk+LTWTQHQ4cqkMg+8HO9/mB54nQm1nCXHjJADUr0UZpgu8DPhsK 21Jg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=xdxW8yCj; 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 hr42-20020a1709073faa00b0077fad1e7d16si3376616ejc.371.2022.09.13.08.54.45; Tue, 13 Sep 2022 08:55:11 -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=xdxW8yCj; 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 S231146AbiIMPbZ (ORCPT + 99 others); Tue, 13 Sep 2022 11:31:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39678 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236653AbiIMP3S (ORCPT ); Tue, 13 Sep 2022 11:29:18 -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 1E5B8B846; Tue, 13 Sep 2022 07:39:54 -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 D852FB80F9C; Tue, 13 Sep 2022 14:35:58 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 312F7C43140; Tue, 13 Sep 2022 14:35:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1663079757; bh=gF/NFCBwJR+rpMhh5ZAUWokS9BviWbSmkaDiQ6eEz5Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xdxW8yCjhJVEDk7PIjrpyJNQwuFGX+TN1VUINxbp9qHzsI5fa4yGoNQNr0TN2YV0m 7LyIYRhIkTQ6vz1EcKK5WHmTXzn5TaQ9KUw/6gmiip9EnXei70ok7FKqsmZ96LEkVT OHiJgo+IxEj7Ce5/MudLW6vaue8VaM/TNJ58q1Yo= 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.14 54/61] ipv6: sr: fix out-of-bounds read when setting HMAC data. Date: Tue, 13 Sep 2022 16:07:56 +0200 Message-Id: <20220913140349.162337924@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220913140346.422813036@linuxfoundation.org> References: <20220913140346.422813036@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 fdeb90dd1c824..9c45165fe79bb 100644 --- a/net/ipv6/seg6.c +++ b/net/ipv6/seg6.c @@ -129,6 +129,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