Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2872744yba; Sun, 28 Apr 2019 11:02:20 -0700 (PDT) X-Google-Smtp-Source: APXvYqz3B/619Z/lcaC1svh1DPpBgnRkAjkJMQRRrANE7XI/bQpBX6AyHD5Kb7D7XVjUJ/LjpWU4 X-Received: by 2002:a62:140d:: with SMTP id 13mr33479164pfu.114.1556474540733; Sun, 28 Apr 2019 11:02:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556474540; cv=none; d=google.com; s=arc-20160816; b=Py8fvxCi2hRxZkL47keKezDTmmbK8gA59KVZx8HCfmeOTuZaQ1tB10zpb0rBGHixmY jBst2KVeonflwvVMBcM3PA+n5mXZt9Urz56hTQvIxYSRvnDODhIHvjCEDdpPH+pvcaoC lUijsOUMdTErGaadKjPrcdtoDh+gtJLnz/eXSsx5lw4t9xFL66mbT4fsrt1ojiaOSN26 U6lvPDqCeSDGGOPvC909jsEfbe3fcw0seLP27uNhHThxhDKt6v4WqQAcpG6Ex67ujwHo FENO3jCuNrPF5PObZOU485PwLgoJojKowM23DToFEQdhz4V5/mj7nB+oaINTWGtC2zqZ dRxQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=cigPqpv3EbqRHveB6bMukXbNAdYdoNI2R+pRgqg/pak=; b=o3rnpT+sREr4/JmrCIF2JFoKBXdRMHV6/vZcNeQP2r++O3RcdUb6ovW1UcdQAwLr/N pxQz9UoJspAgnq0MyeZmiOMrEeAKEJZn81S6NK/Ni2AhnAtuEDg3Z2RI/CeI10kE9rMs ogdTBKtLOkGpbKjF1u2iDZxizNutr6AB4mBid9atW7Aju1PZJ+EA9Ll7sOzGXrxeoKbM 5xz0y8hGKeUaGM/hrm0uQXI91tLd6HVfRNup8qchKi/mDMaTDhrH7xyfYXqCzEf4OKXR oFrh0QBmaqrV6/8qa3kXUkG/Gtnhc68ZmttosKTgRb7u5vIgzSkW1ShEktPKchH7gqCb WXyA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=V7uhXqUE; 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 r9si30605226pls.323.2019.04.28.11.02.05; Sun, 28 Apr 2019 11:02:20 -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=V7uhXqUE; 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 S1727099AbfD1R7s (ORCPT + 99 others); Sun, 28 Apr 2019 13:59:48 -0400 Received: from mail-pl1-f194.google.com ([209.85.214.194]:42703 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726926AbfD1R7s (ORCPT ); Sun, 28 Apr 2019 13:59:48 -0400 Received: by mail-pl1-f194.google.com with SMTP id x15so3984900pln.9; Sun, 28 Apr 2019 10:59:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=cigPqpv3EbqRHveB6bMukXbNAdYdoNI2R+pRgqg/pak=; b=V7uhXqUEI2VtmyWshqsswwdT4xcBODxImnK+G5AEQU2F8Xo5/AeJJ04NbdpSF3+ETf zFEAiQEg0eWaNharc3qkRz4syjtRsyC82yilvcvKzcGLpRm2FcoKG3j74KVtxj7yR1s0 Xo9E8dhnwqeeiZswzro3T1juoqzIrzlD1K1JXEaP2vP5Cp6nD08BMJgaT8KJ2Q5sXu7c ncXVgqYHbKKjTA4qVgYqqSduDqk1kt2Mko9pmpDW8oy/J1KhvaoQP3jMAKStOlibpDFN KO0bJsWTQ4IhFslJ6G/0nx2nO0meAbt3cVoOCv/XIBdFRgJHvW+7z5qDaDoxkasBNpDw ZxMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=cigPqpv3EbqRHveB6bMukXbNAdYdoNI2R+pRgqg/pak=; b=ezr1JRg5cqiGCm70udyLo8LnoYcK5qRWKNcEXeBudPX2wbflw23DR15QHIdr0urVkg BoHGb3nE+8JkBAuyhbfOnEt0MApfrgebKCgeIjTSyWHwiZ//nfomGbqtx1gqsmAU9Oxr GMPurnG/qxG0rY+361/h0E243SvIFNhidKtMjvGqlKnlcfaRBhEazcbU/2+UhLfRRdfS JRqKxfFPYNYJNFqLS8PKbrwcF6ofc/FBh4yaRi9MGb7XihndjWvRlYgA7YX2RrwfsVpH 60ZavyHJL9MneQQSu2oK8bAoLdeiL2TU+FxFwexRvKpjJk1yd4O83dw1qFGWRuMmKPxV GV2w== X-Gm-Message-State: APjAAAWTlq+/ycd74QKbo/j6oOlfEMe0Bz4eOQ7FoyN+wZA7Ua5O2m5N 5qBQ1/VTYkB/FIcv1nrDS0GNyGTRkFcvYGpGsQbsZ73H X-Received: by 2002:a17:902:9b8d:: with SMTP id y13mr3478970plp.70.1556474387663; Sun, 28 Apr 2019 10:59:47 -0700 (PDT) MIME-Version: 1.0 References: <71250616-36c1-0d96-8fac-4aaaae6a28d4@redhat.com> <20190428030539.17776-1-yuehaibing@huawei.com> <516ba6e4-359b-15d0-e169-d8cc1e989a4a@redhat.com> <2c823bbf-28c4-b43d-52d9-b0e0356f03ae@redhat.com> <6AADFAC011213A4C87B956458587ADB4021F7531@dggeml532-mbs.china.huawei.com> In-Reply-To: From: Cong Wang Date: Sun, 28 Apr 2019 10:59:36 -0700 Message-ID: Subject: Re: [PATCH] tun: Fix use-after-free in tun_net_xmit To: Jason Wang Cc: "weiyongjun (A)" , yuehaibing , "davem@davemloft.net" , "edumazet@google.com" , "brouer@redhat.com" , "mst@redhat.com" , "lirongqing@baidu.com" , "nicolas.dichtel@6wind.com" , "3chas3@gmail.com" <3chas3@gmail.com>, "wangli39@baidu.com" , "linux-kernel@vger.kernel.org" , "netdev@vger.kernel.org" , Peter Xu Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Apr 28, 2019 at 12:51 AM Jason Wang wrote: > > tun_net_xmit() doesn't have the chance to > > access the change because it holding the rcu_read_lock(). > > > The problem is the following codes: > > > --tun->numqueues; > > ... > > synchronize_net(); > > We need make sure the decrement of tun->numqueues be visible to readers > after synchronize_net(). And in tun_net_xmit(): It doesn't matter at all. Readers are okay to read it even they still use the stale tun->numqueues, as long as the tfile is not freed readers can read whatever they want... The decrement of tun->numqueues is just how we unpublish the old tfile, it is still valid for readers to read it _after_ unpublish, we only need to worry about free, not about unpublish. This is the whole spirit of RCU. You need to rethink about my SOCK_RCU_FREE patch. Thanks.