Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp3060875rwb; Mon, 15 Aug 2022 17:09:46 -0700 (PDT) X-Google-Smtp-Source: AA6agR5guMvr6uzA2BKMEHmQoHjpch6joQVwGKnOafu34qax380iAveNEN1LAibGRN8f4oLNcrZx X-Received: by 2002:a17:907:2d92:b0:731:3310:418d with SMTP id gt18-20020a1709072d9200b007313310418dmr11775398ejc.379.1660608585875; Mon, 15 Aug 2022 17:09:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660608585; cv=none; d=google.com; s=arc-20160816; b=hcJJGRkwCyZWnZ1a8IS1FlfOjWvPJ6MY1defRTYCNYJgDGSgVfKcnHlGNyTn2MkCml 4tjx9Volv+B4VDyNcpXHOSCqIUsrQhofjUhTcumB94th0II6HbZ9YMipIs9onmNiEDuV wXzfgyzCfQTyIDPUtvOQCkC4ZK4FPisOzymm1/8eHCbxGKk5wRCRqJklUyITW7EE/FxS 9q2vBEQwicC4DZRzdK21kJZRYCVTHLbu9FdjCu/Jp48oFyztP+wrLkPH9FLHQ2zr2z6A 3V3/CzJFOVSC0u9RhYF7RGZyD55zIlCcE9LBOS0q51g/b1rYpVpUQVLlewJcsDaaE3jk BXJA== 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=n27QIhHQC/tUCQk6DoLN9AraBl8s7d7Q7DIbODxLjV0=; b=qprMPt6odCuQx1vpIg0skRw7Vtk+4BXLYQInWGTKFvlJuzBMRMDa7WMHjDUnKeDW7u 8aek7a6zgANeGDRgikKj7RcjUH9yBWCXBeFhgQxE5HXXUupzGZBdkBy7ewOXVhgvoDwg pcBUy72Pw3sjbVEEAEBFI4e9voait5REE1jXxouvxgLxZ2cMdi1tjeZ3ihswvz9bBndF K3Ha8UCaeutQ7u3Si2Qta53YMHhIL+Pv1fdqyeZ7oB0euSWGiTIqPTepFNu2wB7QApCt fGzJ4BrP1UJAIqUtOhRRhwRjV8HBeZn8M01nat67spfpA1Cmb/r4DJ0KOQiSYLMze1fh oslw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=uiF8ZVP8; 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 j14-20020a056402238e00b0043c30f0f4a6si8407801eda.107.2022.08.15.17.09.16; Mon, 15 Aug 2022 17:09:45 -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=uiF8ZVP8; 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 S1352279AbiHPAFX (ORCPT + 99 others); Mon, 15 Aug 2022 20:05:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39888 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1354762AbiHOX5L (ORCPT ); Mon, 15 Aug 2022 19:57:11 -0400 Received: from sin.source.kernel.org (sin.source.kernel.org [IPv6:2604:1380:40e1:4800::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1EF07164429; Mon, 15 Aug 2022 13:20:15 -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 sin.source.kernel.org (Postfix) with ESMTPS id 0F2A3CE130B; Mon, 15 Aug 2022 20:20:14 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 228AEC433C1; Mon, 15 Aug 2022 20:20:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660594812; bh=babRv2B5l7m2rDS+DlymJa5KLjTrzKorVRbJUUyz1Ko=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uiF8ZVP8lC249WVlXSvp/yDtzVAxam8fRur6p56mSps6PMAaz7YGSYMD3T0MrUEvk 9KTKCLH7Lvkm9ABQIz2Y3qr/3S0z2ig+5sih2CZEoz68etOIJ2R4N+znOk08x6mORy JkPKVR0HaT+frC7nwtW8Rs6JXJNXnAVazJ6eh2jg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Bernard Pidoux , Eric Dumazet , Jakub Kicinski , Sasha Levin Subject: [PATCH 5.19 0566/1157] net: rose: fix netdev reference changes Date: Mon, 15 Aug 2022 19:58:42 +0200 Message-Id: <20220815180502.250972084@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180439.416659447@linuxfoundation.org> References: <20220815180439.416659447@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 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: Eric Dumazet [ Upstream commit 931027820e4dafabc78aff82af59f8c1c4bd3128 ] Bernard reported that trying to unload rose module would lead to infamous messages: unregistered_netdevice: waiting for rose0 to become free. Usage count = xx This patch solves the issue, by making sure each socket referring to a netdevice holds a reference count on it, and properly releases it in rose_release(). rose_dev_first() is also fixed to take a device reference before leaving the rcu_read_locked section. Following patch will add ref_tracker annotations to ease future bug hunting. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Reported-by: Bernard Pidoux Signed-off-by: Eric Dumazet Tested-by: Bernard Pidoux Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin --- net/rose/af_rose.c | 11 +++++++++-- net/rose/rose_route.c | 2 ++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/net/rose/af_rose.c b/net/rose/af_rose.c index bf2d986a6bc3..a8e3ec800a9c 100644 --- a/net/rose/af_rose.c +++ b/net/rose/af_rose.c @@ -192,6 +192,7 @@ static void rose_kill_by_device(struct net_device *dev) rose_disconnect(s, ENETUNREACH, ROSE_OUT_OF_ORDER, 0); if (rose->neighbour) rose->neighbour->use--; + dev_put(rose->device); rose->device = NULL; } } @@ -592,6 +593,8 @@ static struct sock *rose_make_new(struct sock *osk) rose->idle = orose->idle; rose->defer = orose->defer; rose->device = orose->device; + if (rose->device) + dev_hold(rose->device); rose->qbitincl = orose->qbitincl; return sk; @@ -645,6 +648,7 @@ static int rose_release(struct socket *sock) break; } + dev_put(rose->device); sock->sk = NULL; release_sock(sk); sock_put(sk); @@ -721,7 +725,6 @@ static int rose_connect(struct socket *sock, struct sockaddr *uaddr, int addr_le struct rose_sock *rose = rose_sk(sk); struct sockaddr_rose *addr = (struct sockaddr_rose *)uaddr; unsigned char cause, diagnostic; - struct net_device *dev; ax25_uid_assoc *user; int n, err = 0; @@ -778,9 +781,12 @@ static int rose_connect(struct socket *sock, struct sockaddr *uaddr, int addr_le } if (sock_flag(sk, SOCK_ZAPPED)) { /* Must bind first - autobinding in this may or may not work */ + struct net_device *dev; + sock_reset_flag(sk, SOCK_ZAPPED); - if ((dev = rose_dev_first()) == NULL) { + dev = rose_dev_first(); + if (!dev) { err = -ENETUNREACH; goto out_release; } @@ -788,6 +794,7 @@ static int rose_connect(struct socket *sock, struct sockaddr *uaddr, int addr_le user = ax25_findbyuid(current_euid()); if (!user) { err = -EINVAL; + dev_put(dev); goto out_release; } diff --git a/net/rose/rose_route.c b/net/rose/rose_route.c index eb0b8197ac82..fee772b4637c 100644 --- a/net/rose/rose_route.c +++ b/net/rose/rose_route.c @@ -615,6 +615,8 @@ struct net_device *rose_dev_first(void) if (first == NULL || strncmp(dev->name, first->name, 3) < 0) first = dev; } + if (first) + dev_hold(first); rcu_read_unlock(); return first; -- 2.35.1