Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp6725091imm; Tue, 24 Jul 2018 01:48:44 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcY0P2OckvaUpsKdfzBoxfsp6cu8RRAypUw69Fq6UAfdtcL6+z0Wfwav6X9b0ulWDt9RG6r X-Received: by 2002:a63:2644:: with SMTP id m65-v6mr15277287pgm.371.1532422124255; Tue, 24 Jul 2018 01:48:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532422124; cv=none; d=google.com; s=arc-20160816; b=Jofe+/A1VPvDZdd1/QXSQhpTRgkABit+/XIjA7y5iAySxIt9G4qIAh5JL1pRBFs848 jK20/QVy2yn9t0rVIJwkSsqtOpfVRqPRHm2V0Bq3gi/hY/n6/y4d1Mqyz7dLxX0Qq52r BjgssaIXv0+qj8B/8Q2eLOWqZeev5mpgDUT6K12O3bOlVArZGIH2LqsSJjlDmoEVOg9g Po2bMrIgxDUqNjhtJaT3JGHpqMpcIx35ju+B4cQYNZ6WdqggNHznaoyxrxyT/yJxAxNU rYy9nkXMWDk+E/XlIHDAJ2I3m6ufoNl7toyZ1ca2SuVJoJoXPW1XOjaVBuuwlP3yyIb5 edGw== 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:in-reply-to :mime-version:user-agent:date:message-id:from:cc:references:to :subject:arc-authentication-results; bh=kcEkBbVeqYnRUkZQbT+NhCCZdr/9ge4LZ1Dw4yLs5nk=; b=m/WiCQmRbB/q4jYK3IFI4C/5zPMyi0SbGVcALiVN9KkX5CxeY8E1DChsZSTMfKrvGh RB2o3AWsciUP5nGLVMIqXoqP/l4H5HfRfAWm3UKiZ02978s3qYJDjXEqeAt/QYitPZsL ng00dfAeDAuVq2O4V62U01B+B91Qm8EUGWne4UvVqwqOAHQnRoz7NjfIpljFT1+TX4bM UBaO2TyR17S/rIz7T4GxTHOft4ezE0TGbj1GciVXcdpgGkeloPNYBvpoDB9yy0yiNke/ sI9eleIEchKDBEJMs6OORHdXxgZPnUCwQTqM0Gl1RjTqs6zu6Z/QKbwaL33DtiQvQIyR jA0w== ARC-Authentication-Results: i=1; mx.google.com; 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 d9-v6si10661550pgg.423.2018.07.24.01.48.28; Tue, 24 Jul 2018 01:48:44 -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; 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 S2388222AbeGXJw6 (ORCPT + 99 others); Tue, 24 Jul 2018 05:52:58 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:10109 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2388136AbeGXJw6 (ORCPT ); Tue, 24 Jul 2018 05:52:58 -0400 Received: from DGGEMS409-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 3E7C69210E0BB; Tue, 24 Jul 2018 16:47:30 +0800 (CST) Received: from [127.0.0.1] (10.177.16.168) by DGGEMS409-HUB.china.huawei.com (10.3.19.209) with Microsoft SMTP Server id 14.3.382.0; Tue, 24 Jul 2018 16:46:29 +0800 Subject: Re: [PATCH] net/p9/trans_fd.c: fix double list_del() To: Tomas Bortoli References: <20180723121902.20201-1-tomasbortoli@gmail.com> CC: , , , , From: jiangyiwen Message-ID: <5B56E764.2090608@huawei.com> Date: Tue, 24 Jul 2018 16:46:28 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.5.1 MIME-Version: 1.0 In-Reply-To: <20180723121902.20201-1-tomasbortoli@gmail.com> Content-Type: text/plain; charset="windows-1252" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.177.16.168] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2018/7/23 20:19, Tomas Bortoli wrote: > A double list_del(&req->req_list) is possible in p9_fd_cancel() as > shown by Syzbot. To prevent it we have to ensure that we have the > client->lock when deleting the list. Furthermore, we have to update > the status of the request before releasing the lock, to prevent the > race. > > Signed-off-by: Tomas Bortoli > Reported-by: syzbot+735d926e9d1317c3310c@syzkaller.appspotmail.com > --- > net/9p/trans_fd.c | 9 ++++----- > 1 file changed, 4 insertions(+), 5 deletions(-) > > diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c > index a64b01c56e30..370c6c69a05c 100644 > --- a/net/9p/trans_fd.c > +++ b/net/9p/trans_fd.c > @@ -199,15 +199,14 @@ static void p9_mux_poll_stop(struct p9_conn *m) > static void p9_conn_cancel(struct p9_conn *m, int err) > { > struct p9_req_t *req, *rtmp; > - unsigned long flags; > LIST_HEAD(cancel_list); > > p9_debug(P9_DEBUG_ERROR, "mux %p err %d\n", m, err); > > - spin_lock_irqsave(&m->client->lock, flags); > + spin_lock(&m->client->lock); > > if (m->err) { > - spin_unlock_irqrestore(&m->client->lock, flags); > + spin_unlock(&m->client->lock); > return; > } > > @@ -219,7 +218,6 @@ static void p9_conn_cancel(struct p9_conn *m, int err) > list_for_each_entry_safe(req, rtmp, &m->unsent_req_list, req_list) { > list_move(&req->req_list, &cancel_list); > } > - spin_unlock_irqrestore(&m->client->lock, flags); > > list_for_each_entry_safe(req, rtmp, &cancel_list, req_list) { > p9_debug(P9_DEBUG_ERROR, "call back req %p\n", req); > @@ -228,6 +226,7 @@ static void p9_conn_cancel(struct p9_conn *m, int err) > req->t_err = err; > p9_client_cb(m->client, req, REQ_STATUS_ERROR); > } > + spin_unlock(&m->client->lock); If you want to expand the ranges of client->lock, the cancel_list will not be necessary, you can optimize this code. In addition, we delete some person because too many recipients are limited. Thanks, Yiwen. > } > > static __poll_t > @@ -370,12 +369,12 @@ static void p9_read_work(struct work_struct *work) > if (m->req->status != REQ_STATUS_ERROR) > status = REQ_STATUS_RCVD; > list_del(&m->req->req_list); > - spin_unlock(&m->client->lock); > p9_client_cb(m->client, m->req, status); > m->rc.sdata = NULL; > m->rc.offset = 0; > m->rc.capacity = 0; > m->req = NULL; > + spin_unlock(&m->client->lock); > } > > end_clear: >