Received: by 2002:ab2:6991:0:b0:1f7:f6c3:9cb1 with SMTP id v17csp867576lqo; Wed, 8 May 2024 18:59:30 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXotfZY5l3K5imo9q/t0YxKa2D28sB0P0NmB5/C6Ho7SRLTOs4esumL16m3O2N4QyH+XVbDqSivnL/AogOgRo+maSoCRQSoOAgOU0XcCg== X-Google-Smtp-Source: AGHT+IHoSEtMu0yfSSzPmZiTLvfpL9sVX7rL9XyoPgKCaKqMM3CR7tpIvQTcJRGpc9YlKxLB1xID X-Received: by 2002:a05:6a20:12d0:b0:1ac:f796:963c with SMTP id adf61e73a8af0-1afc8dc867dmr5374632637.56.1715219970455; Wed, 08 May 2024 18:59:30 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715219970; cv=pass; d=google.com; s=arc-20160816; b=S/dRW0laMPr/dnGkENFoUNhQ3yXBcVj6cIwxvjyMwx7sODu481/UGZdpckZzKhseC8 ywS37WAbN35ma37LsqT1TIOO0ogO4BTcpJhoYypYfo630nzILBIr/uYVkq2Mnyq3eFf5 OTU5dsfNsKyK6pHQQDEwxbG3+YBPaJXtL4fOLxtUKf7VWPIz+PcFO48QfMHVDV8v46bj rJV/3loKk8+Lvg/00+HC+Vth40KdFnnDoc/re6iq0eI2OosH7tNdYbIAG32/B7UG9jDl ChtPY0NHrDeT9qXeEQTvBesauNUTCdTBUVy+iZYR86ljJOkpr46jKcowDByq3Q4ecWLc nXPA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-subscribe:list-id:precedence:references :in-reply-to:message-id:date:subject:cc:to:from; bh=EZshpE/pNK29OaMci0FT36jgft1gw/XF0tYMOh69f9c=; fh=Y0jZIFV10LRUZc/saxqovYUxHDOIsKFv9Jy0YMCRg54=; b=JdfNG3A4TDG/vkbByhbg8W+KzZcTdIZ6MMOYFmS6w/bOgjri45wMQPt1BWRDH8a6e2 yCV52uY2u5wKs5hZc80enASEe8XHeArpMQnGam3CNt25PRu6ysgCZlsvOnxvS/M2CjUa GBHNfy4aMmaItx3oR10B0+0istEeDL6j+GxvVGWuCY65o0Sb/7o3urchcrHdhS9mYhDf 9tYV/Pr93BjvM5+2RnMxkSige2wrPsOboGnbhxiXT/o9VXOvySsE2MNoB3eA+11SCe8U TPtcdumeJ8VvSAwAVNlWEfNA0dS6faXQ/Uk68ib0F5fibYPflwYsfvQUx4Zm8c6SN9zv l3qQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=zju.edu.cn); spf=pass (google.com: domain of linux-kernel+bounces-174040-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-174040-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id d2e1a72fcca58-6f4d2b1db55si430989b3a.269.2024.05.08.18.59.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 May 2024 18:59:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-174040-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=zju.edu.cn); spf=pass (google.com: domain of linux-kernel+bounces-174040-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-174040-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 84D92B225AC for ; Thu, 9 May 2024 01:57:23 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7BDF313CAA9; Thu, 9 May 2024 01:56:57 +0000 (UTC) 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: 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 == ax25_dev) { list_del(&s->list); - goto unlock_put; + break; } } - dev->ax25_ptr = NULL; - spin_unlock_bh(&ax25_dev_lock); - ax25_dev_put(ax25_dev); - return; - -unlock_put: dev->ax25_ptr = NULL; spin_unlock_bh(&ax25_dev_lock); netdev_put(dev, &ax25_dev->dev_tracker); -- 2.17.1