Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp674001ybh; Tue, 10 Mar 2020 06:15:54 -0700 (PDT) X-Google-Smtp-Source: ADFU+vvjikEVqZhPkjiveI+oK/1EYkdaiYNwbz1avEOfOPVzF5TSolbdPqz9Tj4bd+/d33QFyJic X-Received: by 2002:aca:2801:: with SMTP id 1mr1105105oix.168.1583846154041; Tue, 10 Mar 2020 06:15:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1583846154; cv=none; d=google.com; s=arc-20160816; b=S/OSeWgfVA6a32v8UObdmGBKj4UW9JbHUUy4BlfaCKIBgp3Tqlx2WWvlKd4HNLXrIH 0pjVTJ+liV/8cb0HlhX0NLL5RIMYhilyahCYBBqQjZZ7jMX7upgXsolv2HcYC7jdEIFm JzB/dQOaYyVpsUIYkMkyG+H+eCChFj9eN1uIOIPttCS+DmrOynUqCAxsGDiEVlsyJ0Jw XU5gtOlN7A8TjIsoquHHoJXd5m+S60q9St9qRIP+QUoKvg+HTnhvo7zITOsvyjy+x7e+ g5m8401Q0+UjmHO6Z+DMgBQhzReWkefamWkd6F849AiGV1pPF7KCNQ+vbPaFoseAjRYN h4/A== 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=EsNcSFOu5Ann305HCCvS12QumPPknCILq0nDKOEZHoU=; b=tNsb+JMl15+9aFAhuwXudpnsCuctOSZmUj7O/ke6QopzG5qINtYAA477cNFy0Y0Ggv tXkYEYOe1vCw6ZsM1NLpKVL0jaIGVHuiv4TboTgEnrS8bZZPX/ITPwU+hPwhqQf6uSFD G8KKFoW4uK89++rfdLXxxH3J8UPaxOGcgVJyadILY1+laJmxi1C/gpj/Z1eO0+jmsGXm HwIMEuWTES6MKvqammsyFPGgSw3E/ZRCQoVwkW5iKcmmsYAzrO36/Bj26ytI4cOF3fRC LCPjkToXpzFKh0ea90Nyhnu2F8sSUnBwmjJwr1SqijaZ2GwMOhayJ8gGSM4YIItu6lRp +l1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="vpxf/lb7"; 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 f6si8225232otq.50.2020.03.10.06.15.41; Tue, 10 Mar 2020 06:15:54 -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="vpxf/lb7"; 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 S1732024AbgCJNPV (ORCPT + 99 others); Tue, 10 Mar 2020 09:15:21 -0400 Received: from mail.kernel.org ([198.145.29.99]:39890 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732019AbgCJNPR (ORCPT ); Tue, 10 Mar 2020 09:15:17 -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 A2194208E4; Tue, 10 Mar 2020 13:15:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1583846117; bh=11lTqkhPdykb/T5b6KrUOa+oT9IU1Yv8PZKOza1sqoc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vpxf/lb7Q5PG1SylzQBuWfkQbvgRoEWeSmw8ejne2TQjNH+uCWWYUj2ks23FzvXKZ fhI6pz/9vbO0zAhTsso7hfAdhQlAoNM4+GNrtjuZ30NY4nVCemlwX7h+gqpD5DCI1y Ieus3o7ULJAXIA0SLS0Civx+Vymcd96Il0kwzCMo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Mike Marciniszyn , Dennis Dalessandro , Jason Gunthorpe Subject: [PATCH 4.19 75/86] IB/hfi1, qib: Ensure RCU is locked when accessing list Date: Tue, 10 Mar 2020 13:45:39 +0100 Message-Id: <20200310124534.815634089@linuxfoundation.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200310124530.808338541@linuxfoundation.org> References: <20200310124530.808338541@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: Dennis Dalessandro commit 817a68a6584aa08e323c64283fec5ded7be84759 upstream. The packet handling function, specifically the iteration of the qp list for mad packet processing misses locking RCU before running through the list. Not only is this incorrect, but the list_for_each_entry_rcu() call can not be called with a conditional check for lock dependency. Remedy this by invoking the rcu lock and unlock around the critical section. This brings MAD packet processing in line with what is done for non-MAD packets. Fixes: 7724105686e7 ("IB/hfi1: add driver files") Link: https://lore.kernel.org/r/20200225195445.140896.41873.stgit@awfm-01.aw.intel.com Reviewed-by: Mike Marciniszyn Signed-off-by: Dennis Dalessandro Signed-off-by: Jason Gunthorpe Signed-off-by: Greg Kroah-Hartman --- drivers/infiniband/hw/hfi1/verbs.c | 4 +++- drivers/infiniband/hw/qib/qib_verbs.c | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) --- a/drivers/infiniband/hw/hfi1/verbs.c +++ b/drivers/infiniband/hw/hfi1/verbs.c @@ -595,10 +595,11 @@ static inline void hfi1_handle_packet(st opa_get_lid(packet->dlid, 9B)); if (!mcast) goto drop; + rcu_read_lock(); list_for_each_entry_rcu(p, &mcast->qp_list, list) { packet->qp = p->qp; if (hfi1_do_pkey_check(packet)) - goto drop; + goto unlock_drop; spin_lock_irqsave(&packet->qp->r_lock, flags); packet_handler = qp_ok(packet); if (likely(packet_handler)) @@ -607,6 +608,7 @@ static inline void hfi1_handle_packet(st ibp->rvp.n_pkt_drops++; spin_unlock_irqrestore(&packet->qp->r_lock, flags); } + rcu_read_unlock(); /* * Notify rvt_multicast_detach() if it is waiting for us * to finish. --- a/drivers/infiniband/hw/qib/qib_verbs.c +++ b/drivers/infiniband/hw/qib/qib_verbs.c @@ -360,8 +360,10 @@ void qib_ib_rcv(struct qib_ctxtdata *rcd if (mcast == NULL) goto drop; this_cpu_inc(ibp->pmastats->n_multicast_rcv); + rcu_read_lock(); list_for_each_entry_rcu(p, &mcast->qp_list, list) qib_qp_rcv(rcd, hdr, 1, data, tlen, p->qp); + rcu_read_unlock(); /* * Notify rvt_multicast_detach() if it is waiting for us * to finish.