Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp731014imm; Thu, 13 Sep 2018 06:58:38 -0700 (PDT) X-Google-Smtp-Source: ANB0VdbBDgcpYkuQbKe0P8MJKWXMj/Hdf7KO71yfe30GmK8jaPPq2qjSlDnhl3vv6ZSrVAf7s3Wc X-Received: by 2002:a63:b812:: with SMTP id p18-v6mr7246385pge.156.1536847118879; Thu, 13 Sep 2018 06:58:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536847118; cv=none; d=google.com; s=arc-20160816; b=KCnoNHI4e39kcs1B4vvqOoouAE3Lzkv47tIcdAyKz8uXrCo7mASuHv/R3sEhdQWS9t FVrTtnG5ecKtMZq5VyaJJM3V+pmpJkF6pd8lVLcxmdKJbkqBbr5iBTr1JD7QT2UX6Bi7 SKRAVDUmXDi38HOAaBL7aSjGvNm7sNLr5LP+Gs+FwLqzrNxqb5n5Xk6KdmSsHpDA1UOJ i7ZAnps75+xLsztOPx40yfG3ANcLI23Ipo4JvgEyBrZCR6RGru98wdiUdZVCxBPvvyfe h4lPxSdJoScswJJ/DaD1d8cJjrHM8Mpzjh5COhkA8diG5i6C05nrwbESWnh9Tva0E0KM CAag== 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:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from; bh=joQF4re/Y/hkW7C7jzc3hsQD04MMJLwM/E8sqMb5xmQ=; b=xgMwts4QKWMIuKRoXoqboeSW88r+kuOsDAuwvbWsfywEEEB6Ip7/fjDFuPTtJTxrq6 Ob4oBMTIDdeL4g1lHTnnBqgmNGgD5AbifYVfef4TPUB6yf2+B57B3vHFQhZiaJa8bF27 jn8sQRWQxgC0STNgdXjCKyZa0DIVn3gyGgrIAGK83rOc1l4oh/3CgYOLtpmxcecUzESK JwZQKY3Nlb6A85/R+LvsHf1X9nlF8Uq6/EHVnZfTVp1V1C5fjS5p8zyqmNbrQrePZdUc btVc+/wWraHfuPQCGxekjQTFieGQMWTNZedQZ0AAGKY1uH3CZHewZGRsV/vM6OLwXhhE sKRg== 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 y1-v6si3992746pgo.644.2018.09.13.06.58.24; Thu, 13 Sep 2018 06:58:38 -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 S1731164AbeIMTGi (ORCPT + 99 others); Thu, 13 Sep 2018 15:06:38 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:34238 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730847AbeIMTGi (ORCPT ); Thu, 13 Sep 2018 15:06:38 -0400 Received: from localhost (ip-213-127-77-73.ip.prioritytelecom.net [213.127.77.73]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 2D791CE7; Thu, 13 Sep 2018 13:57:01 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org, Eric Van Hensbergen , Ron Minnich , Latchesar Ionkov Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Tomas Bortoli , syzbot+735d926e9d1317c3310c@syzkaller.appspotmail.com, Yiwen Jiang , "David S. Miller" , Dominique Martinet , Sasha Levin Subject: [PATCH 4.18 093/197] net/9p/trans_fd.c: fix race by holding the lock Date: Thu, 13 Sep 2018 15:30:42 +0200 Message-Id: <20180913131845.253517118@linuxfoundation.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180913131841.568116777@linuxfoundation.org> References: <20180913131841.568116777@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Tomas Bortoli [ Upstream commit 9f476d7c540cb57556d3cc7e78704e6cd5100f5f ] 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. Link: http://lkml.kernel.org/r/20180723184253.6682-1-tomasbortoli@gmail.com Signed-off-by: Tomas Bortoli Reported-by: syzbot+735d926e9d1317c3310c@syzkaller.appspotmail.com To: Eric Van Hensbergen To: Ron Minnich To: Latchesar Ionkov Cc: Yiwen Jiang Cc: David S. Miller Signed-off-by: Dominique Martinet Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- net/9p/trans_fd.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) --- a/net/9p/trans_fd.c +++ b/net/9p/trans_fd.c @@ -199,15 +199,14 @@ static void p9_mux_poll_stop(struct p9_c 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_con 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_con req->t_err = err; p9_client_cb(m->client, req, REQ_STATUS_ERROR); } + spin_unlock(&m->client->lock); } static __poll_t @@ -375,8 +374,9 @@ static void p9_read_work(struct work_str 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;