Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp1253560imw; Tue, 5 Jul 2022 06:29:23 -0700 (PDT) X-Google-Smtp-Source: AGRyM1s1sPwHZeEbZjBaTwSvjwcbH3hWYYjk+MJbuC2kJ3l99I4nBmUEJBOXHYTTT9QHDdRRXJ57 X-Received: by 2002:a17:90a:ab16:b0:1ed:2251:a878 with SMTP id m22-20020a17090aab1600b001ed2251a878mr42306975pjq.231.1657027762846; Tue, 05 Jul 2022 06:29:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657027762; cv=none; d=google.com; s=arc-20160816; b=hjHHui+8KKa6HY+z4lLXRCGyc3P5qDNumkkxwZg53lwi99wAbzUY3wQor1i6NSRsGS fv0cJFF2WgsAijPKnj+XqOBjV9rwCMiXRMzUreLexh0nkeYr9wt3xVw/OIVhUJ7UpI+t 1Jy92WQYkAcclADTVErp+YJJYHNyxvzGgEyODo7PXV2E3c/sQ5aAh2i8Vf3BsNOx66h4 EDhuBGcv+nmGcMooE3kW4o27KTCkYBVtKDFMo7BJVOHxaaFLQg42Wh6OCve5IVRxnmDK lqqeyib91V62mHqVMnFil4RrK20guFYexf5OkNkJqHb2FUh8m73R20TLgiLCYw5PvqAi TRuA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=m5QF3/knbNIkfsz9Ih19xC9aRoqs1+tXr2aU7D7q+MY=; b=l7bmGe2RKQ8XTWgqcdmEIaJTVfi2RJs2yX8v8SZJgPJsjq2ojthJTEtcW15LNFVPxj dO41fTYDBZoksqUYN0u9OAb5/SwBvuORsy3w7bhFJ8M3r6XJln0Eeu0M0xiV4w7Q/Jjm n9roY7k69i26mBf60nuNRI+ovO59goA43saotz5aYhxyF0Hs7vx2pn7V0K1BRjwuV5mY vC0MFBM1XK+KPHs2PTLZHo6TVwOs90MoSEgxHKGFEneTyLvvsB0TLgu1ZsY9dKCgUFl3 nwE9OQGtb2HBhMyevvjZlfosUjj/ADm74Fu3AQg9QjNfjLpzIUNdJ14eCldPKaGkk5sq puXg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=w2DVuJ1N; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y3-20020a656c03000000b0040ce841ddb8si14129735pgu.499.2022.07.05.06.29.10; Tue, 05 Jul 2022 06:29:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=w2DVuJ1N; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234352AbiGEMVE (ORCPT + 99 others); Tue, 5 Jul 2022 08:21:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53850 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234056AbiGEMNe (ORCPT ); Tue, 5 Jul 2022 08:13:34 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DE7D81AD91; Tue, 5 Jul 2022 05:11:04 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 72A2561988; Tue, 5 Jul 2022 12:11:04 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 40798C341C7; Tue, 5 Jul 2022 12:11:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1657023063; bh=YiCygZYgHmwf26uNvEy1H53XouYE1er55VWdDFhki7A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=w2DVuJ1NoLnMvEXL7eSgK1iOuNtvM1Qi4AtkoKNLg6DRtj89SzjctXrdE2/5ECLfE uJxAMOa0w8frnYu+LI3vdmQBltNxs+k8D24wYm3Pim/oyX9h/PRX1840MYkoE0Vr6O iRHgjiNW/bufACPxPj0EtT+RXGcMjZ4o1VVvPdDo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Petar Penkov , Jakub Kicinski Subject: [PATCH 5.15 24/98] net: tun: stop NAPI when detaching queues Date: Tue, 5 Jul 2022 13:57:42 +0200 Message-Id: <20220705115618.278365758@linuxfoundation.org> X-Mailer: git-send-email 2.37.0 In-Reply-To: <20220705115617.568350164@linuxfoundation.org> References: <20220705115617.568350164@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jakub Kicinski commit a8fc8cb5692aebb9c6f7afd4265366d25dcd1d01 upstream. While looking at a syzbot report I noticed the NAPI only gets disabled before it's deleted. I think that user can detach the queue before destroying the device and the NAPI will never be stopped. Fixes: 943170998b20 ("tun: enable NAPI for TUN/TAP driver") Acked-by: Petar Penkov Link: https://lore.kernel.org/r/20220623042105.2274812-1-kuba@kernel.org Signed-off-by: Jakub Kicinski Signed-off-by: Greg Kroah-Hartman --- drivers/net/tun.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) --- a/drivers/net/tun.c +++ b/drivers/net/tun.c @@ -274,6 +274,12 @@ static void tun_napi_init(struct tun_str } } +static void tun_napi_enable(struct tun_file *tfile) +{ + if (tfile->napi_enabled) + napi_enable(&tfile->napi); +} + static void tun_napi_disable(struct tun_file *tfile) { if (tfile->napi_enabled) @@ -654,8 +660,10 @@ static void __tun_detach(struct tun_file if (clean) { RCU_INIT_POINTER(tfile->tun, NULL); sock_put(&tfile->sk); - } else + } else { tun_disable_queue(tun, tfile); + tun_napi_disable(tfile); + } synchronize_net(); tun_flow_delete_by_queue(tun, tun->numqueues + 1); @@ -809,6 +817,7 @@ static int tun_attach(struct tun_struct if (tfile->detached) { tun_enable_queue(tfile); + tun_napi_enable(tfile); } else { sock_hold(&tfile->sk); tun_napi_init(tun, tfile, napi, napi_frags);