Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp1194854pxa; Thu, 20 Aug 2020 05:19:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzLjJxzSFGG/glvQh909hEnsOyQPOedKGttfhXHiMYfVyxPBqlwoVMpy8ap029qDNhXm6kf X-Received: by 2002:a05:6402:3199:: with SMTP id di25mr2639137edb.315.1597925949686; Thu, 20 Aug 2020 05:19:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597925949; cv=none; d=google.com; s=arc-20160816; b=R7JfrN5+4wOaOu2Cw7QcxEPPqyAnhQOwmmCgxUrzvJBe8S+l0Z/tSdcj1ihQESBTt7 acarwQ+5udIgOcldrEWlZLnBkTg2/nlso+0zfLwMxdcqTjMPG5HGcDWwjsSnw9mr3Zo2 bdUhIx5RLGcr4MKmajhW5wCkk6f5B3KxsK3AACJ/w8Wspu3/2EFop0ZdNc9e1UqXoQOr O2pOpyvu5karRHSSWstT3cCnRaJi6YEy08rXP3Ge6RcQ8YJ9TBHKaQ7WyGAliMLrZMV5 jR3KC+KGTJMI2orXYASob4rfLjQIoNO9ZsQh4UClIPUc9NvTv/hxbo1zOWTTSO4VNfKF t0Ug== 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:dkim-signature; bh=y46GXEN5U7E4s4OPcYz2GK4eoeWQJmq56RU99MP4r8I=; b=lYNqcfJPItEb5euCg6kFHij9FTOm4bsaO1ObBYttGsa8/qbjk5FdlZMrAwIVFSkqW5 2eKIemLuknSVa283bOOihjfBItoozcGDkp9C+CUfhEuEWZLv9SSvxQRNBkwlOD9JUrOT GQTz8bqstVjmeDyngNXtlLc+q/vApz7uucmt4/5Q92WFrs5xKluiLFjN8NscGQ64KgfX dwvGNAtQA+TsWPd5HJ7uZam9rEgT/lOxaDUj0s0b2+cVx/jrKgWDJim39RncY+UFZe+v 3OWhK9VprSM7wevVx9sUdVBodishgi8pw1PHJiIzXIb+dBG1z9wJ85ffS/noZMbSr2CP q8Lg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=dohGRD9t; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id gl17si1086082ejb.589.2020.08.20.05.18.45; Thu, 20 Aug 2020 05:19:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=dohGRD9t; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730475AbgHTMSD (ORCPT + 99 others); Thu, 20 Aug 2020 08:18:03 -0400 Received: from mail.kernel.org ([198.145.29.99]:39984 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726925AbgHTJ4d (ORCPT ); Thu, 20 Aug 2020 05:56:33 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id C38832067C; Thu, 20 Aug 2020 09:56:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597917393; bh=WBgfNVb4k44s9KC7OFjmYwafkNkP4GWt5fO3r7F+LYI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dohGRD9tu4qYSUdsX/lHBQr3vkGpgRn/aSTQs+9BNJM2XZK7oPzGyiD1/593zN1d4 CpQTUfx56KapxdX/sK5C8mlXPKZqpVo8jgz/CBkdz5DjQM2JeAsPbFXR/l8kMIpQSK VIW8UtJCqFqgczE1zo5uV7DJMl6BGIYtPrhmuqPk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+77a25acfa0382e06ab23@syzkaller.appspotmail.com, Wang Hai , Dominique Martinet , Sasha Levin Subject: [PATCH 4.9 016/212] 9p/trans_fd: Fix concurrency del of req_list in p9_fd_cancelled/p9_read_work Date: Thu, 20 Aug 2020 11:19:49 +0200 Message-Id: <20200820091603.156368680@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200820091602.251285210@linuxfoundation.org> References: <20200820091602.251285210@linuxfoundation.org> User-Agent: quilt/0.66 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 From: Wang Hai [ Upstream commit 74d6a5d5662975aed7f25952f62efbb6f6dadd29 ] p9_read_work and p9_fd_cancelled may be called concurrently. In some cases, req->req_list may be deleted by both p9_read_work and p9_fd_cancelled. We can fix it by ignoring replies associated with a cancelled request and ignoring cancelled request if message has been received before lock. Link: http://lkml.kernel.org/r/20200612090833.36149-1-wanghai38@huawei.com Fixes: 60ff779c4abb ("9p: client: remove unused code and any reference to "cancelled" function") Cc: # v3.12+ Reported-by: syzbot+77a25acfa0382e06ab23@syzkaller.appspotmail.com Signed-off-by: Wang Hai Signed-off-by: Dominique Martinet Signed-off-by: Sasha Levin --- net/9p/trans_fd.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c index 91f71958c2e16..b0f47563f0bf3 100644 --- a/net/9p/trans_fd.c +++ b/net/9p/trans_fd.c @@ -377,6 +377,10 @@ static void p9_read_work(struct work_struct *work) if (m->req->status == REQ_STATUS_SENT) { list_del(&m->req->req_list); p9_client_cb(m->client, m->req, REQ_STATUS_RCVD); + } else if (m->req->status == REQ_STATUS_FLSHD) { + /* Ignore replies associated with a cancelled request. */ + p9_debug(P9_DEBUG_TRANS, + "Ignore replies associated with a cancelled request\n"); } else { spin_unlock(&m->client->lock); p9_debug(P9_DEBUG_ERROR, @@ -717,11 +721,20 @@ static int p9_fd_cancelled(struct p9_client *client, struct p9_req_t *req) { p9_debug(P9_DEBUG_TRANS, "client %p req %p\n", client, req); + spin_lock(&client->lock); + /* Ignore cancelled request if message has been received + * before lock. + */ + if (req->status == REQ_STATUS_RCVD) { + spin_unlock(&client->lock); + return 0; + } + /* we haven't received a response for oldreq, * remove it from the list. */ - spin_lock(&client->lock); list_del(&req->req_list); + req->status = REQ_STATUS_FLSHD; spin_unlock(&client->lock); return 0; -- 2.25.1