Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp842468pxb; Wed, 6 Apr 2022 01:34:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxevLnG2ZIe6ghit3wN+hOXHfk2uNEyGvdB9b/6CXEnsPYNDU3lzx1W5DMvq17NgqzHQNbk X-Received: by 2002:a17:902:ef45:b0:156:1858:71fc with SMTP id e5-20020a170902ef4500b00156185871fcmr7587664plx.23.1649234053893; Wed, 06 Apr 2022 01:34:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649234053; cv=none; d=google.com; s=arc-20160816; b=mRSYWqckJ7InffJ22Q2RXRdXB0NSoa4otLNlTVzAYRqdzww3CzLjBCSy7ORjnYGsWL jxs48pyS8xqza9s9LzDzwF1a+/VWOYX5Jd/oi82hWkBRlMrUydXdjjX/AnNcytTYft+b n4yD8OX1DwpA2E5m3YPJAbwIDexJz02zqnJJV8wDLzznEy5vo68d59KelyszW0gtC0XZ 7nrd8ldSmyF8dE3RNygij1FhtOYt5Q9+RfFVcLxba06jE/lPIA6LXMO8o5uxHgtSRQDW NA9MMznjI+abMQz3GqwLac4NlfLd798N7FDpWo1pYurPgn12hTHmd/43qKs1J5sfeywC innw== 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=3WZDHAwHZ2yBVlOKywvBzx1FxPDSNszi8vk/jEeDxFc=; b=b2ycIp71XETM5N/1P0ymUWJgninpERLub+4YvpNvxzGHu+wrrLOevcIst3L0meR5y3 +bWXkoj/L4TjhrMOZ8FShrZI+LeuxMLXy4C28dSSN0ML8bexKzylaPKsh//YWmnyfgw+ pZWB52AsGC+W8ljiE6YPWkvQVYHm76C3rPmsjp72O0zeMf++fOfKxUrpJfhzJMiBe+mY VvwDfPy9efA3eoO58Wn4rxIwiPylCFOqoZL9j+qyaEZMgO44WDerP6WJKbg6vJdiuwZx NdOsJxPIJfkTB6BSIV0wb2mtoOK3UNrZyDwwchdDHFIYWpUAoYiZEnQUcwmtOxOlkuHF xewQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=eVjBl1M+; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id t187-20020a632dc4000000b003816043f111si18395561pgt.774.2022.04.06.01.34.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Apr 2022 01:34:13 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=eVjBl1M+; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 68A4F41C88E; Wed, 6 Apr 2022 01:19:44 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1839271AbiDFA6u (ORCPT + 99 others); Tue, 5 Apr 2022 20:58:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47412 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349329AbiDEJtj (ORCPT ); Tue, 5 Apr 2022 05:49:39 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B526D2DF1; Tue, 5 Apr 2022 02:44:02 -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 5F8C9B817D3; Tue, 5 Apr 2022 09:44:01 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C4558C385A1; Tue, 5 Apr 2022 09:43:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649151840; bh=yrQk/XIIlYNaH6bGJzY3EtFzh7n9iwUU8rSENQg7smo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eVjBl1M+hhooItK5YhOnsYKE6vwzMRHy0xqhJE/DPf4WMWYpx/xwYdeBcvAQpwQZL Zg4UTk1kyydtp1nSLh31cUm7Ic3Fvg36JmJGZGKzuqauGjopfyo+4qnThs2vkMjyDa NB4TnoAa++KAraMDS5tQCfKbo1cGtS5mp9wB+1ic= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Petr Machata , Ido Schimmel , Jakub Kicinski , Sasha Levin Subject: [PATCH 5.15 560/913] af_netlink: Fix shift out of bounds in group mask calculation Date: Tue, 5 Apr 2022 09:27:02 +0200 Message-Id: <20220405070356.631304130@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070339.801210740@linuxfoundation.org> References: <20220405070339.801210740@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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: Petr Machata [ Upstream commit 0caf6d9922192dd1afa8dc2131abfb4df1443b9f ] When a netlink message is received, netlink_recvmsg() fills in the address of the sender. One of the fields is the 32-bit bitfield nl_groups, which carries the multicast group on which the message was received. The least significant bit corresponds to group 1, and therefore the highest group that the field can represent is 32. Above that, the UB sanitizer flags the out-of-bounds shift attempts. Which bits end up being set in such case is implementation defined, but it's either going to be a wrong non-zero value, or zero, which is at least not misleading. Make the latter choice deterministic by always setting to 0 for higher-numbered multicast groups. To get information about membership in groups >= 32, userspace is expected to use nl_pktinfo control messages[0], which are enabled by NETLINK_PKTINFO socket option. [0] https://lwn.net/Articles/147608/ The way to trigger this issue is e.g. through monitoring the BRVLAN group: # bridge monitor vlan & # ip link add name br type bridge Which produces the following citation: UBSAN: shift-out-of-bounds in net/netlink/af_netlink.c:162:19 shift exponent 32 is too large for 32-bit type 'int' Fixes: f7fa9b10edbb ("[NETLINK]: Support dynamic number of multicast groups per netlink family") Signed-off-by: Petr Machata Reviewed-by: Ido Schimmel Link: https://lore.kernel.org/r/2bef6aabf201d1fc16cca139a744700cff9dcb04.1647527635.git.petrm@nvidia.com Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin --- net/netlink/af_netlink.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c index 81ba8e51e01f..83ca93b32f5f 100644 --- a/net/netlink/af_netlink.c +++ b/net/netlink/af_netlink.c @@ -157,6 +157,8 @@ EXPORT_SYMBOL(do_trace_netlink_extack); static inline u32 netlink_group_mask(u32 group) { + if (group > 32) + return 0; return group ? 1 << (group - 1) : 0; } -- 2.34.1