Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp1862177rwb; Fri, 19 Aug 2022 10:37:02 -0700 (PDT) X-Google-Smtp-Source: AA6agR78y+Hzcu1LcOSRBJjzF2wvp0jlBZojHZgKpt3+XyjXmlNqFn6y2B6RekkvGqT72wKvVlwB X-Received: by 2002:a17:906:9b08:b0:730:5d3c:4b1b with SMTP id eo8-20020a1709069b0800b007305d3c4b1bmr5589980ejc.606.1660930621835; Fri, 19 Aug 2022 10:37:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660930621; cv=none; d=google.com; s=arc-20160816; b=lDfYunvf1bZuVjils4wByKC81c0WMS4qVhGsohW5JDhp0eRlmGiwfhFAT+e7CRlYT2 CC0d2wCx2mCIs7uT66cLxlsqnTsLui8iiBvEQoixmyn1JP/oSw6aVj+gLhuwMBRdCTOW Q2IChH7Yy5hoFG0AHRoI2qY7ETksQjszUE7g9emLDRZ+7jWhs1r+MjeOXzhPZDyUkpwM zars88CwH8FWV3yrM0YuA5xDdCX1OosAIBJLN0AhlFrSYykIixW+E2U9yRg+lTiJZqZu 1SYIu9rkfuCAr726YynVowrrF3C5n+6Yd94hCbnRya4IDEagcVo1xM8CDT/h98VUxn22 fi9g== 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=VMtoUpWhLzlwPetz9pzd8S6COkfEHlOtxirxRpTEXQ0=; b=NczSB7RcCH/9YUgBi5HPCRH40ARTL2jOqDUjvf7p4Y/QSFUQtiHar1AarWASycvjLs HnQoIsjBSZZ6PHOVbqqA2n75apsiIGkmsmoVU6m6b86IDHdLmh7TZc38wxNrxOmytQvh DOuN4Nfjt6yTPUphvPASjy7hMXolUegCperfCxClRFlg3oYGLN5ZjMuNBSER1EC7CwBA wDJMFDUMMLGg3r/vt+V5kNb1beQSFbiY1hGnnMR7gnLDd0GvcXVM+YTGipTv2nzx73vh V6RVV3m1ObMBXfnVKQh1qZLDoaJK6dXHd/lZyaj1IheVhO5LF3hbFqg47JDx1LHRZEZe HTUw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=bZdw+dQD; 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 dr18-20020a170907721200b0072f1c8d0ec4si3337732ejc.584.2022.08.19.10.36.36; Fri, 19 Aug 2022 10:37:01 -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=bZdw+dQD; 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 S1352177AbiHSQTz (ORCPT + 99 others); Fri, 19 Aug 2022 12:19:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37300 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352168AbiHSQPu (ORCPT ); Fri, 19 Aug 2022 12:15:50 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E347FE398D; Fri, 19 Aug 2022 08:58:50 -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 A1398617A6; Fri, 19 Aug 2022 15:58:49 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7C883C433D6; Fri, 19 Aug 2022 15:58:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660924729; bh=H0jdplw0fqiMze9MxaK/cIh5ZG+lDAueEBDJlsMIsKY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bZdw+dQDMnrIslUaIk1+2Jw85TVLkQN+lr4XbIqbp7nSwaMzEKYF94oDr3XGMY9IO /cOOWIC7/9trz4S+u50txAqd1UvpPv1qXXja4XBpg8aoEcgdh1rxkoxAJLfGxkeHop BSUr1uB9wwtJ3KYOETINbG19F2h9VOHebiaDLSLw= 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.10 264/545] net: rose: fix netdev reference changes Date: Fri, 19 Aug 2022 17:40:34 +0200 Message-Id: <20220819153841.133848298@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220819153829.135562864@linuxfoundation.org> References: <20220819153829.135562864@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 cf7d974e0f61..29a208ed8fb8 100644 --- a/net/rose/af_rose.c +++ b/net/rose/af_rose.c @@ -191,6 +191,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; } } @@ -591,6 +592,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; @@ -644,6 +647,7 @@ static int rose_release(struct socket *sock) break; } + dev_put(rose->device); sock->sk = NULL; release_sock(sk); sock_put(sk); @@ -720,7 +724,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; @@ -777,9 +780,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; } @@ -787,6 +793,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 95b198f84a3a..981bdefd478b 100644 --- a/net/rose/rose_route.c +++ b/net/rose/rose_route.c @@ -613,6 +613,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