Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp3408358rwa; Tue, 23 Aug 2022 04:24:13 -0700 (PDT) X-Google-Smtp-Source: AA6agR7Iv/La9xqriUc+p4zJzV6Cx5xwvgtIju9QdMnXrFjuwKvezTmY9Bp4H+ioMutgZOq50mVY X-Received: by 2002:a17:90a:6b4c:b0:1fa:d973:e4eb with SMTP id x12-20020a17090a6b4c00b001fad973e4ebmr2789223pjl.15.1661253852905; Tue, 23 Aug 2022 04:24:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661253852; cv=none; d=google.com; s=arc-20160816; b=MQZ9QADz0AFhJcRLKaVAIfCcKDiCMC4+Fe3jNZHEwZVG/z/mDObSPVXiv1DXi4zrEJ Tj1Dr0qPLeki37/g8w614nMy1auAH3jORcG4SgavSw8Em+qoQp2oQZ3FbdEPhE9ssFaL 4ll8fU5VkD3e6ndN/gVP63oHJGnlCdQlukCr0YeGEqsDLYXHuGMYRijhpKVuaxnczf31 NNO3RZlp4dAe6NjOB9R6nhXDaKU0k+bZ3fcgwK5ZwKBY3q5qyFeH1aemE08vdob8wfmV I+mYVZaoky+2zBFQLbCVltbnY7M7H8fP/cvSdxNuKxhmE1ow7Bg8owTi4HEnKySn3AOc eLIg== 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=fn1A9G9EhDLwY08SP5tre6OnZcTDdn8+4m5M3GMh+iQ=; b=sDlcE/23R6Cg9KnxfUDzEdhJI3TrwMVqgrzQuuqevuFa/4wcFpo1K5YrDRPBD5zICk S36so1fJ2zo4B8mVTQ9Bdu66Cy91uepS7QdnPFoJruYHJCcpQwrQE++4qhyHSlV7FMGC NWTqVz4T2A8RU1mAQRZAXJDdBin88eCm8Q2yH/AX6O8ePhCXE40wsCTvfiQr9gge/Ckx e6QO9DaU00raB3D5iRyrTgdAsOfTCwiHk6mEMhyHGMKw0YztizMF+UjjrWn3hKFupU1Y 64/eRVsLk9JH43IOctgNNZSQ83pl0VJjZdJg65DcxAFXZihznf08a6PpEnPfsAR4T62Y TnNQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=HooSGEnZ; 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 t70-20020a638149000000b00429c526b398si15110669pgd.484.2022.08.23.04.24.02; Tue, 23 Aug 2022 04:24:12 -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=HooSGEnZ; 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 S1355686AbiHWKpS (ORCPT + 99 others); Tue, 23 Aug 2022 06:45:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45074 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1355734AbiHWKg6 (ORCPT ); Tue, 23 Aug 2022 06:36:58 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F0D72A6C38; Tue, 23 Aug 2022 02:07:26 -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 ams.source.kernel.org (Postfix) with ESMTPS id 731A3B81C89; Tue, 23 Aug 2022 09:07:25 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B4195C433D6; Tue, 23 Aug 2022 09:07:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661245644; bh=YrtYR5uzYTGHvW1l1duOpFLg7RFtdbzcLZIhVMmPlcc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HooSGEnZeecdagB0+kQsxM506ftYGTKw+34qGWFlpYuKQNNtOZMxfXyCfcWKYKaOv FY65ThT6U2ttUvQUanpY+nJC8bh4qnmb5bnTtt/uGuCHXriY8K3k9PAydYZ5nSQ5Sw Z+b6E4VU7eU6P0KTWr1XVFcdLrAHdZ2xfB7AciG4= 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 4.19 111/287] net: rose: fix netdev reference changes Date: Tue, 23 Aug 2022 10:24:40 +0200 Message-Id: <20220823080104.106110987@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220823080100.268827165@linuxfoundation.org> References: <20220823080100.268827165@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 d00a0ef39a56..03a1ee221112 100644 --- a/net/rose/af_rose.c +++ b/net/rose/af_rose.c @@ -194,6 +194,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; } } @@ -594,6 +595,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; @@ -647,6 +650,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 46ae92d70324..5671853bef83 100644 --- a/net/rose/rose_route.c +++ b/net/rose/rose_route.c @@ -616,6 +616,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