Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp4027695ioo; Wed, 25 May 2022 13:11:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy+xWCewAF+59iyHaXainyPKoF/U4ot0kFVPs8APw6AjyAUK+wibr6iHZPxwILqMuM5Dvog X-Received: by 2002:a63:8041:0:b0:3fa:dd68:eb9b with SMTP id j62-20020a638041000000b003fadd68eb9bmr4018791pgd.554.1653509513234; Wed, 25 May 2022 13:11:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653509513; cv=none; d=google.com; s=arc-20160816; b=lra5Fo/zlHEEAmqDt3Ph17zQc946zDfjHL1WIZ3r+1QhiFD5hDDKNHBc5/go6rq0ud ogxSv1bP0G9Oc1DUwCMs9m9jiP+9ubVrJejdXpfUrb6kdjmL1ngxkAgbwfc3ZkdNjbRJ 3Fzqou1tEb4Kfxk5hSOyyrFzaJ633DOkpNVSWDSh9AAsOurR51BidLjy/DfQZugDZheY 5LxPrZ3EbrNf4H6YFE/zHeNvtW/ZDkSlBbFWOZ9yeNjMDXQDv/xilEIXdpo8XqWUjLGZ dX12KxWIy7ByJznvMRlLKV5n48GoFRHs3F1NKXUY+/kYliQVyTqu194olTvcYTx0khgT 6/cw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from; bh=GWDGJUMjIz1jQrnI3Z7csdnuPccJRkAO5wU79MYSaMY=; b=AhTV5Vzyk0xCqLWp7n+fpbPhCnPc1EcVt0vW2lDyJXTDtR589QSbAElWxmV83zbwv8 z+C0WSFXNvhZiTepONk5aOKo5fbt6ozNXQy23txwwMjO+xHPzgNL7Jq6+E0v6OugWX8R NyS9JNKAxZNdYKo24V6nN2A8UJeSR9jUT1XBaY93jfJ7GJMX0eDrIf7ZlrpElHtIkvlE 2zKppkCNckx2lzuFqAgG52VIAtOtpASqYyNQKIeKNpWMaaEHLuT0OTaGoI2rtfCu2giF cTN5IXKmB1gJgE8pD0yVsQL5exfMatLSmWlRTPLxl4glNapMD4k0mGOf+ESxU7fFrDmt Xyew== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a191-20020a6390c8000000b003db60740a25si18226698pge.35.2022.05.25.13.11.40; Wed, 25 May 2022 13:11:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242769AbiEYLaD (ORCPT + 99 others); Wed, 25 May 2022 07:30:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49174 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239102AbiEYL3r (ORCPT ); Wed, 25 May 2022 07:29:47 -0400 X-Greylist: delayed 163321 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Wed, 25 May 2022 04:29:44 PDT Received: from azure-sdnproxy-3.icoremail.net (azure-sdnproxy.icoremail.net [20.232.28.96]) by lindbergh.monkeyblade.net (Postfix) with SMTP id 31F479CCB3; Wed, 25 May 2022 04:29:43 -0700 (PDT) Received: from ubuntu.localdomain (unknown [124.236.130.193]) by mail-app4 (Coremail) with SMTP id cS_KCgDn_iHyEo5iQ1u7AA--.41494S2; Wed, 25 May 2022 19:28:58 +0800 (CST) From: Duoming Zhou To: netdev@vger.kernel.org Cc: jreuter@yaina.de, ralf@linux-mips.org, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, linux-kernel@vger.kernel.org, linux-hams@vger.kernel.org, thomas@osterried.de, Duoming Zhou Subject: [PATCH net] ax25: Fix ax25 session cleanup problem in ax25_release Date: Wed, 25 May 2022 19:28:50 +0800 Message-Id: <20220525112850.102363-1-duoming@zju.edu.cn> X-Mailer: git-send-email 2.17.1 X-CM-TRANSID: cS_KCgDn_iHyEo5iQ1u7AA--.41494S2 X-Coremail-Antispam: 1UD129KBjvJXoWxAF4xtw13WFWrXFy8AFyDGFg_yoW5XrWxpF WDKa43trZrXF4UAw48WrZ7XF18uws8t3yDtF1jvFZa9w1fX3s8JFn5tF1jqFW3GFZ5tFn7 u34qgan8Zr1kuFJanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUvC14x267AKxVW8JVW5JwAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2ocxC64kIII0Yj41l84x0c7CEw4AK67xGY2AK02 1l84ACjcxK6xIIjxv20xvE14v26w1j6s0DM28EF7xvwVC0I7IYx2IY6xkF7I0E14v26r4U JVWxJr1l84ACjcxK6I8E87Iv67AKxVW0oVCq3wA2z4x0Y4vEx4A2jsIEc7CjxVAFwI0_Gc CE3s1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAqx4xG64xvF2IEw4CE5I8CrVC2j2WlYx0E 2Ix0cI8IcVAFwI0_Jr0_Jr4lYx0Ex4A2jsIE14v26r1j6r4UMcvjeVCFs4IE7xkEbVWUJV W8JwACjcxG0xvY0x0EwIxGrwACjI8F5VA0II8E6IAqYI8I648v4I1lFIxGxcIEc7CjxVA2 Y2ka0xkIwI1lc2xSY4AK67AK6r4kMxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY6r 1j6r4UMI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17CE b7AF67AKxVWUtVW8ZwCIc40Y0x0EwIxGrwCI42IY6xIIjxv20xvE14v26r1j6r1xMIIF0x vE2Ix0cI8IcVCY1x0267AKxVW8JVWxJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAI cVC2z280aVAFwI0_Jr0_Gr1lIxAIcVC2z280aVCY1x0267AKxVW8JVW8JrUvcSsGvfC2Kf nxnUUI43ZEXa7VUbeT5PUUUUU== X-CM-SenderInfo: qssqjiasttq6lmxovvfxof0/1tbiAgwBAVZdtZ3p6QAKsn X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_PASS, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The timers of ax25 are used for correct session cleanup. If we use ax25_release() to close ax25 sessions and ax25_dev is not null, the del_timer_sync() functions in ax25_release() will execute. As a result, the sessions could not be cleaned up correctly, because the timers have stopped. This patch adds a device_up flag in ax25_dev in order to judge whether the device is up. If there are sessions to be cleaned up, the del_timer_sync() in ax25_release() will not execute. As a result the sessions could be cleaned up correctly. Fixes: 82e31755e55f ("ax25: Fix UAF bugs in ax25 timers") Reported-by: Thomas Osterried Signed-off-by: Duoming Zhou --- include/net/ax25.h | 1 + net/ax25/af_ax25.c | 13 ++++++++----- net/ax25/ax25_dev.c | 1 + 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/include/net/ax25.h b/include/net/ax25.h index 0f9790c455b..a427a05672e 100644 --- a/include/net/ax25.h +++ b/include/net/ax25.h @@ -228,6 +228,7 @@ typedef struct ax25_dev { ax25_dama_info dama; #endif refcount_t refcount; + bool device_up; } ax25_dev; typedef struct ax25_cb { diff --git a/net/ax25/af_ax25.c b/net/ax25/af_ax25.c index 363d47f9453..47ce6b630cc 100644 --- a/net/ax25/af_ax25.c +++ b/net/ax25/af_ax25.c @@ -81,6 +81,7 @@ static void ax25_kill_by_device(struct net_device *dev) if ((ax25_dev = ax25_dev_ax25dev(dev)) == NULL) return; + ax25_dev->device_up = false; spin_lock_bh(&ax25_list_lock); again: @@ -1053,11 +1054,13 @@ static int ax25_release(struct socket *sock) ax25_destroy_socket(ax25); } if (ax25_dev) { - del_timer_sync(&ax25->timer); - del_timer_sync(&ax25->t1timer); - del_timer_sync(&ax25->t2timer); - del_timer_sync(&ax25->t3timer); - del_timer_sync(&ax25->idletimer); + if (!ax25_dev->device_up) { + del_timer_sync(&ax25->timer); + del_timer_sync(&ax25->t1timer); + del_timer_sync(&ax25->t2timer); + del_timer_sync(&ax25->t3timer); + del_timer_sync(&ax25->idletimer); + } dev_put_track(ax25_dev->dev, &ax25_dev->dev_tracker); ax25_dev_put(ax25_dev); } diff --git a/net/ax25/ax25_dev.c b/net/ax25/ax25_dev.c index d2a244e1c26..5451be15e07 100644 --- a/net/ax25/ax25_dev.c +++ b/net/ax25/ax25_dev.c @@ -62,6 +62,7 @@ void ax25_dev_device_up(struct net_device *dev) ax25_dev->dev = dev; dev_hold_track(dev, &ax25_dev->dev_tracker, GFP_ATOMIC); ax25_dev->forward = NULL; + ax25_dev->device_up = true; ax25_dev->values[AX25_VALUES_IPDEFMODE] = AX25_DEF_IPDEFMODE; ax25_dev->values[AX25_VALUES_AXDEFMODE] = AX25_DEF_AXDEFMODE; -- 2.17.1