Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp6117639imm; Mon, 23 Jul 2018 11:44:21 -0700 (PDT) X-Google-Smtp-Source: AAOMgpc7FfbVzYmbMw2+thfAdI5YI5G5YWCQrpBAYj8y4HyOjt/ALe9yO6vtV4fbTxRugiQUGfBr X-Received: by 2002:a63:1d5e:: with SMTP id d30-v6mr13682319pgm.12.1532371461698; Mon, 23 Jul 2018 11:44:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532371461; cv=none; d=google.com; s=arc-20160816; b=FEBwHgX61pQ0KNYvF1A764hB6mJUec0OTzYELBiZLA5fY9eyXQiL7kx2PSzPUwaobb gQhxLnHGHGlpKqnwBt+/NWztwNQwYTvSwURi31qfHS87ZOdFzGivzV+O5wZDbER/VaGm R8ak7m7CAh51aTYBsKYw2sH3VCSXkaJShAas/1PTW60lIRgKUvov5U4l+H4ZETO7U/oB i8GI4Mszf3mGP3TPe+1LUqW1/4M6cQlsvbDB1RtRZ0ScB/9qBtnHOUIide9CmkP1uQDQ NY14BhhOLTjbLs3S0Kgje2Lgtm1pQO31OG5Mj0OV3WzsM4TdgGs6UiXhotI7VCQa6366 iBXA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=y9Xfm3vtovJ8g5i3WTgcahs6SUzJIiJRUaY1j06RJ80=; b=Lb/dKg5r6knnGhd6fGiBYyTmqJ6eNTEi41EKW+FsJVPVMDO8z7Jx64haiMIk2FXGH+ ADKBHOd6QEuXsljtLAAKiZBxl915XiyPAinhs8sFXaXF3JNf0gDZgLO5AtLhMnascTtZ VH/EMgE8F4UtJlqGnO7RNU9HIrS8L66PuWU1w4M3ZUFVRc6qlaB0hSop+iEhamhoDlvY UxOvr3BaALUj2/xrJlYax98bysf4i7dSuWpXyI1aUrbLd9nhtY2c8FiTnXUFfnAoXq8l 1AG7qj2bnS3v0GZP/TM8QkTa0MosSAI7CdJNqOdf5BW9Kit2cXWP13ct6eBrGuPTO+sq BrDA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=JybiprDy; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t19-v6si9505432pgb.196.2018.07.23.11.44.06; Mon, 23 Jul 2018 11:44:21 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=JybiprDy; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388099AbeGWTps (ORCPT + 99 others); Mon, 23 Jul 2018 15:45:48 -0400 Received: from mail-lf1-f68.google.com ([209.85.167.68]:37473 "EHLO mail-lf1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387933AbeGWTps (ORCPT ); Mon, 23 Jul 2018 15:45:48 -0400 Received: by mail-lf1-f68.google.com with SMTP id j8-v6so1202977lfb.4; Mon, 23 Jul 2018 11:43:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=y9Xfm3vtovJ8g5i3WTgcahs6SUzJIiJRUaY1j06RJ80=; b=JybiprDyiwKJyF1VXoa3/XeX9kG5HxekyBk+iWyMkKoLfH1mRvXElSM0a+C3kakl9Q dcFB3g94U5eg6jYvEU4oZujOxugqgF5U2n+ck74YqDDblQGQ33/3BEYWFr8rZzoocqtP Nzp1XnN2m5h86jN+VN1+ELRKptVLZ8e5OByw1G6t8BhqDyKxhgQQNw+xOqO2htod2aGx Q7Zt5+CQluxrFZAR4yBj1JefKh7VQ8r5r8A0Bto182zelrTbdycUVDMonU+Ul5ICxBDy nktUt0BQ4M3Cd30BeqD8CMI/sJeL9Lsbth/RaXogV/lFxd4mkEjqlJVw4++h8Mf0LWpW 8ouQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=y9Xfm3vtovJ8g5i3WTgcahs6SUzJIiJRUaY1j06RJ80=; b=Pod+smngyFQo6/n1JWI3zvolSx5EYXhaEfGNTqnN7uqoW490koe7s+OqqVqbzqCy2F ropND1U5jJlgIapgy1BqUjjClqJbdAIcVlhJ2YYb9uInT7cIngvwa1E+EkfxscKFgW4X sutU2NagJxO9gwpxxALjHZbTXBNNGukiXq/wg8Xz3oxT7ZmcDApaa6K0tDmJno0z9orU 7kIUbanxr4dvARMw98zkFBpksbFM/WVuC04NI7dh9l/bMWxHCTccL1U9QeNuI8WmUPTC fdoElCQjpIviMYnLdLNhprvra6URcnm+Z7DsRWNHufjEVKrkRvqEDvw2ATjN1YSU2j0R uk9w== X-Gm-Message-State: AOUpUlHcQcDclz5pbzccqLPKJedKnrTMK4FmT4zq4t0CZywGL0NruDIQ ILseOuL0mNq9XzkNEtQNS3s= X-Received: by 2002:a19:120d:: with SMTP id h13-v6mr7884617lfi.13.1532371394446; Mon, 23 Jul 2018 11:43:14 -0700 (PDT) Received: from debian-tom.lan ([2001:2012:22e:1b00:f2e2:9015:9262:3fde]) by smtp.gmail.com with ESMTPSA id k65-v6sm1925437lje.3.2018.07.23.11.43.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 23 Jul 2018 11:43:13 -0700 (PDT) From: Tomas Bortoli To: ericvh@gmail.com, rminnich@sandia.gov, lucho@ionkov.net Cc: asmadeus@codewreck.org, davem@davemloft.net, v9fs-developer@lists.sourceforge.net, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, syzkaller@googlegroups.com, Tomas Bortoli Subject: [PATCH] net/9p/trans_fd.c: fix race by holding the lock Date: Mon, 23 Jul 2018 20:42:53 +0200 Message-Id: <20180723184253.6682-1-tomasbortoli@gmail.com> X-Mailer: git-send-email 2.11.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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; -- 2.11.0