Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2020491pxa; Mon, 3 Aug 2020 05:34:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzEt/9W2Hvl8IUuKxJi74KQCT85M/TjhmqD0B1ojywTmS0iZN0jT++4mcjfFnPtkG5UQ0Gi X-Received: by 2002:aa7:c408:: with SMTP id j8mr15616881edq.83.1596458064919; Mon, 03 Aug 2020 05:34:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596458064; cv=none; d=google.com; s=arc-20160816; b=sXezYLGWLMgPlNpgctKT8hDZp/ZbppM1WyZfI8XdhEcD2MWRXCIsg/os5gq92nfJf8 B2m2tyrOC/AC2rxte3i8V6HainFLlr1WodSMlbyd6I3/O9s1I2OcNDXkendq2/DeLORl 8GTp9nnxTmN2A815mrytYXxFg9zmwoYRJOQZBFrjce6hNldfOIlzEkuO83u3Guagz2Y7 qOqtW6LtPmkz/Jt0XsmoN4xV5y+R8KX0b0R2ItZGF+eTvipl7ECShdo+6cOiiKsJrIOl pVsi1gbbe+92wmZf/l8RKROvEOv50EoSn7MH2Tkx7ax+9USilF8niQnchzxiyUkOvQkH OFEA== 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=Dm5Wqt9wKZgrS9y5AmInLMK5vrVV82GAoXrJoCByatg=; b=O5niYrbK8MvOzXvUYmDeDy5GrsZZVcR1ktAL01A5UgOvoEtaHxM1dOk4qzH4ld9559 gsnwkAOlA4aaFg5cePAzWjo4c9rCY4O9NuNnOZ0umMsu7RqVu4MEoFtafSGRvjHYspNo 1Ki1MINCUOluxmkC+ujMIjVbCKFWJSla46WL0NidgGf0HXGlf/IbPBOqm3QKYiFrZ0oj ULoigVZXosNJc0JORuH8HeoPuuzdYD/TPU0tVsNvf6zb3brFPqb1tuvEOVHnPY4wSHsm gIJDluDQD7KdZoFgacCoQ2irCXGbaBGOFEXGgds3ivcQDIQrdsIX6rUojf5GITbF5Kf+ 7+EQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ExEO0IFl; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d8si10547795edl.399.2020.08.03.05.34.02; Mon, 03 Aug 2020 05:34:24 -0700 (PDT) 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; dkim=pass header.i=@kernel.org header.s=default header.b=ExEO0IFl; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729163AbgHCMbR (ORCPT + 99 others); Mon, 3 Aug 2020 08:31:17 -0400 Received: from mail.kernel.org ([198.145.29.99]:58574 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729157AbgHCMbN (ORCPT ); Mon, 3 Aug 2020 08:31:13 -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 3BB5920781; Mon, 3 Aug 2020 12:31:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1596457871; bh=mmLLq4bPGESN35BigUKSGoPRpQeB72bEz7jTDimc6Fw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ExEO0IFltRA9TyUHU9muoNsQlIpjxsPTLZInY6OZhJbaKH0AvTP9om1xiRVnTkaoe olYBj33QWiSvMGbFCAHYv6P1vRlSrb3rMqMvzWQAgWZ25ZhPf+2GYAneF9Xq3Z8CKp m76dEklx5GpLubzGk5+NERjU7l+V6D34uur+Xz+U= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+77a25acfa0382e06ab23@syzkaller.appspotmail.com, Wang Hai , Dominique Martinet Subject: [PATCH 4.19 13/56] 9p/trans_fd: Fix concurrency del of req_list in p9_fd_cancelled/p9_read_work Date: Mon, 3 Aug 2020 14:19:28 +0200 Message-Id: <20200803121850.962253359@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200803121850.306734207@linuxfoundation.org> References: <20200803121850.306734207@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: Wang Hai commit 74d6a5d5662975aed7f25952f62efbb6f6dadd29 upstream. p9_read_work and p9_fd_cancelled may be called concurrently. In some cases, req->req_list may be deleted by both p9_read_work and p9_fd_cancelled. We can fix it by ignoring replies associated with a cancelled request and ignoring cancelled request if message has been received before lock. Link: http://lkml.kernel.org/r/20200612090833.36149-1-wanghai38@huawei.com Fixes: 60ff779c4abb ("9p: client: remove unused code and any reference to "cancelled" function") Cc: # v3.12+ Reported-by: syzbot+77a25acfa0382e06ab23@syzkaller.appspotmail.com Signed-off-by: Wang Hai Signed-off-by: Dominique Martinet Signed-off-by: Greg Kroah-Hartman --- net/9p/trans_fd.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) --- a/net/9p/trans_fd.c +++ b/net/9p/trans_fd.c @@ -377,6 +377,10 @@ static void p9_read_work(struct work_str if (m->rreq->status == REQ_STATUS_SENT) { list_del(&m->rreq->req_list); p9_client_cb(m->client, m->rreq, REQ_STATUS_RCVD); + } else if (m->rreq->status == REQ_STATUS_FLSHD) { + /* Ignore replies associated with a cancelled request. */ + p9_debug(P9_DEBUG_TRANS, + "Ignore replies associated with a cancelled request\n"); } else { spin_unlock(&m->client->lock); p9_debug(P9_DEBUG_ERROR, @@ -718,11 +722,20 @@ static int p9_fd_cancelled(struct p9_cli { p9_debug(P9_DEBUG_TRANS, "client %p req %p\n", client, req); + spin_lock(&client->lock); + /* Ignore cancelled request if message has been received + * before lock. + */ + if (req->status == REQ_STATUS_RCVD) { + spin_unlock(&client->lock); + return 0; + } + /* we haven't received a response for oldreq, * remove it from the list. */ - spin_lock(&client->lock); list_del(&req->req_list); + req->status = REQ_STATUS_FLSHD; spin_unlock(&client->lock); p9_req_put(req);