Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp2096614imm; Thu, 19 Jul 2018 13:07:55 -0700 (PDT) X-Google-Smtp-Source: AAOMgpe45JF+TobAvDE4G9WjVqjNWvYOCEo9+zX1CgiMNbiZ9HXTK1YL8ABS7a22+O4EOR8gS9y5 X-Received: by 2002:a63:2704:: with SMTP id n4-v6mr11019711pgn.87.1532030875291; Thu, 19 Jul 2018 13:07:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532030875; cv=none; d=google.com; s=arc-20160816; b=dU0heGjVe3BRvHUbXFM8q5b+zixsO95hErXc16fyXRzda8oEjswTU0YOpK1HEeGa9Y wW3MD3+d1a5qryZ8jfNdTMenpuzzjis5B1C70bDzHRC7IZYsCRa5vZn5hE+qUv1qgBDr ndKhbsaFw75Typ7gCzImlWpT3GH7SnIzrUG/GOmnLx4lQcYZ5xE8N6criOnoRVNRa/ah RR6NRzNXpBDcHLnT4cpLFaVMbt1DN/0Wwp3z4K13vHZzYOqO6mmtdEFDZnGmxVzfKdn0 mgDE6D/EpY6NwzMK/vvo2sfapYBOV3YgIARxzAi5lyzGpN7fWcRC5LrdH0BEy0Fu6mMR jhkQ== 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=uxQ7ZVIbXjJzI3VK2/066QXTwvE33shPFfeCFLf9jAg=; b=q90PecrMyC4Wdvi+e47JuRQxf5A923i3yCsO5j4Xw/HiNuu1pW5NqYfKFLAIKY3Z7n GpMRt1GP3KH7JcQLzemlhdRN9uEbYAsvzJI7I7WqwrlVX2XW4wEtF6dVjXqKmak536zG Dq+QgiQTkR0nbclI2I8D4Jlev6YuA0ACTw6WwyY0nZk8DxC6nVZiHLDS8PGc+IB//9i9 pZNTztXPVtDY6V584iNwsY8NMpJoC9DNKfdr6ZuNmBrTwJM4kvAyyeiSzc1EUBW4nsxb NFO8aHXm+sib1SeARq+svPswWWPQx1vH2t9qVs8pR/DpIZEa4m/K78NX0yl2fGOB5p1y ek5A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=PaMutjyi; 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 b1-v6si24857pli.54.2018.07.19.13.07.39; Thu, 19 Jul 2018 13:07:55 -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=PaMutjyi; 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 S1729692AbeGSUvq (ORCPT + 99 others); Thu, 19 Jul 2018 16:51:46 -0400 Received: from mail-lj1-f193.google.com ([209.85.208.193]:42452 "EHLO mail-lj1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727556AbeGSUvq (ORCPT ); Thu, 19 Jul 2018 16:51:46 -0400 Received: by mail-lj1-f193.google.com with SMTP id f1-v6so7541955ljc.9; Thu, 19 Jul 2018 13:07:04 -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=uxQ7ZVIbXjJzI3VK2/066QXTwvE33shPFfeCFLf9jAg=; b=PaMutjyiOyNjrFlxU+kx1EefLaYZt+/P+RHvufduslt6xpIosFZlLpOTnTnTVmDbsW veIitudfED1A27G6t6oPBvpaND/7oJAMbj2r9hjW/T6kTtX4Rc32kTy5kaQHfPkQG3SL szvcUvxUvEyGJYzRErqJC0pJY6RBFqXcSoewky6xu07Yl5ODftEky25JrAiEYokWmTQm 147FRVCqToiD8xDpVD2GqPkO2Ovy98Twa9k11/sacgONu2Bhjm+2DNbE4i+1dU8NvTsy Ae67sGZNVCDB8pcj2E0bN0qB5f3LGAD5U6rGNPEMwlyHkhhTZyQNqGZ9dhnBsRmbikjy njKA== 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=uxQ7ZVIbXjJzI3VK2/066QXTwvE33shPFfeCFLf9jAg=; b=WLXbaa+Ku5pAHWWgR//dsLAcAbkIQqWqlrzauhrrwmRNL8iWxvBe0GdjjwwIXHmiTN yQIHK0GoAkQfX7bUq34AAPzyoqf/I10lPahs5uEkrfh4syCiro+n/Kl6R352zw5HfOLo JMMXqk4xfxOOcfQAToAAWthPWoIgW5Y5jz1dyu7AbZIdxIc2VKhjfa59v/uXMJuSljTi M+nppyw4mwI5+0ldqWdp4mNtSamPKYlzmFL80xbOsd67FeXR8w7c0MmQLWNSwH8yfo4I oSCDL9xuLjD6kmuMc2ASowuYkkBA2YJTPcyVSyIlC25XeFV5XB2rCDqlQ9QEsTQdzBGh zPlg== X-Gm-Message-State: AOUpUlGdISIo0+yyjtkLruP0syv2wK6PhTCgkkuQYusgHa5w6rWDWhRR Sqcv5U4WVgEeboKzeY1HGXE= X-Received: by 2002:a2e:9d0e:: with SMTP id t14-v6mr8649997lji.112.1532030823880; Thu, 19 Jul 2018 13:07:03 -0700 (PDT) Received: from debian-tom.lan ([2001:2012:22e:1b00:f2e2:9015:9262:3fde]) by smtp.gmail.com with ESMTPSA id o11-v6sm8397ljh.34.2018.07.19.13.07.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 19 Jul 2018 13:07:02 -0700 (PDT) From: Tomas Bortoli To: ericvh@gmail.com, rminnich@sandia.gov, lucho@ionkov.net Cc: 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-condition by flushing workqueue before the kfree() Date: Thu, 19 Jul 2018 22:06:07 +0200 Message-Id: <20180719200607.30286-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 The patch adds the flush in p9_mux_poll_stop() as it the function used by p9_conn_destroy(), in turn called by p9_fd_close() to stop the async polling associated with the data regarding the connection. Signed-off-by: Tomas Bortoli Reported-by: syzbot+39749ed7d9ef6dfb23f6@syzkaller.appspotmail.com --- As shown by Syzbot, it is possible to provoke a race between p9_fd_close() and p9_poll_workfn() that is called to take care of the async read/write work to do. To make sure p9_fd_close() frees "trans" when it is not used anymore, it has to explicitly call flush_scheduled_work() before the kfree(). net/9p/trans_fd.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c index bf459ee0feab..76ae134c05d9 100644 --- a/net/9p/trans_fd.c +++ b/net/9p/trans_fd.c @@ -185,6 +185,8 @@ static void p9_mux_poll_stop(struct p9_conn *m) spin_lock_irqsave(&p9_poll_lock, flags); list_del_init(&m->poll_pending_link); spin_unlock_irqrestore(&p9_poll_lock, flags); + + flush_scheduled_work(); } /** -- 2.11.0