Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp6321255imm; Mon, 23 Jul 2018 15:55:25 -0700 (PDT) X-Google-Smtp-Source: AAOMgpeoNdJPocXQ6Ke6Rf+9ITAMzPLF4OU5ze04gBtKKLUO7cjW9dqRxwu0WOz/NsqA4STXJCBL X-Received: by 2002:a62:4308:: with SMTP id q8-v6mr15305871pfa.86.1532386525317; Mon, 23 Jul 2018 15:55:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532386525; cv=none; d=google.com; s=arc-20160816; b=Xcyo7tkqoZQP82RcR+QAc9aoYL7P6Vvzu85tZUQWqDnanHcyDH/tAjcKCOzZ3/LwAs d5gS7UDtEYmWY+umNUWBmSi3z0gi0dMT2ZjxOiMFlA4Wjx4kn5uitbceHd7NGxlgWDm8 GcY5YietDhjRjMHIHisc1Y7mpjTvkXBS2tTZQ8C/U2f6jImOdX2bO2pCBF7jQUEc0R5P KWvnnDqhjxnFRFUkkdfwCS/vqsME/f91cJUk4P6NEJHgin6+ZieAT0Rqr+7qiRA2yjpB P3Vsm5mcuaeBzDxd27GIf7Fow3UCw1v9szXJQrLK7CQvbxnoYHHn5UJTsHvweUBQuu3/ VICA== 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=Nl0pi5Wv9HFpCjmHf9bclPfcfR2BJy0BXXsdhlSTl9s=; b=Y/dtCy7pQ4P79uwx38qFjbYO4j6vNAGq17Rpd/56+JUvZrS+zadtLaPoUsaT6X9xws WH7gbGOJmRNiP7OnrrY4vctOjTIpf4u1ZHnVPG4dcE7KUnTTGldA820GhJLuyiB2V7MY keo18m9gkOtM2QDGf+HT4zUMN4ckFpEOobccn+oQoTOsJWbyF/oitODBpHgC/fSmVCrY kDleasmi+/DZKEs0skjQrXS6cwqSfUvRchow0hA/F0kUd8MKsmBbglHL9pL59SdF5Kve Vpic8RxdraY94iNvIJ0Uh/uQBYtXjPcy/IOn+gNItK1l6Q5BDcpnq9RaBz0w/IJt2k7P ujZw== 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 p14-v6si9930576pgd.306.2018.07.23.15.55.10; Mon, 23 Jul 2018 15:55:25 -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 S2388226AbeGWX5s (ORCPT + 99 others); Mon, 23 Jul 2018 19:57:48 -0400 Received: from nautica.notk.org ([91.121.71.147]:38420 "EHLO nautica.notk.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388109AbeGWX5s (ORCPT ); Mon, 23 Jul 2018 19:57:48 -0400 Received: by nautica.notk.org (Postfix, from userid 1001) id 61FF7C009; Tue, 24 Jul 2018 00:54:19 +0200 (CEST) Date: Tue, 24 Jul 2018 00:54:04 +0200 From: Dominique Martinet To: Tomas Bortoli Cc: ericvh@gmail.com, rminnich@sandia.gov, lucho@ionkov.net, davem@davemloft.net, v9fs-developer@lists.sourceforge.net, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, syzkaller@googlegroups.com Subject: Re: [PATCH] net/9p/trans_fd.c: fix race by holding the lock Message-ID: <20180723225404.GA17214@nautica> References: <20180723184253.6682-1-tomasbortoli@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20180723184253.6682-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: > It may be possible to run p9_fd_cancel() with a deleted req->req_list > and incur in a double del. To fix hold the client->lock while changing > the status, so the other threads will be synchronized. > > Signed-off-by: Tomas Bortoli > Reported-by: syzbot+735d926e9d1317c3310c@syzkaller.appspotmail.com OK, taking this one. > --- > net/9p/trans_fd.c | 10 +++++----- > 1 file changed, 5 insertions(+), 5 deletions(-) > > diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c > index 588bf88c3305..f9f96d50d96d 100644 > --- a/net/9p/trans_fd.c > +++ b/net/9p/trans_fd.c > @@ -197,15 +197,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; > } > > @@ -217,7 +216,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); > @@ -226,6 +224,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 > @@ -373,8 +372,9 @@ 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); > + /* update req->status while holding client->lock */ > p9_client_cb(m->client, m->req, status); > + spin_unlock(&m->client->lock); > m->rc.sdata = NULL; > m->rc.offset = 0; > m->rc.capacity = 0;