From nobody Wed Dec 17 03:13:20 2025 Received: from sgoci-sdnproxy-4.icoremail.net (sgoci-sdnproxy-4.icoremail.net [129.150.39.64]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 73A2813CAB7; Thu, 9 May 2024 01:56:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=129.150.39.64 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715219792; cv=none; b=cMLhSl4R2ZMwR7zFtMizIRFe5RCkzuj7fjEMQLiv81B4rn1g/nvv1eC1kz7UgB3uoY2D1MWjfQZqmaEC1nqNLnS1RSY/2Jq0UuWV1voprnZNEIBjZ/qoHMA66lZjQSszs9LyM6aN+ApgffsPWjvew6jEUxY2JEfy31Z3M9WupL8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715219792; c=relaxed/simple; bh=13gDM9SHnWumwF7mjNB55HranphOClB2GlO71pvtBTU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=NS2ywEgJrU8d9bsY7oN82wumY8asFR/i0HwBEfj+5fIbpUMck7xDuPJOaOHL/TjPLXodOE9M9asm2IznLFwN1rRNs+CBQHW+2C8WNumHT6LzDfeDJeoTOfj+IOiuZnZATIF/HzgTwo99Dhx1ycnxRd1bUq0/WQC65u2W/cfEnCs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=zju.edu.cn; spf=pass smtp.mailfrom=zju.edu.cn; arc=none smtp.client-ip=129.150.39.64 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=zju.edu.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=zju.edu.cn Received: from ubuntu.localdomain (unknown [221.192.180.131]) by mail-app4 (Coremail) with SMTP id cS_KCgD3hLI9LTxmyklMAA--.57094S2; Thu, 09 May 2024 09:56:16 +0800 (CST) From: Duoming Zhou To: netdev@vger.kernel.org Cc: linux-kernel@vger.kernel.org, linux-hams@vger.kernel.org, pabeni@redhat.com, kuba@kernel.org, edumazet@google.com, davem@davemloft.net, jreuter@yaina.de, dan.carpenter@linaro.org, Duoming Zhou Subject: [PATCH net v6 1/3] ax25: Use kernel universal linked list to implement ax25_dev_list Date: Thu, 9 May 2024 09:56:12 +0800 Message-Id: X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-CM-TRANSID: cS_KCgD3hLI9LTxmyklMAA--.57094S2 X-Coremail-Antispam: 1UD129KBjvJXoW3GFyfGF1xKFy5KFWxXr43ZFb_yoW7XrW8pF WakFyrArZ7Jr1UAr4DWF1xWr1jyrWUt3yDAry5uF1Skw1DX3s8Jr1rtryUJryUGrW3Ar18 J34UXr4DAr48ZF7anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUU9C14x267AKxVW8JVW5JwAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2ocxC64kIII0Yj41l84x0c7CEw4AK67xGY2AK02 1l84ACjcxK6xIIjxv20xvE14v26w1j6s0DM28EF7xvwVC0I7IYx2IY6xkF7I0E14v26F4U JVW0owA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oV Cq3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0 I7IYx2IY67AKxVWUXVWUAwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r 4UM4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwACI402YVCY1x02628v n2kIc2xKxwCY1x0262kKe7AKxVWUtVW8ZwCY02Avz4vE14v_KwCF04k20xvY0x0EwIxGrw CFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v26r1j6r18MI8I3I0E7480Y4vE 14v26r106r1rMI8E67AF67kF1VAFwI0_Jw0_GFylIxkGc2Ij64vIr41lIxAIcVC0I7IYx2 IY67AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Gr0_Cr1lIxAIcVCF04k26cxK x2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r1j6r4UMIIF0xvEx4A2jsIEc7CjxVAFwI 0_Gr0_Gr1UYxBIdaVFxhVjvjDU0xZFpf9x0JUL4SrUUUUU= X-CM-SenderInfo: qssqjiasttq6lmxovvfxof0/1tbiAwIQAWY7nwoGrwAIs5 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The origin ax25_dev_list implements its own single linked list, which is complicated and error-prone. For example, when deleting the node of ax25_dev_list in ax25_dev_device_down(), we have to operate on the head node and other nodes separately. This patch uses kernel universal linked list to replace original ax25_dev_list, which make the operation of ax25_dev_list easier. There are two points that need to notice: [1] We should add a check to judge whether the list is empty before INIT_LIST_HEAD in ax25_dev_device_up(), otherwise it will empty the list for each new ax25_dev added. [2] We should do "dev->ax25_ptr =3D ax25_dev;" and "dev->ax25_ptr =3D NULL;" while holding the spinlock, otherwise the ax25_dev_device_up() and ax25_dev_device_down() could race, we're not guaranteed to find a match ax25_dev in ax25_dev_device_down(). Suggested-by: Dan Carpenter Signed-off-by: Duoming Zhou --- include/net/ax25.h | 3 +-- net/ax25/ax25_dev.c | 43 ++++++++++++++++++------------------------- 2 files changed, 19 insertions(+), 27 deletions(-) diff --git a/include/net/ax25.h b/include/net/ax25.h index 0d939e5aee4..c2a85fd3f5e 100644 --- a/include/net/ax25.h +++ b/include/net/ax25.h @@ -216,7 +216,7 @@ typedef struct { struct ctl_table; =20 typedef struct ax25_dev { - struct ax25_dev *next; + struct list_head list; =20 struct net_device *dev; netdevice_tracker dev_tracker; @@ -330,7 +330,6 @@ int ax25_addr_size(const ax25_digi *); void ax25_digi_invert(const ax25_digi *, ax25_digi *); =20 /* ax25_dev.c */ -extern ax25_dev *ax25_dev_list; extern spinlock_t ax25_dev_lock; =20 #if IS_ENABLED(CONFIG_AX25) diff --git a/net/ax25/ax25_dev.c b/net/ax25/ax25_dev.c index 282ec581c07..56b14d240a6 100644 --- a/net/ax25/ax25_dev.c +++ b/net/ax25/ax25_dev.c @@ -22,11 +22,12 @@ #include #include #include +#include #include #include #include =20 -ax25_dev *ax25_dev_list; +LIST_HEAD(ax25_dev_list); DEFINE_SPINLOCK(ax25_dev_lock); =20 ax25_dev *ax25_addr_ax25dev(ax25_address *addr) @@ -34,7 +35,7 @@ ax25_dev *ax25_addr_ax25dev(ax25_address *addr) ax25_dev *ax25_dev, *res =3D NULL; =20 spin_lock_bh(&ax25_dev_lock); - for (ax25_dev =3D ax25_dev_list; ax25_dev !=3D NULL; ax25_dev =3D ax25_de= v->next) + list_for_each_entry(ax25_dev, &ax25_dev_list, list) if (ax25cmp(addr, (const ax25_address *)ax25_dev->dev->dev_addr) =3D=3D = 0) { res =3D ax25_dev; ax25_dev_hold(ax25_dev); @@ -52,6 +53,9 @@ void ax25_dev_device_up(struct net_device *dev) { ax25_dev *ax25_dev; =20 + /* Initialized the list for the first entry */ + if (!ax25_dev_list.next) + INIT_LIST_HEAD(&ax25_dev_list); ax25_dev =3D kzalloc(sizeof(*ax25_dev), GFP_KERNEL); if (!ax25_dev) { printk(KERN_ERR "AX.25: ax25_dev_device_up - out of memory\n"); @@ -59,7 +63,6 @@ void ax25_dev_device_up(struct net_device *dev) } =20 refcount_set(&ax25_dev->refcount, 1); - dev->ax25_ptr =3D ax25_dev; ax25_dev->dev =3D dev; netdev_hold(dev, &ax25_dev->dev_tracker, GFP_KERNEL); ax25_dev->forward =3D NULL; @@ -85,8 +88,8 @@ void ax25_dev_device_up(struct net_device *dev) #endif =20 spin_lock_bh(&ax25_dev_lock); - ax25_dev->next =3D ax25_dev_list; - ax25_dev_list =3D ax25_dev; + list_add(&ax25_dev->list, &ax25_dev_list); + dev->ax25_ptr =3D ax25_dev; spin_unlock_bh(&ax25_dev_lock); ax25_dev_hold(ax25_dev); =20 @@ -111,32 +114,25 @@ void ax25_dev_device_down(struct net_device *dev) /* * Remove any packet forwarding that points to this device. */ - for (s =3D ax25_dev_list; s !=3D NULL; s =3D s->next) + list_for_each_entry(s, &ax25_dev_list, list) if (s->forward =3D=3D dev) s->forward =3D NULL; =20 - if ((s =3D ax25_dev_list) =3D=3D ax25_dev) { - ax25_dev_list =3D s->next; - goto unlock_put; - } - - while (s !=3D NULL && s->next !=3D NULL) { - if (s->next =3D=3D ax25_dev) { - s->next =3D ax25_dev->next; + list_for_each_entry(s, &ax25_dev_list, list) { + if (s =3D=3D ax25_dev) { + list_del(&s->list); goto unlock_put; } - - s =3D s->next; } - spin_unlock_bh(&ax25_dev_lock); dev->ax25_ptr =3D NULL; + spin_unlock_bh(&ax25_dev_lock); ax25_dev_put(ax25_dev); return; =20 unlock_put: + dev->ax25_ptr =3D NULL; spin_unlock_bh(&ax25_dev_lock); ax25_dev_put(ax25_dev); - dev->ax25_ptr =3D NULL; netdev_put(dev, &ax25_dev->dev_tracker); ax25_dev_put(ax25_dev); } @@ -200,16 +196,13 @@ struct net_device *ax25_fwd_dev(struct net_device *de= v) */ void __exit ax25_dev_free(void) { - ax25_dev *s, *ax25_dev; + ax25_dev *s, *n; =20 spin_lock_bh(&ax25_dev_lock); - ax25_dev =3D ax25_dev_list; - while (ax25_dev !=3D NULL) { - s =3D ax25_dev; - netdev_put(ax25_dev->dev, &ax25_dev->dev_tracker); - ax25_dev =3D ax25_dev->next; + list_for_each_entry_safe(s, n, &ax25_dev_list, list) { + netdev_put(s->dev, &s->dev_tracker); + list_del(&s->list); kfree(s); } - ax25_dev_list =3D NULL; spin_unlock_bh(&ax25_dev_lock); } --=20 2.17.1 From nobody Wed Dec 17 03:13:20 2025 Received: from zg8tmja5ljk3lje4ms43mwaa.icoremail.net (zg8tmja5ljk3lje4ms43mwaa.icoremail.net [209.97.181.73]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6E50C13C8E4; Thu, 9 May 2024 01:56:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.97.181.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715219807; cv=none; b=J6q7kApJYeo0QP1mK2qxqxd7cOC8W6WBzH0GKvuUbJAc8/YBRrC1CSsv1h5jdVV0Nmn0UUblRv8LV/cOHa1bnrvQUk7SkwUVd5JV3HxqIEfJRP029RGQ0s5ud0mxaG2reZ4YVe9HZZu9Kzj1/DS9Cf1uzFfhpxgetUBDl5FeWlA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715219807; c=relaxed/simple; bh=pAMA04ifScVk7DtVBKC9aemVsE2UnpKI1hMezSYxt8I=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=mbT/iS08Ifxxt0alA1GpDlMX2I/d668xb5QihZMd2/1Sv1mZyVVSzHV3JD5az0AyWvtp7HxyiBHMF2hSn1vZuSDRC3RB2AUVCQpMqlmL4ALfoxGTB5igPcmPpwEzmgoVk+KowxAW7XTIT0CudpoGHI+Ngz8zT3VmvokXs3MUklQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=zju.edu.cn; spf=pass smtp.mailfrom=zju.edu.cn; arc=none smtp.client-ip=209.97.181.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=zju.edu.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=zju.edu.cn Received: from ubuntu.localdomain (unknown [221.192.180.131]) by mail-app4 (Coremail) with SMTP id cS_KCgDX9rRKLTxm_0lMAA--.21121S2; Thu, 09 May 2024 09:56:29 +0800 (CST) From: Duoming Zhou To: netdev@vger.kernel.org Cc: linux-kernel@vger.kernel.org, linux-hams@vger.kernel.org, pabeni@redhat.com, kuba@kernel.org, edumazet@google.com, davem@davemloft.net, jreuter@yaina.de, dan.carpenter@linaro.org, Duoming Zhou Subject: [PATCH net v6 2/3] ax25: Fix reference count leak issues of ax25_dev Date: Thu, 9 May 2024 09:56:25 +0800 Message-Id: X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-CM-TRANSID: cS_KCgDX9rRKLTxm_0lMAA--.21121S2 X-Coremail-Antispam: 1UD129KBjvJXoW7ZF4rXr4Utr1rur1UtFykGrg_yoW8tFWkpF Wa9FW5ArWktr4Utr4DWr1xWr1jyryqk395CryUuF1Ikw1rX3sxJr1rtrWDXFy5GryrAF48 Xw17Xrs8ZFWkCaDanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUU9C14x267AKxVW8JVW5JwAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2ocxC64kIII0Yj41l84x0c7CEw4AK67xGY2AK02 1l84ACjcxK6xIIjxv20xvE14v26w1j6s0DM28EF7xvwVC0I7IYx2IY6xkF7I0E14v26F4U JVW0owA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oV Cq3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0 I7IYx2IY67AKxVWUXVWUAwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r 4UM4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwACI402YVCY1x02628v n2kIc2xKxwCY1x0262kKe7AKxVWUtVW8ZwCY02Avz4vE14v_KwCF04k20xvY0x0EwIxGrw CFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v26r1j6r18MI8I3I0E7480Y4vE 14v26r106r1rMI8E67AF67kF1VAFwI0_Jw0_GFylIxkGc2Ij64vIr41lIxAIcVC0I7IYx2 IY67AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Gr0_Cr1lIxAIcVCF04k26cxK x2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r1j6r4UMIIF0xvEx4A2jsIEc7CjxVAFwI 0_Gr0_Gr1UYxBIdaVFxhVjvjDU0xZFpf9x0JUL4SrUUUUU= X-CM-SenderInfo: qssqjiasttq6lmxovvfxof0/1tbiAwIQAWY7nwoGrwAKs7 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The ax25_addr_ax25dev() and ax25_dev_device_down() exist a reference count leak issue of the object "ax25_dev". Memory leak issue in ax25_addr_ax25dev(): The reference count of the object "ax25_dev" can be increased multiple times in ax25_addr_ax25dev(). This will cause a memory leak. Memory leak issues in ax25_dev_device_down(): The reference count of ax25_dev is set to 1 in ax25_dev_device_up() and then increase the reference count when ax25_dev is added to ax25_dev_list. As a result, the reference count of ax25_dev is 2. But when the device is shutting down. The ax25_dev_device_down() drops the reference count once or twice depending on if we goto unlock_put or not, which will cause memory leak. As for the issue of ax25_addr_ax25dev(), it is impossible for one pointer to be on a list twice. So add a break in ax25_addr_ax25dev(). As for the issue of ax25_dev_device_down(), increase the reference count of ax25_dev once in ax25_dev_device_up() and decrease the reference count of ax25_dev after it is removed from the ax25_dev_list. Fixes: d01ffb9eee4a ("ax25: add refcount in ax25_dev to avoid UAF bugs") Suggested-by: Dan Carpenter Signed-off-by: Duoming Zhou --- net/ax25/ax25_dev.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/net/ax25/ax25_dev.c b/net/ax25/ax25_dev.c index 56b14d240a6..37150f766a0 100644 --- a/net/ax25/ax25_dev.c +++ b/net/ax25/ax25_dev.c @@ -39,6 +39,7 @@ ax25_dev *ax25_addr_ax25dev(ax25_address *addr) if (ax25cmp(addr, (const ax25_address *)ax25_dev->dev->dev_addr) =3D=3D = 0) { res =3D ax25_dev; ax25_dev_hold(ax25_dev); + break; } spin_unlock_bh(&ax25_dev_lock); =20 @@ -91,7 +92,6 @@ void ax25_dev_device_up(struct net_device *dev) list_add(&ax25_dev->list, &ax25_dev_list); dev->ax25_ptr =3D ax25_dev; spin_unlock_bh(&ax25_dev_lock); - ax25_dev_hold(ax25_dev); =20 ax25_register_dev_sysctl(ax25_dev); } @@ -132,7 +132,6 @@ void ax25_dev_device_down(struct net_device *dev) unlock_put: dev->ax25_ptr =3D NULL; spin_unlock_bh(&ax25_dev_lock); - ax25_dev_put(ax25_dev); netdev_put(dev, &ax25_dev->dev_tracker); ax25_dev_put(ax25_dev); } --=20 2.17.1 From nobody Wed Dec 17 03:13:20 2025 Received: from zg8tmtyylji0my4xnjeumjiw.icoremail.net (zg8tmtyylji0my4xnjeumjiw.icoremail.net [162.243.161.220]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B023E13CF83; Thu, 9 May 2024 01:56:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=162.243.161.220 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715219817; cv=none; b=gNZhCAa7F9EfEWYD3VSZ8iec/+agD5igCu8SgOR21z33Te5qaFFaNhpCJ2EfM7UOpGrCdO56uXzomyoLfMw4zrguo38T5SirAmOZ5QWOiLL1qODq9i6a2VVq/LKLa9MWZ6U6Yt6DDt51GBFVE33P0ElTprcNNkDhcRZXjCXe98g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715219817; c=relaxed/simple; bh=Lli1kLaNsVAUfmSU8DR3wNA4Occs19lWcrVhE1EaVvs=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=dghimGXJvMT/yMLQZoiI4LOpERdQONS93D57MpK/ulEJWUevVV5X4pkW3MZPVsW/p0LV2VRpi3NMc1JOgP6FYzJeIOFrZALfPIuGeGEBw7A+iD6B1mUns/d60ynotGB8O7d4weQd/vZuIgbJ/+YIq+XVvpzxe9l2mwftHkjNsnc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=zju.edu.cn; spf=pass smtp.mailfrom=zju.edu.cn; arc=none smtp.client-ip=162.243.161.220 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=zju.edu.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=zju.edu.cn Received: from ubuntu.localdomain (unknown [221.192.180.131]) by mail-app4 (Coremail) with SMTP id cS_KCgDnc7FWLTxmNkpMAA--.45924S2; Thu, 09 May 2024 09:56:40 +0800 (CST) From: Duoming Zhou To: netdev@vger.kernel.org Cc: linux-kernel@vger.kernel.org, linux-hams@vger.kernel.org, pabeni@redhat.com, kuba@kernel.org, edumazet@google.com, davem@davemloft.net, jreuter@yaina.de, dan.carpenter@linaro.org, Duoming Zhou Subject: [PATCH net v6 3/3] ax25: Fix reference count leak issues of net_device Date: Thu, 9 May 2024 09:56:36 +0800 Message-Id: <4890e260622ae06922a838f063d5dfd385931cda.1715219007.git.duoming@zju.edu.cn> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-CM-TRANSID: cS_KCgDnc7FWLTxmNkpMAA--.45924S2 X-Coremail-Antispam: 1UD129KBjvJXoW7WFyxZry8AFy8Gry3XF18Xwb_yoW8JFyrpF W2gFW3ArZ7Jr1DJr4DWr97Wr15Zryq93yrCr15u3WSk3s5X3sxJryrKrWUXry7KrWfZF18 u347Wrs8uF4kZaUanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUU9C14x267AKxVW8JVW5JwAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2ocxC64kIII0Yj41l84x0c7CEw4AK67xGY2AK02 1l84ACjcxK6xIIjxv20xvE14v26w1j6s0DM28EF7xvwVC0I7IYx2IY6xkF7I0E14v26F4U JVW0owA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oV Cq3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0 I7IYx2IY67AKxVWUAVWUtwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r 4UM4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwACI402YVCY1x02628v n2kIc2xKxwCY1x0262kKe7AKxVWUtVW8ZwCY02Avz4vE14v_KwCF04k20xvY0x0EwIxGrw CFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v26r1j6r18MI8I3I0E7480Y4vE 14v26r106r1rMI8E67AF67kF1VAFwI0_Jw0_GFylIxkGc2Ij64vIr41lIxAIcVC0I7IYx2 IY67AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Gr0_Cr1lIxAIcVCF04k26cxK x2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r1j6r4UMIIF0xvEx4A2jsIEc7CjxVAFwI 0_Gr0_Gr1UYxBIdaVFxhVjvjDU0xZFpf9x0JUlYL9UUUUU= X-CM-SenderInfo: qssqjiasttq6lmxovvfxof0/1tbiAwIQAWY7nwoGrwANs8 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The ax25_dev_device_down() exists reference count leak issues of the object "net_device". When the ax25 device is shutting down. The ax25_dev_device_down() drops the reference count of net_device one or zero times depending on if we goto unlock_put or not, which will cause memory leak. In order to solve the above issue, decrease the reference count of net_device after dev->ax25_ptr is set to null. Fixes: d01ffb9eee4a ("ax25: add refcount in ax25_dev to avoid UAF bugs") Suggested-by: Dan Carpenter Signed-off-by: Duoming Zhou --- net/ax25/ax25_dev.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/net/ax25/ax25_dev.c b/net/ax25/ax25_dev.c index 37150f766a0..f37b143d69b 100644 --- a/net/ax25/ax25_dev.c +++ b/net/ax25/ax25_dev.c @@ -121,15 +121,9 @@ void ax25_dev_device_down(struct net_device *dev) list_for_each_entry(s, &ax25_dev_list, list) { if (s =3D=3D ax25_dev) { list_del(&s->list); - goto unlock_put; + break; } } - dev->ax25_ptr =3D NULL; - spin_unlock_bh(&ax25_dev_lock); - ax25_dev_put(ax25_dev); - return; - -unlock_put: dev->ax25_ptr =3D NULL; spin_unlock_bh(&ax25_dev_lock); netdev_put(dev, &ax25_dev->dev_tracker); --=20 2.17.1