Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp2876433pxu; Sat, 19 Dec 2020 05:03:58 -0800 (PST) X-Google-Smtp-Source: ABdhPJzb6KQhJlHzNDqthWMAqDAsisXfQiT4Z/4vyB2Cff2oY3jjvi2M85wwBxM9y60rYX/N0aIA X-Received: by 2002:a05:6402:1684:: with SMTP id a4mr8764592edv.348.1608383038492; Sat, 19 Dec 2020 05:03:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1608383038; cv=none; d=google.com; s=arc-20160816; b=nmaatsKSihz+GRZN0k8M/YauiQQbfo4Kh24hac2o1a7Qntym27t/fdiq/SMhV7a5Ui V/En6leQCBYObabBQp7i+8KNloOgK9K7RgABphWN3Mm106lfZ4avNgfalntZ33GlRvQ+ OIjcLq2AZh8RS36jjudYKJ6Twbp277a7JVTwKlDCKtIZDQ7Uyvgdl6qmBW2zF4+XyxDK O00+ch3kwKP1QRq3WvCepVDavkP0i4cpufwpe7yHcUwFpsEE0JgjIaRarY8j2AsjTjx6 0OCiWbmcY1APyUPleuyOJxmFV7fOJ0xm0sWoZRxpI0hFkqxIUzPU1clwp5gk/IBSwVg4 B1dA== 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; bh=uNEqUseANeyOaF4wjDzbprPisMMjqq9d4oJ4tL0ILHg=; b=MkGwDccyF/Fg2EKUC7OsBQvGjUq9U5w7CNHPHOZ/lIAlpllcfirv7hBjRQCbetNRnZ vQWnkw3nR1yD4gcIsTqWbcnzfRDdFGsM1IIXOdkpd4VDRQ87TfknCJDttBujyO/crgW/ Xd3gya76zBu2w92Y1IjPM9QDg4rC6W4BrYffQpy5tYxlpvP4tEvKHleT1Ux8XfxUvYp9 5lk0TZ2x2zOsScACFOEIJnwRC1O9f1zdI+LWCnLwaWI7BhVnUXCFI59fESAL7sk1UYus eDJiUPEbEjUb5MoskqjmJgcex8pgPaZQ+ME4pBiwFC/gAjWaZvCSjXYzQYZyQXmnFG9S i1Dg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dp16si7447029ejc.635.2020.12.19.05.03.35; Sat, 19 Dec 2020 05:03:58 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728079AbgLSM7T (ORCPT + 99 others); Sat, 19 Dec 2020 07:59:19 -0500 Received: from mail.kernel.org ([198.145.29.99]:45496 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727849AbgLSM6u (ORCPT ); Sat, 19 Dec 2020 07:58:50 -0500 From: Greg Kroah-Hartman Authentication-Results: mail.kernel.org; dkim=permerror (bad message/signature format) To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+9d39fa49d4df294aab93@syzkaller.appspotmail.com, Michal Kubecek , Jakub Kicinski Subject: [PATCH 5.9 22/49] ethtool: fix stack overflow in ethnl_parse_bitset() Date: Sat, 19 Dec 2020 13:58:26 +0100 Message-Id: <20201219125345.771146133@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201219125344.671832095@linuxfoundation.org> References: <20201219125344.671832095@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Michal Kubecek [ Upstream commit a770bf515613c6e12ae904c3593e26016de99448 ] Syzbot reported a stack overflow in bitmap_from_arr32() called from ethnl_parse_bitset() when bitset from netlink message is longer than target bitmap length. While ethnl_compact_sanity_checks() makes sure that trailing part is all zeros (i.e. the request does not try to touch bits kernel does not recognize), we also need to cap change_bits to nbits so that we don't try to write past the prepared bitmaps. Fixes: 88db6d1e4f62 ("ethtool: add ethnl_parse_bitset() helper") Reported-by: syzbot+9d39fa49d4df294aab93@syzkaller.appspotmail.com Signed-off-by: Michal Kubecek Link: https://lore.kernel.org/r/3487ee3a98e14cd526f55b6caaa959d2dcbcad9f.1607465316.git.mkubecek@suse.cz Signed-off-by: Jakub Kicinski Signed-off-by: Greg Kroah-Hartman --- net/ethtool/bitset.c | 2 ++ 1 file changed, 2 insertions(+) --- a/net/ethtool/bitset.c +++ b/net/ethtool/bitset.c @@ -630,6 +630,8 @@ int ethnl_parse_bitset(unsigned long *va return ret; change_bits = nla_get_u32(tb[ETHTOOL_A_BITSET_SIZE]); + if (change_bits > nbits) + change_bits = nbits; bitmap_from_arr32(val, nla_data(tb[ETHTOOL_A_BITSET_VALUE]), change_bits); if (change_bits < nbits)