Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp1266806rdb; Wed, 6 Dec 2023 13:30:59 -0800 (PST) X-Google-Smtp-Source: AGHT+IFBLH03A2ycVXsohTU3dk6cWl4z0NF1W9upVZR6UazgAOW6U2fztK/2IrYX1DXXHMgY0DXF X-Received: by 2002:a17:90a:6c05:b0:286:6cc1:8669 with SMTP id x5-20020a17090a6c0500b002866cc18669mr1351788pjj.78.1701898259206; Wed, 06 Dec 2023 13:30:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701898259; cv=none; d=google.com; s=arc-20160816; b=dkvX1hWCE2+B8xCh+JkboPq2sFMAwYszmPdvFkxw86lwbZp+ggT0sRTUzzQmhM+K7Y s4DyVidBAo+5fdIY4KiOsUSfTFCr8izPs5uwFKnvOfBF57/5d48h8aRv48A699CHIb5v ybk2S9k/yCDKKL6wDdcM5aRVtDVxnNhuRpz2kMVlWfnDOJVS0LPiFYbSSMesQNaHxD5s WEHx+pQLBw/4kn1JgAhzHB6hSkjc0ucjZQ6sgPz31XA2VWL6Z/z2rt4ZGvh0ytpJu1kc bVhhaAsSuAtottly+edZuHqzmtDV/gNZ495B1FAatsYQkstAue03SNvg/Gu42zLFmyNc H0dg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=g03bQpuMmo4YuqUmht2+GdVcY497EE8uIElIfJUFTJ4=; fh=71/tysKpH7/aGHTJwx9C9vvG8MYmR8BFuLsm9amhdio=; b=y0cfKc1XamnfahqQROtH7Jm0boey9aE64YzTcddSbnmKG7k1wlOr8cmz7TGCZVvWnL kWACYU80lslEcYsF8SyFCA0hX2qyk36O+NMfihHc6B+guSQuv78+eu+AiCnwJAHLFh3S cpfVP2oVPra7+9ZmVZZeJlxItCqpBm374rv2ciLDwXpDfJhWDqW7KK4g5EYDHqQ3/n0u 0ycSdFM6sb7hCmWSvZjNfewNpE3YKCMf3WxQrXH3Z7PparLZJhCNoyxpLfp8DPwWYxXA FvasxVrS7zdhmoU0Sx6qp9lUDT6AQ6UT+ksdB+c4iGzfzZMfWBVh2kNwNw3F4eg8SpiV spTg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="twVx/Shl"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id mt2-20020a17090b230200b00286d452783esi409782pjb.5.2023.12.06.13.30.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 13:30:59 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="twVx/Shl"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 7F43E8043000; Wed, 6 Dec 2023 13:30:48 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1442936AbjLFVae (ORCPT + 99 others); Wed, 6 Dec 2023 16:30:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60204 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379643AbjLFVad (ORCPT ); Wed, 6 Dec 2023 16:30:33 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2120798 for ; Wed, 6 Dec 2023 13:30:39 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2283AC433C7; Wed, 6 Dec 2023 21:30:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1701898238; bh=EOp+MGij0g64WAy1COWNmioZgirQtGqmKjfocQx8jHM=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=twVx/ShlYhgK/Jw/IDceo1jDbIcb0cSb+M8yO5GcsOjsQ2kdr0g/GOYVkbqjRwkFx b/zG9FpZTmLkINbm5aoNb5RZELRSbA8ycJqWzBKFx9erYRhpvvK4trl9IgC/yzDayu 2XTlYYmi0PG7P9+Me8EYw7uP8hogrguvsmrEw1eMhitz4f+/w8ogmlUq1mAmSDvKvT xPPeaeZmPjnwUOFK6U3i+qqh8HByM2tjk8D+G8iel4kUaPHpyK+ys3tRNimAtxKdvv IsxXcwPffiAzdruSl4RNlAH4Pooq6lCxuG4RfsxZCNmRuxucM0p7Hv5LarOpTCi7U4 1yhzZ+pvwledg== Date: Wed, 6 Dec 2023 21:30:33 +0000 From: Simon Horman To: Shifeng Li Cc: Shifeng Li , saeedm@nvidia.com, leon@kernel.org, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, ogerlitz@mellanox.com, netdev@vger.kernel.org, linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org, dinghui@sangfor.com.cn Subject: Re: [PATCH] net/mlx5e: Fix slab-out-of-bounds in mlx5_query_nic_vport_mac_list() Message-ID: <20231206213033.GB50400@kernel.org> References: <20231130094656.894412-1-lishifeng@sangfor.com.cn> <20231203175015.GP50400@kernel.org> <35e833bf-8aa6-48bd-999c-6b4c9a4fe7f0@126.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <35e833bf-8aa6-48bd-999c-6b4c9a4fe7f0@126.com> X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Wed, 06 Dec 2023 13:30:48 -0800 (PST) On Mon, Dec 04, 2023 at 10:30:14AM +0800, Shifeng Li wrote: > On 2023/12/4 1:50, Simon Horman wrote: > > On Thu, Nov 30, 2023 at 01:46:56AM -0800, Shifeng Li wrote: > > > Out_sz that the size of out buffer is calculated using query_nic_vport > > > _context_in structure when driver query the MAC list. However query_nic > > > _vport_context_in structure is smaller than query_nic_vport_context_out. > > > When allowed_list_size is greater than 96, calling ether_addr_copy() will > > > trigger an slab-out-of-bounds. > > > > > > [ 1170.055866] BUG: KASAN: slab-out-of-bounds in mlx5_query_nic_vport_mac_list+0x481/0x4d0 [mlx5_core] > > > [ 1170.055869] Read of size 4 at addr ffff88bdbc57d912 by task kworker/u128:1/461 > > > [ 1170.055870] > > > [ 1170.055932] Workqueue: mlx5_esw_wq esw_vport_change_handler [mlx5_core] > > > [ 1170.055936] Call Trace: > > > [ 1170.055949] dump_stack+0x8b/0xbb > > > [ 1170.055958] print_address_description+0x6a/0x270 > > > [ 1170.055961] kasan_report+0x179/0x2c0 > > > [ 1170.056061] mlx5_query_nic_vport_mac_list+0x481/0x4d0 [mlx5_core] > > > [ 1170.056162] esw_update_vport_addr_list+0x2c5/0xcd0 [mlx5_core] > > > [ 1170.056257] esw_vport_change_handle_locked+0xd08/0x1a20 [mlx5_core] > > > [ 1170.056377] esw_vport_change_handler+0x6b/0x90 [mlx5_core] > > > [ 1170.056381] process_one_work+0x65f/0x12d0 > > > [ 1170.056383] worker_thread+0x87/0xb50 > > > [ 1170.056390] kthread+0x2e9/0x3a0 > > > [ 1170.056394] ret_from_fork+0x1f/0x40 > > > > > > Fixes: e16aea2744ab ("net/mlx5: Introduce access functions to modify/query vport mac lists") > > > Cc: Ding Hui > > > Signed-off-by: Shifeng Li > > > > Hi, > > > > I am unsure how you calculated the 96 figure above. > > But in any case I agree that the cited patch introduced > > the mismatch that you describe. > > > out_sz = MLX5_ST_SZ_BYTES(query_nic_vport_context_in) + req_list_size * MLX5_ST_SZ_BYTES(mac_address_layout) > = 0x80/8 + 128 * 0x40/8 = 0x410 (bytes) > > nic_vport_ctx = MLX5_ADDR_OF(query_nic_vport_context_out, out, nic_vport_context) > = 0x880/8 = 0x110 (bytes) > mac_addr = MLX5_ADDR_OF(nic_vport_context, nic_vport_ctx, current_uc_mac_address[96]) + 2 > = 0x110 + 96 * 8 + 2 > = 0x412 (bytes) > > When i is 96, the mac_addr offset is 0x412 but the out_sz is 0x410. > And that will trigger an slab-out-of-bounds. Thanks for the clarification, this looks good to me. > > Reviewed-by: Simon Horman