Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp3368000lqp; Tue, 26 Mar 2024 07:26:22 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXkiK+U6zm5FihDGqAPRrPgeMkfR26C+wUVQ+liRja17Aho7PpI5Krp1oltlUYVP3oPjIPiHaI7N4XwBM2eahlk0aL/y6i8Bn7KcRW7LQ== X-Google-Smtp-Source: AGHT+IFAEw6V3DZGmXLKFuAhUd3t1fbJtiwu5SG4aXLywY7EPJ4CNJk9A9AOUnZiYnBu4GM1m44P X-Received: by 2002:a05:6a20:3d0f:b0:1a3:466d:d33 with SMTP id y15-20020a056a203d0f00b001a3466d0d33mr1432347pzi.9.1711463182059; Tue, 26 Mar 2024 07:26:22 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711463182; cv=pass; d=google.com; s=arc-20160816; b=AmSI6kR+v03dixVZ55vXMt5WXHfHyhO8/AIGJkzvaFxbnqeXopNVnfWrTM/uV3enyS YSu7mC62mRF1tT4jiXICcCfwq7FhvG4U8BKhyj/JyPZ7i9Pgp8MiWXXN7c1L1NQ5uQYF zugjLr2gOjiShJXfGQWaOY1CWibeyPAk0tHnKDGn/IEdN219llfm6diR2q7S0JK6OXKz 5YdKBz07+fEkPuoKblEQ6JMLVOzX1vLPlZDVvHh3sYALWWHnVysps8YH6TDWxoz1ksUJ ttLCxGUwatKk/qyzlGgY/ACS3KmzkE6BnU3vDnRQqgO83S2KZYOGi6W3PpwGOs2tMfb8 KogQ== 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:message-id:date :subject:cc:to:from; bh=4zvcaxlMZ8CkrdQ69J4HigskZP2XUOmAaGZ/A1MOGYI=; fh=iqsD5FM48VTOPuxEGig89CQ2GhIb90OBfTf1imws6OU=; b=cHaYlDttif3IY8VEZqB6O6USxl3R78AyZAPFW7PCdMtSpcTv3UMvuseEWM7IK3GiFw SS6fdZVDLxx5el/pIWg7Jtls+rj1XoAVdRD5zdWQKYockYwcbLa2Slz+LjZF+3JhpuAo /HXp3LRxk0y/2HAQS8f1AdQbp7Wu21zrmJdgFMYan3a9psweCOwse11GTsCQ7AJhdHWv AkMzfO3d1xa+jqTRXwOgeCH7F8V0YHVyzRVAgGl0EcSdAv/Llbjqt24bIx8zgSaAuFLD 3F3N0OP1kgLpmmQ7eKSCND7VN+a8BljT0KiQo4RwA8AFWdu1EdT/Przy2VjAb/LHo8qa yYVw==; 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-119170-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-119170-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id bm5-20020a056a00320500b006e6bcbccd85si7203924pfb.22.2024.03.26.07.26.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Mar 2024 07:26:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-119170-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=zju.edu.cn); spf=pass (google.com: domain of linux-kernel+bounces-119170-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-119170-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id B8AF030109E for ; Tue, 26 Mar 2024 14:26:21 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 29A7C12DD90; Tue, 26 Mar 2024 14:26:12 +0000 (UTC) Received: from zg8tmja2lje4os43os4xodqa.icoremail.net (zg8tmja2lje4os43os4xodqa.icoremail.net [206.189.79.184]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4F34F20DF7; Tue, 26 Mar 2024 14:26:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=206.189.79.184 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711463171; cv=none; b=OY0GwwCRemAoJLkhUYt6U2OWGQRKn2p9CQ95yGFuzKvgD6r+hBlInRH0DUpepgeJhKJp/VJJLiGyT8u96xxDmquVDz9TutyX9VQ9er+p7hCFBn6q5r3Ty2fiEgiHGpNx+Ejxc9hKnAgo0igJspJauyRMTavbUjoqxUwq9EB1Nuo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711463171; c=relaxed/simple; bh=OC7tCvTydfv2WFPYMhnm6Kce8VRGXQdO45oszdOLx2w=; h=From:To:Cc:Subject:Date:Message-Id; b=R91NulUY6xNDLEUI/teb7v71jErr7BLSD9xau8X82lvpMIaC4TQwwfeYo8Qy9WroD11d0yYnOJSrjps63rjU6dkukK/ZLAOMyoOpiyQknE4V3Kh9CTMVoLFatfnr88hdfjYOWpT5hc1G7mpG1uTSgTSJCZDEydQjmp+PKYRbXKk= 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=206.189.79.184 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 [218.12.18.99]) by mail-app4 (Coremail) with SMTP id cS_KCgDXi8Dm2gJmIc5YAQ--.22282S2; Tue, 26 Mar 2024 22:25:52 +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, Duoming Zhou Subject: [PATCH net] ax25: fix use-after-free bugs caused by ax25_ds_del_timer Date: Tue, 26 Mar 2024 22:25:42 +0800 Message-Id: <20240326142542.118058-1-duoming@zju.edu.cn> X-Mailer: git-send-email 2.17.1 X-CM-TRANSID:cS_KCgDXi8Dm2gJmIc5YAQ--.22282S2 X-Coremail-Antispam: 1UD129KBjvJXoW7uFy7GF45tw47JFyxJr13Jwb_yoW8JF4kpF WqgF43AF97AryqyF48WF1kWryUAFy8Z3yDCFy7ua1Ikwn3X3Z8JF1DK3yIqFW7GFZ5Arn7 Cw10qr45uFn5CFUanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUvm14x267AKxVW8JVW5JwAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2ocxC64kIII0Yj41l84x0c7CEw4AK67xGY2AK02 1l84ACjcxK6xIIjxv20xvE14v26w1j6s0DM28EF7xvwVC0I7IYx2IY6xkF7I0E14v26r4U JVWxJr1l84ACjcxK6I8E87Iv67AKxVW0oVCq3wA2z4x0Y4vEx4A2jsIEc7CjxVAFwI0_Gc CE3s1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAqx4xG64xvF2IEw4CE5I8CrVC2j2WlYx0E 2Ix0cI8IcVAFwI0_JrI_JrylYx0Ex4A2jsIE14v26r1j6r4UMcvjeVCFs4IE7xkEbVWUJV W8JwACjcxG0xvY0x0EwIxGrwACjI8F5VA0II8E6IAqYI8I648v4I1lc7CjxVAaw2AFwI0_ Jw0_GFylc2xSY4AK67AK6ry5MxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY6r1j6r 4UMI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17CEb7AF 67AKxVWUtVW8ZwCIc40Y0x0EwIxGrwCI42IY6xIIjxv20xvE14v26r1j6r1xMIIF0xvE2I x0cI8IcVCY1x0267AKxVWUJVW8JwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2 z280aVAFwI0_Jr0_Gr1lIxAIcVC2z280aVCY1x0267AKxVW8JVW8JrUvcSsGvfC2KfnxnU UI43ZEXa7VU1OtxDUUUUU== X-CM-SenderInfo: qssqjiasttq6lmxovvfxof0/1tbiAwUMAWYBgRkWjQBPsg Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: When the ax25 device is detaching, the ax25_dev_device_down() calls ax25_ds_del_timer() to cleanup the slave_timer. When the timer handler is running, the ax25_ds_del_timer() that calls del_timer() in it will return directly. As a result, the use-after-free bugs could happen, one of the scenarios is shown below: (Thread 1) | (Thread 2) | ax25_ds_timeout() ax25_dev_device_down() | ax25_ds_del_timer() | del_timer() | ax25_dev_put() //FREE | | ax25_dev-> //USE In order to mitigate bugs, when the device is detaching, use timer_shutdown_sync() to stop the timer. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Signed-off-by: Duoming Zhou --- net/ax25/ax25_ds_timer.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/net/ax25/ax25_ds_timer.c b/net/ax25/ax25_ds_timer.c index c4f8adbf814..5624c0d174c 100644 --- a/net/ax25/ax25_ds_timer.c +++ b/net/ax25/ax25_ds_timer.c @@ -43,7 +43,12 @@ void ax25_ds_setup_timer(ax25_dev *ax25_dev) void ax25_ds_del_timer(ax25_dev *ax25_dev) { - if (ax25_dev) + if (!ax25_dev) + return; + + if (!ax25_dev->device_up) + timer_shutdown_sync(&ax25_dev->dama.slave_timer); + else del_timer(&ax25_dev->dama.slave_timer); } -- 2.17.1