Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp3286902ybb; Tue, 31 Mar 2020 02:08:09 -0700 (PDT) X-Google-Smtp-Source: ADFU+vuzQWemdFTTVAQdU7ZMBvFPbbm0ar0RDRF5si/3S7e1Dmv0JNku14sulAKHm72fRLU0ccZi X-Received: by 2002:aca:3b85:: with SMTP id i127mr1287555oia.123.1585645689389; Tue, 31 Mar 2020 02:08:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585645689; cv=none; d=google.com; s=arc-20160816; b=CXxxlP/uby/M+ErvcQfHprVfbsH/dwUcpDpKEuzKEV8M+36cgfRNO/5q0Mv+A/hyYw 4g04CKUXIDgpOwxrkELlzQEGsPUZ+ir2K385qIOGoWwT4knWyXLdeHKgTgJ6VZmjXbPM SJ+Tm4AVy0JBgmvgp+ho6ZAllEZorPTS0xXtKIjp9A/16BECGx20sCNwHTxFS4VlJVE1 KICw/TBfi0tZZv+SwJR6PPkiUAPzpXGHichX0azjzInJzvnKlIEgqglUDfCGNS70bLWq TTAPkpcnZ1jmhObBb+HmTLVXXpXkw62FD0SIbTFU8WqfJd0xO31sI3f+RlRjUxQbAtEb EyDw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=1qBP6SIFM0bW82UPwxT/SgWCZEfRyhB2eRRcwcALIXs=; b=HbFXFKiQQfWZVV/4gT/bdCrs9f8A5Qu6rY3aZC5N3i51UcOuDoBjZWo8JO1CCFJ1MH BpM8gYOoOw5qUmAziZV94KiahIqb1vOU7XXYJ0bXTItZPSohZfy72tkv7qwjPTYi+RLp ZBNJPIlzHeH+gMW7Jx3cGMJEBg0Brg66hP/bJhWI8LgIh9RGry7kP0PZWcS6NNQX/R2X 2U7nHL3GeCjc/fydzbn7MhJ+zbtoE+eiCzP7QZP8hmEEW5P7LS4vMPCZVrx4aQ/DtrNV UXEvxoVC5FNfggxMhS67U/6+JclCK5HkMsnMCYWbFCnjFTto88Wf5dk0pnm9gYZf5lcj aknw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=LBuHdiB0; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w32si403401otb.122.2020.03.31.02.07.57; Tue, 31 Mar 2020 02:08:09 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=LBuHdiB0; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731238AbgCaJHo (ORCPT + 99 others); Tue, 31 Mar 2020 05:07:44 -0400 Received: from mail.kernel.org ([198.145.29.99]:49550 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731253AbgCaJHl (ORCPT ); Tue, 31 Mar 2020 05:07:41 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 7AF6C20675; Tue, 31 Mar 2020 09:07:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1585645660; bh=IBrtUwAj/kudXzIhfRRZJyZCAvHi7O3Iql1xDAT/T4M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LBuHdiB0m2qNezTdFzUNNhn4+eX8q0bXJz4ojlTD7NovclX2XPG7PBB4x+54RZNOv j8Y5YLc4FpjugyYxKIUzaSXxQyYHAGbzw5sdTfYWdkWqhZXPfC13sR2jD27dU+5eEV NI+wMeELfM+8BY0pWWe2gIzyohqrGnnvfGYPvKRA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Mark Zhang , Leon Romanovsky , Jason Gunthorpe Subject: [PATCH 5.5 124/170] RDMA/mlx5: Fix the number of hwcounters of a dynamic counter Date: Tue, 31 Mar 2020 10:58:58 +0200 Message-Id: <20200331085437.118041944@linuxfoundation.org> X-Mailer: git-send-email 2.26.0 In-Reply-To: <20200331085423.990189598@linuxfoundation.org> References: <20200331085423.990189598@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Mark Zhang commit ec16b6bbdab1ce2b03f46271460efc7f450658cd upstream. When we read the global counter and there's any dynamic counter allocated, the value of a hwcounter is the sum of the default counter and all dynamic counters. So the number of hwcounters of a dynamically allocated counter must be same as of the default counter, otherwise there will be read violations. This fixes the KASAN slab-out-of-bounds bug: BUG: KASAN: slab-out-of-bounds in rdma_counter_get_hwstat_value+0x36d/0x390 [ib_core] Read of size 8 at addr ffff8884192a5778 by task rdma/10138 CPU: 7 PID: 10138 Comm: rdma Not tainted 5.5.0-for-upstream-dbg-2020-02-06_18-30-19-27 #1 Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS rel-1.12.1-0-ga5cab58e9a3f-prebuilt.qemu.org 04/01/2014 Call Trace: dump_stack+0xb7/0x10b print_address_description.constprop.4+0x1e2/0x400 ? rdma_counter_get_hwstat_value+0x36d/0x390 [ib_core] __kasan_report+0x15c/0x1e0 ? mlx5_ib_query_q_counters+0x13f/0x270 [mlx5_ib] ? rdma_counter_get_hwstat_value+0x36d/0x390 [ib_core] kasan_report+0xe/0x20 rdma_counter_get_hwstat_value+0x36d/0x390 [ib_core] ? rdma_counter_query_stats+0xd0/0xd0 [ib_core] ? memcpy+0x34/0x50 ? nla_put+0xe2/0x170 nldev_stat_get_doit+0x9c7/0x14f0 [ib_core] ... do_syscall_64+0x95/0x490 entry_SYSCALL_64_after_hwframe+0x49/0xbe RIP: 0033:0x7fcc457fe65a Code: bb 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 44 00 00 8b 05 fa f1 2b 00 45 89 c9 4c 63 d1 48 63 ff 85 c0 75 15 b8 2c 00 00 00 0f 05 <48> 3d 00 f0 ff ff 77 76 f3 c3 0f 1f 40 00 41 55 41 54 4d 89 c5 55 RSP: 002b:00007ffc0586f868 EFLAGS: 00000246 ORIG_RAX: 000000000000002c RAX: ffffffffffffffda RBX: 0000000000000000 RCX: 00007fcc457fe65a RDX: 0000000000000020 RSI: 00000000013db920 RDI: 0000000000000003 RBP: 00007ffc0586fa90 R08: 00007fcc45ac10e0 R09: 000000000000000c R10: 0000000000000000 R11: 0000000000000246 R12: 00000000004089c0 R13: 0000000000000000 R14: 00007ffc0586fab0 R15: 00000000013dc9a0 Allocated by task 9700: save_stack+0x19/0x80 __kasan_kmalloc.constprop.7+0xa0/0xd0 mlx5_ib_counter_alloc_stats+0xd1/0x1d0 [mlx5_ib] rdma_counter_alloc+0x16d/0x3f0 [ib_core] rdma_counter_bind_qpn_alloc+0x216/0x4e0 [ib_core] nldev_stat_set_doit+0x8c2/0xb10 [ib_core] rdma_nl_rcv_msg+0x3d2/0x730 [ib_core] rdma_nl_rcv+0x2a8/0x400 [ib_core] netlink_unicast+0x448/0x620 netlink_sendmsg+0x731/0xd10 sock_sendmsg+0xb1/0xf0 __sys_sendto+0x25d/0x2c0 __x64_sys_sendto+0xdd/0x1b0 do_syscall_64+0x95/0x490 entry_SYSCALL_64_after_hwframe+0x49/0xbe Fixes: 18d422ce8ccf ("IB/mlx5: Add counter_alloc_stats() and counter_update_stats() support") Link: https://lore.kernel.org/r/20200305124052.196688-1-leon@kernel.org Signed-off-by: Mark Zhang Signed-off-by: Leon Romanovsky Signed-off-by: Jason Gunthorpe Signed-off-by: Greg Kroah-Hartman --- drivers/infiniband/hw/mlx5/main.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) --- a/drivers/infiniband/hw/mlx5/main.c +++ b/drivers/infiniband/hw/mlx5/main.c @@ -5666,9 +5666,10 @@ mlx5_ib_counter_alloc_stats(struct rdma_ const struct mlx5_ib_counters *cnts = get_counters(dev, counter->port - 1); - /* Q counters are in the beginning of all counters */ return rdma_alloc_hw_stats_struct(cnts->names, - cnts->num_q_counters, + cnts->num_q_counters + + cnts->num_cong_counters + + cnts->num_ext_ppcnt_counters, RDMA_HW_STATS_DEFAULT_LIFESPAN); }