Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp314443ybg; Fri, 12 Jun 2020 02:11:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw3hSrtNY0gCV4bw6itBR8mQt7+CimxgfS70hoBpG8dXaAY9O1beKntDPdfFWAQ7yxq1hB7 X-Received: by 2002:a17:907:9d3:: with SMTP id bx19mr11815108ejc.461.1591953109622; Fri, 12 Jun 2020 02:11:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591953109; cv=none; d=google.com; s=arc-20160816; b=yROvuBJiKKu12s0Hv17kYUR0UnpHoEwu2dH8rldwUECMie0FMFWP+bMqgHBv1sQpfk W/v2cp5Rm/5JAV+LPBqkbtMz6DMlwHCK6EMAcDHglqzG0ZxBN+gqVeNK5bZyQDA1C4tz YmpZCEeOR1FJ1Q7uJJi0t5ZchX7XrI9D9gByNUPGT3aD/QtssygBiSl2m3Fk7pbehxF7 KYDGL94DHG1xyIvjXzxgF3pxNtGOkTY5/2w6bzPovWdfOCuBTieTIEH6cUqbgrbg5uFV WUKQXIpWHn5haWO6NZ6SX4bhCmdX0dlbJYq+NixL1EqkW08xUB83sncy4MtCi/QhDxvr w2Ew== 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=eUkfItwCmGetE7DQEGVB9xvMzCQnkyR8b4Cf+O12Fcg=; b=cdBA/wGdEnpvre2nNNR91Nc03Rsm8IBQ/kcce/IGUJx7ajaoy5yuy1pvcLAa0EvDyH hO9FBujFe/J9Prsqu98sbtYBpVZ5jjDcPFyDDwLSctpUtQn00VgNsKYmEuxDoIiS0nuK /+TD+w89jCRwvbXQnrdok1/rzfdZyvicpvR2+g6N7SMVn9mXbiCZnnMp1iycyv09zyzR r5A/8hfuJpWMd6WkqpmJFyrHM0JsEN924qjhaVwMdiM6aJPX6mWf3AukpzsD/8WJk5ED vh3f4fChf8yy8AkxwaSoYtbFfSomlkboFPiudxWuQtaifadx5mGy2+9glF72twW6LlU1 pFiQ== 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 o1si3225224edr.267.2020.06.12.02.11.27; Fri, 12 Jun 2020 02:11:49 -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 S1726456AbgFLJJV (ORCPT + 99 others); Fri, 12 Jun 2020 05:09:21 -0400 Received: from szxga07-in.huawei.com ([45.249.212.35]:33556 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726302AbgFLJJT (ORCPT ); Fri, 12 Jun 2020 05:09:19 -0400 Received: from DGGEMS409-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 77CE3E1C964E39C45171; Fri, 12 Jun 2020 17:09:16 +0800 (CST) Received: from huawei.com (10.175.113.133) by DGGEMS409-HUB.china.huawei.com (10.3.19.209) with Microsoft SMTP Server id 14.3.487.0; Fri, 12 Jun 2020 17:09:05 +0800 From: Wang Hai To: , , , CC: , , , Subject: [PATCH v2] 9p/trans_fd: Fix concurrency del of req_list in p9_fd_cancelled/p9_read_work Date: Fri, 12 Jun 2020 17:08:33 +0800 Message-ID: <20200612090833.36149-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. 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. Fixes: 60ff779c4abb ("9p: client: remove unused code and any reference to "cancelled" function") Reported-by: syzbot+77a25acfa0382e06ab23@syzkaller.appspotmail.com Signed-off-by: Wang Hai --- v1->v2: 1. Add ignoring replies associated with a cancelled request. 2. Improved some descriptions suggested by Dominique. net/9p/trans_fd.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c index 13cd683a658a..3f67803123be 100644 --- a/net/9p/trans_fd.c +++ b/net/9p/trans_fd.c @@ -362,6 +362,10 @@ static void p9_read_work(struct work_struct *work) 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, @@ -703,11 +707,20 @@ 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); + 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); -- 2.17.1