Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp5773572imm; Mon, 23 Jul 2018 05:58:24 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdrJS5+spV0tjeYR6O7xpyVYwjf4jjKQz8kfVkYTeuIx96EIOl4Qpp0GSLst5McuzISNku8 X-Received: by 2002:aa7:87d0:: with SMTP id i16-v6mr13147381pfo.82.1532350703994; Mon, 23 Jul 2018 05:58:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532350703; cv=none; d=google.com; s=arc-20160816; b=Q6g62R3M2WDCGA4AxMH8koqv77da8DiCVzdqPtpzw8HV8WSZBAt+U9kRyYGtGqANzz qEjZIw1kU983MEDafcz0vzxmtKuCfX806iO1iPIAAYxk4vwb/t1ffRxPrETw+bYDlwp0 /d4bmxdP16Ssi5UthUJX1kEvssLWuERmSW0rgdGejH+qvn/6ipBBhmg0igvp2NC7v594 /p1bQeXdmHu6NcczHt2dZCxbl/7wWd9xXVZgdd+Jtg0V7NwoAyXAeuq8i4Bqt73L2phi vRvmdWEHlq4mimw+m+DDlIhcjsxgYW+uBtVz8q5EbzhKK1UbKwFGNAMKYHT0RHiUeJEU TPcQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:arc-authentication-results; bh=LhTLpqofkJbqJK7ia2sWhZnmB7t1tB8lqQn+DoN1xYE=; b=xds7KkJAmWkZt3v7RcsKUmIZRRhL7W2Nmfya1v2LsmvwBkFvFZlwWK1x2MDstpwgt/ te46c1sdO2+mM014cmFMxbcDZRfhCO4kQDepBzwy1H+veCJF4qFkm3gmLQEbWFP0x+J+ ACFg+f9is/6FmcJsBIvj0bRs1NAmvzH8RaG1eluGcrccm8RZxdzDJu7t+6IJ7U7fQ13z eEU4GaujmuRbpCDK8NIVYqC9ir8JET1dD5phnT5KmK5FLG6wvGimXjuNIOTOCChOSOfN lk0aRLdmC6r/yjYz3rAJcCntsPvdbJ8sWclcy6qpD+1ROAsxXHBdvvMpg25QHEgcXMPp SMJg== 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 b36-v6si2475405pla.420.2018.07.23.05.58.09; Mon, 23 Jul 2018 05:58:23 -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 S2388085AbeGWN6Z (ORCPT + 99 others); Mon, 23 Jul 2018 09:58:25 -0400 Received: from nautica.notk.org ([91.121.71.147]:59933 "EHLO nautica.notk.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387847AbeGWN6Z (ORCPT ); Mon, 23 Jul 2018 09:58:25 -0400 Received: by nautica.notk.org (Postfix, from userid 1001) id 1B6C8C009; Mon, 23 Jul 2018 14:57:16 +0200 (CEST) Date: Mon, 23 Jul 2018 14:57:01 +0200 From: Dominique Martinet To: Tomas Bortoli Cc: ericvh@gmail.com, rminnich@sandia.gov, lucho@ionkov.net, jiangyiwen@huawei.com, davem@davemloft.net, v9fs-developer@lists.sourceforge.net, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, syzkaller@googlegroups.com Subject: Re: [PATCH] net/p9/trans_fd.c: fix double list_del() Message-ID: <20180723125701.GA17971@nautica> References: <20180723121902.20201-1-tomasbortoli@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20180723121902.20201-1-tomasbortoli@gmail.com> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Tomas Bortoli wrote on Mon, Jul 23, 2018: > 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. Nice, so no need to change the list_del to list_del_init! I still have a nitpick on the last moved unlock, but it's mostly aesthetic - the change looks much better to me now. (Since that will require a v2 I'll be evil and go further than Yiwen about the commit message: let it breathe a bit! :) I think a line break before "furthermore" for example will make it easier to read) > > 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); > } > > 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); It took me a while to understand why you extended this lock despite having just read the commit message, I'd suggest: - moving the spin_unlock to right after p9_client_cb (afterall that's what we want, the m->rc and m->req don't need to be protected) - add a comment before p9_client_cb saying something like 'updates req->status' or try to explain why it needs to be locked here but other transports don't need such a lock (they're not dependant on req->status like this) -- Dominique