Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp3018953rwb; Mon, 15 Aug 2022 16:15:48 -0700 (PDT) X-Google-Smtp-Source: AA6agR5DWcs5e6iRbs7G1asWY6tZdPBx/fdQFfuFX7IBRmDarYZhX++wvSX9LhgFcIOPPbGIM5fB X-Received: by 2002:a17:907:7e9f:b0:730:d954:c2b5 with SMTP id qb31-20020a1709077e9f00b00730d954c2b5mr11349537ejc.311.1660605348620; Mon, 15 Aug 2022 16:15:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660605348; cv=none; d=google.com; s=arc-20160816; b=fG9U9QUoQ5OluUIMaCI0G8qYw5GqVHRAtquzttKM+mndXbgPH6wZ/w6BUmPAQgmcRA RSUae/ZS3jppkHmNaCiYoCZ1fvlIvkKzvNIBQTB4cxDg7D2a5WdiS4BjwDhuGgQkimet rYGkMp5CBuFLNCyfyRQslLWZ9n0HccultpTr9c4tlTb6KNNEmdnBUMVgpTk1TkOS0SrF 6bMuOOuPF2W1rZ2WjBGGw6eDyjAZpJ8/qoayCijU93VBB4BXs5abwk/wYQkTLM+NPmUZ Ttoxt3Wg9b3hmWkTbhBRF+ABIuIwNfHYCNQ+buZMc4gz16NKhY+Hs2XVesiXyenoS7ib OWFA== 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=JUwnRSL2kFS6sDYbamt6N8k+StEaFXIHuuV/0ETPTik=; b=bMCmemUjN8ND9Cp9pM7aHuel5wZJuubu7OjE6CpZviMKCxlCLfeEWeA1/+aRAQZGfH ifyDlFqaxvEs7fyuPj9lRXiSJ5HdkiLT1MSFVRF7J03mrN+H8W3mZlrZdv/jY+wNtPwK UhuIwHc9uA/c/U5sc0jRXIrQrnYELekrOJ1Ruu3xovXEL6w1dEcE5jxkbEDBlVL5j3ls 8IA7EMQ8Mnv03QPoXo7SXWRh3eecn1POij1l00ySUwzADRUMocugRn475KZKCaNcdEw9 hgwV2vxEyKHZ69WNnioBi2FEEfGW9xqTxpaWv7dFBCHlahevLQixxY29dml+nYNDetoq TsRA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=UJiNHNG5; 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 jt4-20020a170906dfc400b00730822632e8si7659379ejc.535.2022.08.15.16.15.23; Mon, 15 Aug 2022 16:15:48 -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=UJiNHNG5; 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 S244805AbiHOVYz (ORCPT + 99 others); Mon, 15 Aug 2022 17:24:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37560 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346798AbiHOVSH (ORCPT ); Mon, 15 Aug 2022 17:18:07 -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 D046CB51; Mon, 15 Aug 2022 12:21:36 -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 4AADDCE12C8; Mon, 15 Aug 2022 19:21:35 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 31A4CC433C1; Mon, 15 Aug 2022 19:21:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660591293; bh=iHhW4qyLdoFyQYBl6J+HvzCnbf6OZqPZB8iVowfHA8Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UJiNHNG5q/8gTJ3G2XgHyPQQ0qR4YBEVrlTw37GBHT1VRyVoZ96HsdarOeNTAp7et vRGO2hxzBSP5Xj7NBZKb9rIs3M+lrw3v9duJREr19UB+Bqm/BCGAzDBVFzZZoVyThW kA99V0rLwxAn1vVENJTd9bV6ory0ZBs42LCS2Cek= 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.18 0532/1095] net: rose: fix netdev reference changes Date: Mon, 15 Aug 2022 19:58:51 +0200 Message-Id: <20220815180451.559061671@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180429.240518113@linuxfoundation.org> References: <20220815180429.240518113@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 5e93510fa3d2..09ad2d9e63c9 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