Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp949464ybg; Wed, 10 Jun 2020 18:59:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzvW3McL8a4o6nbCg2gcGpEK4NqY/L6N03Bbg7d5NiAmQt3o2P6qpK2N7yUzCmsRBwIRe0J X-Received: by 2002:a17:906:78b:: with SMTP id l11mr6435883ejc.427.1591840765793; Wed, 10 Jun 2020 18:59:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591840765; cv=none; d=google.com; s=arc-20160816; b=eOiWlD9NPKjZBO/k0nD1z1DGX2Y9p7APsgUKy9c36jZvzmEu7nYZXlkKA+eQKGyatc VX5w+n4VjXDAhelkZI6CB0C6n1d9cOLjD1+jynSzMArQdTByPam/cLN1Po5jRqXTWvos a5D9GfY05Nyc/L7ypcKW8DHrXVC4Mi8Xn2g23h/pmZY1ABMlp1COwhA8MqUefvL7gIJ0 hPOUwDkFgtuIohxM7EUNIhCqb30bcLLe1nDQ4pVI32Wjt7lYvANfqDEBemMh843y7VDS GsJQyQqmpwD/El4OqM3ZPdN04gJzwlfElyO0r2EdZ5Uqjon8A6XVBh2fPLZqVncHLgOr Cl+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:cc :to:from; bh=DaT/MkiNsYahnHAZ76+Njfr8F/kTNR7lY2GiPah8YQA=; b=vzj4HWFlm1iAFdxlno6HZyqWunS6H2jzsr/VbCkL+P+dKM4O1Uj39zcHUT8X/1yzjG EbSM55xXUZYbAS4/xXzeFUFOBZ+JuvUlWZzYoGw9d+x1znzIu2eP53Twj5VBbMXdoFBw A/2fB5GjGTKHtt++STOpC7mGfeUwkHJfhKOc12+NFqdOZe+c2Ct3V/Z/qTRByPJBpiwC taRyLPuYSWawN+9BUJOdiX4oL/adERfxFLS86SUs+XrnO3oPdtRibwbLab77MEkj3sxX 7Ny+WaHH0/c0zPs7TELuI07YuoNBMK8AURWQdSBlHs1g6L6VCSHjjDhYuDL1vwWyTHyL 5t3g== ARC-Authentication-Results: i=1; mx.google.com; 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 v7si813196edw.193.2020.06.10.18.59.03; Wed, 10 Jun 2020 18:59:25 -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; 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 S1726624AbgFKBya (ORCPT + 99 others); Wed, 10 Jun 2020 21:54:30 -0400 Received: from szxga07-in.huawei.com ([45.249.212.35]:58088 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726290AbgFKBy3 (ORCPT ); Wed, 10 Jun 2020 21:54:29 -0400 Received: from DGGEMS401-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 4998A452455622F1EEA3; Thu, 11 Jun 2020 09:49:33 +0800 (CST) Received: from huawei.com (10.175.113.133) by DGGEMS401-HUB.china.huawei.com (10.3.19.201) with Microsoft SMTP Server id 14.3.487.0; Thu, 11 Jun 2020 09:49:26 +0800 From: Wang Hai To: , , , CC: , , , Subject: [PATCH] 9p/trans_fd: Fix concurrency del of req_list in p9_fd_cancelled/p9_read_work Date: Thu, 11 Jun 2020 09:48:55 +0800 Message-ID: <20200611014855.60550-1-wanghai38@huawei.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.175.113.133] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org p9_read_work and p9_fd_cancelled may be called concurrently. Before list_del(&m->rreq->req_list) in p9_read_work is called, the req->req_list may have been deleted in p9_fd_cancelled. We can fix it by setting req->status to REQ_STATUS_FLSHD after list_del(&req->req_list) in p9_fd_cancelled. Before list_del(&req->req_list) in p9_fd_cancelled is called, the req->req_list may have been deleted in p9_read_work. We should return when req->status = REQ_STATUS_RCVD which means we just received a response for oldreq, so we need do nothing in p9_fd_cancelled. Fixes: 60ff779c4abb ("9p: client: remove unused code and any reference to "cancelled" function") Reported-by: Hulk Robot Signed-off-by: Wang Hai --- net/9p/trans_fd.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c index f868cf6fba79..a563699629cb 100644 --- a/net/9p/trans_fd.c +++ b/net/9p/trans_fd.c @@ -718,11 +718,18 @@ static int p9_fd_cancelled(struct p9_client *client, struct p9_req_t *req) { p9_debug(P9_DEBUG_TRANS, "client %p req %p\n", client, req); - /* we haven't received a response for oldreq, - * remove it from the list. + /* If req->status == REQ_STATUS_RCVD, it means we just received a + * response for oldreq, we need do nothing here. Else, remove it from + * the list. */ spin_lock(&client->lock); + if (req->status == REQ_STATUS_RCVD) { + spin_unlock(&client->lock); + return 0; + } + list_del(&req->req_list); + req->status = REQ_STATUS_FLSHD; spin_unlock(&client->lock); p9_req_put(req); -- 2.17.1