Received: by 2002:a89:288:0:b0:1f7:eeee:6653 with SMTP id j8csp315870lqh; Mon, 6 May 2024 22:53:22 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXqVgCTgFDdppK/kshvK3Ie4FztM1fkgvEbgibfakhquErd5oTepEqQGdKabdl3w31ogSpvcBj/8GpJAs3m+mgv30H6L+Ddp+7mJwP9vw== X-Google-Smtp-Source: AGHT+IHvT8t9egPe3/pGMCHHRfMZ8n5cn7WioMqA5biDkr25AhP5M6aoKIS3KDwXSVwdikHY8ivo X-Received: by 2002:a05:622a:1819:b0:43a:ea03:31b6 with SMTP id t25-20020a05622a181900b0043aea0331b6mr13291456qtc.31.1715061202511; Mon, 06 May 2024 22:53:22 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715061202; cv=pass; d=google.com; s=arc-20160816; b=wzkhcOhs7aicAMxPDhNWIuDW+GPUgaKCrj6uWy+SbjEt3ZlyoTSLe/txXvzEzdwVB3 ATnLj8Qb+F/tR8jlSLm0SlYV4MrNZNQbtX6NSrC6KMAYy6tlhdLqBKuhRqn50iR2G9Fj j766SXH1HQ8VuFKmaFaO1vCZh5V3sWfKrLFqLsnXn3zgJgi/iLVw1ILBAW49m5EnFZco 0PKTmJ5NiwRjCLp+upvJEqcbwarSVvxUvIHZ/ISOfNvaz0UL9YKEZFZ7qWA1fREeeZuI dTULw6h213qc1/elJ+tF4BB5d2B1TfGkn2EJ/Y6rb3gu/kmxKTK2Uf0znvaUBevRkQxY kMqA== 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=7xv0LFSOBz1KFh6BmFo3orYoFd4Lz053pacO1qnNnX8=; fh=IE3AZvDm9DC3cdTbYv1PuJ+zr4mdKz6MWG85KR/OiZ4=; b=AOFRj8tpFdB3uNqiwoP3kY4euHZAKHcd8jfj7MyXpRbUAwZgAiY45jar5OShqMI1h5 IAJ4dR09pE3xh9Z0bwD95+Cb6fC+sHs4Cq5pnpjHjIOmsX/DH4PXtij8JVsWtjf0Z/lD A9LEqo4n9VKmEdfKx+gIxDz4+t92d8eiqahbb6AkjX9YcXJZiLX2849iAbhzrKe+FGbL LjHkzZMFHHGQcfVmSbWeoO5vTp4oCJdVgEzFzM7t6ARYckQsqTVQJyGgGlc9/GKZcVPH kwdC22Ls2iE9CLnPG1JtW+atPiTi679bX9bDeOWHPTFZrv7uMoKVNWGJaRaRYB+gnCPp 0E0Q==; 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-170709-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-170709-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 h3-20020ac87d43000000b0043af58e3f2esi11068160qtb.230.2024.05.06.22.53.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 May 2024 22:53:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-170709-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-170709-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-170709-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 4140B1C21581 for ; Tue, 7 May 2024 05:53:22 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 05C6B6D1D2; Tue, 7 May 2024 05:53:08 +0000 (UTC) Received: from azure-sdnproxy.icoremail.net (azure-sdnproxy.icoremail.net [52.237.72.81]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 76CCD6BFA9; Tue, 7 May 2024 05:53:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=52.237.72.81 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715061187; cv=none; b=FnrrixnJiKVs2ezFvKpWhDpGcUc7oo5DZR8UGvf4Gv/ekaaSekwSeFbHcF5U3HBXD76vlX/NF0kdhSSebmIFeokE+alNg2uZY+v3pOZQbxd6/mFKyo3Gryaqk76tQdMxoohtqurMt1/WEoQHSuTvBBGkYvBqWrur9Xe7HfbowBM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715061187; c=relaxed/simple; bh=5eM5W6ze1j1mLPSQUbYA7MyvceG+JiOuYyGAGTYb/88=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=tB0gQIsoPYJtLptoigjZqx+X8Qik6GF1y9+ifdGvGzinVCxiVwYwA2I8dkZmRBEfeDd4lc7RfMjUAT3GAlmm1ExWxDNIzv0RvPjFkIkjGOO/2tZgnVElIrrqyOhxjNNucVIHGLKC3Gx50y+gJ3fb5M4TX6bVq7A7hdyyL+XbWyI= 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=52.237.72.81 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.179.90]) by mail-app2 (Coremail) with SMTP id by_KCgA356arwTlmxjNDAA--.29804S2; Tue, 07 May 2024 13:52:46 +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, horms@kernel.org, Markus.Elfring@web.de, dan.carpenter@linaro.org, lars@oddbit.com, Duoming Zhou Subject: [PATCH net v4 3/4] ax25: Fix reference count leak issues of net_device Date: Tue, 7 May 2024 13:52:43 +0800 Message-Id: <02697d01b0d95859a9caf45f6b37af2d2b9959d8.1715059894.git.duoming@zju.edu.cn> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-CM-TRANSID:by_KCgA356arwTlmxjNDAA--.29804S2 X-Coremail-Antispam: 1UD129KBjvJXoW7WFyxZry8AFy8Gry3XF18Xwb_yoW8GrWUpF W2gFW3ArZ7Jr1DGr4DWr97Wr10vryq93yrur15u3WIk3s5X3sxJryrKrWDXry7KrW3ZF18 u347Wrs5uF1kZaDanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUU9E14x267AKxVW8JVW5JwAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2ocxC64kIII0Yj41l84x0c7CEw4AK67xGY2AK02 1l84ACjcxK6xIIjxv20xvE14v26w1j6s0DM28EF7xvwVC0I7IYx2IY6xkF7I0E14v26F4U JVW0owA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oV Cq3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0 I7IYx2IY67AKxVWUXVWUAwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r 4UM4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwACI402YVCY1x02628v n2kIc2xKxwCY1x0262kKe7AKxVWUtVW8ZwCY02Avz4vE14v_GrWl42xK82IYc2Ij64vIr4 1l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK 67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r1q6r43MIIYrxkI7VAKI48JMIIF0xvE2Ix0cI 8IcVAFwI0_Jr0_JF4lIxAIcVC0I7IYx2IY6xkF7I0E14v26F4j6r4UJwCI42IY6xAIw20E Y4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Jr0_Gr1lIxAIcVC2z280aVCY1x0267 AKxVW8JVW8JrUvcSsGvfC2KfnxnUUI43ZEXa7VUbQJ57UUUUU== X-CM-SenderInfo: qssqjiasttq6lmxovvfxof0/1tbiAwMOAWY4-AkEPQBBsc 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 --- Changes in v4: - Make the fix procedure of net_device as a separate update steps. 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 6a572fe1046..05e556cdc2b 100644 --- a/net/ax25/ax25_dev.c +++ b/net/ax25/ax25_dev.c @@ -120,15 +120,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