Received: by 2002:ab2:6991:0:b0:1f7:f6c3:9cb1 with SMTP id v17csp866882lqo; Wed, 8 May 2024 18:57:06 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWcnzrCDJI0uVrpLAi+mbEEafkCK/vpDC6XneQhXWJdrmuMC0nnhJusm3ZaKIx69OvYVbQ5ZFRvqgPgqROF9tOsIPp4/6msqkNS9e1vWQ== X-Google-Smtp-Source: AGHT+IFFixzZlqlphGHPu48zGZbET6JVNsJ8XJjZo2FoxWvtuV7RMSZDFUcetS/QUPqHCnsXINuR X-Received: by 2002:a0c:e705:0:b0:6a0:d671:942 with SMTP id 6a1803df08f44-6a15cbc1133mr19616296d6.4.1715219825784; Wed, 08 May 2024 18:57:05 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715219825; cv=pass; d=google.com; s=arc-20160816; b=IBUTeGevNVBjlOvpxoK8BIoRfIBZ7WdkYxazzHV2PPDKKlg7VCTZXk2aYi2Fv3nXsa kAIE/Jmbxw5YgJKfuuQQXoY2jDspMzmKXVzc6MV3SWI9XcxZE/yZ1ikiOmqh4VhuAkrM S/JZtCl6Vx6yWHzZ6uV0F8mhGimfR46jr3oDDgh3+9zCBi9fw/7IwP8aAcJF4gM07Y/P FGAw0hE7VIlg78MXVcA8693r0qHYuAuKZw6R2OG5c5YLo6f+xdBm3YXwjlc09z6e4e1u sKQxGeJpCDUzOkDbgvl2ur2C4eA5lHgzsSAK0c14t33O+I7iGYr71UnZ4x/h1nsZepNd qM4Q== 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=BneRMGYWLr5WAqkKDViZSCOj6PEF7iZk+M7q3XMqwew=; fh=Y0jZIFV10LRUZc/saxqovYUxHDOIsKFv9Jy0YMCRg54=; b=WmUFYkB3oOT3R8u3SpOlSd+uN2EnnRas1rCMAZlpNoRxgmo+cpuI3oMNkZxGwzhfjZ nMr6Tgp6Zn9cs/2uu5YjulQkFnvaPqxkYxZ++P+KXdGZEVtsHXZJ3ZlR4ETK040Xpicn WFXD8s0TFTMphoE7vH7ijT4bxUy3jD1zFel/6Ao9Kk1x6diKzmQWMgRmmlbINSJffmem LlgTU5IhhzIyFkHKDGkHr7EqHwxLcX7gIVwOWK9GCWTOHzxSIMg2cDxMcjZR4nQ2T3Xb nJmalb9ze8hWrj/ozBxhlfp46Klmf5nnkeish91UA4aVsExdYAlIoK/Aegi6+NPRZTLH iTQQ==; 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-174039-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-174039-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id 6a1803df08f44-6a15f29a924si4340386d6.193.2024.05.08.18.57.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 May 2024 18:57:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-174039-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=zju.edu.cn); spf=pass (google.com: domain of linux-kernel+bounces-174039-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-174039-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 07C171C2114F for ; Thu, 9 May 2024 01:57:05 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 212AE13CA9E; Thu, 9 May 2024 01:56:48 +0000 (UTC) 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: 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) == 0) { res = ax25_dev; ax25_dev_hold(ax25_dev); + break; } spin_unlock_bh(&ax25_dev_lock); @@ -91,7 +92,6 @@ void ax25_dev_device_up(struct net_device *dev) list_add(&ax25_dev->list, &ax25_dev_list); dev->ax25_ptr = ax25_dev; spin_unlock_bh(&ax25_dev_lock); - ax25_dev_hold(ax25_dev); ax25_register_dev_sysctl(ax25_dev); } @@ -132,7 +132,6 @@ void ax25_dev_device_down(struct net_device *dev) unlock_put: dev->ax25_ptr = NULL; spin_unlock_bh(&ax25_dev_lock); - ax25_dev_put(ax25_dev); netdev_put(dev, &ax25_dev->dev_tracker); ax25_dev_put(ax25_dev); } -- 2.17.1