From patchwork Sat Mar 11 18:06:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zheng Wang X-Patchwork-Id: 68166 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp395391wrd; Sat, 11 Mar 2023 10:22:09 -0800 (PST) X-Google-Smtp-Source: AK7set/btu1ia//kFXXxnqIb7Bjwqx0GJ1NWuJCpcuOzM/Xz5VEGoi9jBUdILcIDj8tAqZuKIxjH X-Received: by 2002:a05:6a20:4c88:b0:cc:786d:2128 with SMTP id fq8-20020a056a204c8800b000cc786d2128mr23821348pzb.53.1678558929108; Sat, 11 Mar 2023 10:22:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678558929; cv=none; d=google.com; s=arc-20160816; b=er35R1/2h3FLu3MKTWjzU3pb0Ng7PFKPCR+9rkTEgp9KN4gayvXXU9k4bJ0k7tmu7X CMDFtDF5Qg76fiD4qz+v4ubHxbwXYkmnS53BUfWM4Toi7sPAHW6gYJrVbSYSKuLltS9e p+3uJxCI3e5Q0zs+3OCvfeQKDIpJ/CH6zr58paZqm8pHDaeEL1FuBjO65SVUz296JkTa kCn7YadOtSpL7WGlQmOL2TfFdhVB2M+aoa54+KB/d9R6Tmte4nNyg6GgzxX9pSb3FQS3 f4fZoVjdnpmhv2znyZa+pc+iopP2IeJ6zTAOOjuBasU6AWrhGGsof65FEzHmaSq888Te FkLw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=YXELYQhkSMhCKRXhZ5fp5y3ZjId2tVim6Q6kYlCoa7M=; b=Iy65Qk2deTn3a2OJ6fGrzE81TwFqPRsgq72au3qrIpeC1P4iXQU6rUy9MJhXrPprma Vv/XDQLUame9I5HUA6EOPCqsz6ZRgwO1OhWv2sR+zU6VnyptQI3szmDaESYfEblLrn/x MhGDpKqcCdTvzieP3nMbUSrnNJwCra9YeSZYEX0lncp7vFMG3nunMCfcyvhvK1H2Ccy/ 1w7VBxCjaI/lTCyIPp/ii9Hhdm8hjKNyv/CpllYmmWgkuUquotPbP3wZ3zIq2ZrA2f/j 5HTv2wynzjsb8xefvIMHwdjgOSVmsFlk4Zkf0oHhK3tosqmAnGLyjKC2wa9P0XZG6Jjs L/zg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b=Zq6+HtY+; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=163.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u11-20020a6540cb000000b005089640a405si1903401pgp.752.2023.03.11.10.21.56; Sat, 11 Mar 2023 10:22:09 -0800 (PST) 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; dkim=pass header.i=@163.com header.s=s110527 header.b=Zq6+HtY+; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=163.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230363AbjCKSHS (ORCPT + 99 others); Sat, 11 Mar 2023 13:07:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38966 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230344AbjCKSHQ (ORCPT ); Sat, 11 Mar 2023 13:07:16 -0500 Received: from m12.mail.163.com (m12.mail.163.com [220.181.12.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id A963D6A422; Sat, 11 Mar 2023 10:07:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id:MIME-Version; bh=YXELY QhkSMhCKRXhZ5fp5y3ZjId2tVim6Q6kYlCoa7M=; b=Zq6+HtY+LKoMdn8gyJH66 PvNEjR9Rx9i+ik6raQMpODircupWNMoJcHjMUzGc18bMIiakzTpOLOnVZkWhXOYR 2wRHklABN0Vp6044UY3yAOo7srmwIE+Ybn3zKniz7nNnISAxP7E4j8HPMYuXQRR4 AslrjmnRNuslB/MbcdzZRc= Received: from leanderwang-LC2.localdomain (unknown [111.206.145.21]) by zwqz-smtp-mta-g0-0 (Coremail) with SMTP id _____wDnwxQowwxk9fcHDA--.22999S2; Sun, 12 Mar 2023 02:06:32 +0800 (CST) From: Zheng Wang To: s.shtylyov@omp.ru Cc: davem@davemloft.net, linyunsheng@huawei.com, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, hackerzheng666@gmail.com, 1395428693sheep@gmail.com, alex000young@gmail.com, Zheng Wang Subject: [PATCH net v3] net: ravb: Fix possible UAF bug in ravb_remove Date: Sun, 12 Mar 2023 02:06:30 +0800 Message-Id: <20230311180630.4011201-1-zyytlz.wz@163.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-CM-TRANSID: _____wDnwxQowwxk9fcHDA--.22999S2 X-Coremail-Antispam: 1Uf129KBjvJXoW7CF1DZF1Dur1Uur45AFyUtrb_yoW8Gr1Dp3 9xKa4fuws5Jr1UWa1xGws7ZFWrG3WUKrnIgFWxAw4FvasayF1DXr1FgFW0yw1UJrWkta4a vrWjvw1xu3WDAa7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0pEZ2adUUUUU= X-Originating-IP: [111.206.145.21] X-CM-SenderInfo: h2113zf2oz6qqrwthudrp/1tbiXQgvU1WBo4EEqwAAsw X-Spam-Status: No, score=-0.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_VALIDITY_RPBL,SPF_HELO_NONE,SPF_PASS autolearn=no 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760096467928191274?= X-GMAIL-MSGID: =?utf-8?q?1760096607557863763?= In ravb_probe, priv->work was bound with ravb_tx_timeout_work. If timeout occurs, it will start the work. And if we call ravb_remove without finishing the work, there may be a use-after-free bug on ndev. Fix it by finishing the job before cleanup in ravb_remove. Fixes: c156633f1353 ("Renesas Ethernet AVB driver proper") Signed-off-by: Zheng Wang Reviewed-by: Sergey Shtylyov --- v3: - fix typo in commit message v2: - stop dev_watchdog so that handle no more timeout work suggested by Yunsheng Lin, add an empty line to make code clear suggested by Sergey Shtylyov --- drivers/net/ethernet/renesas/ravb_main.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/net/ethernet/renesas/ravb_main.c b/drivers/net/ethernet/renesas/ravb_main.c index 0f54849a3823..eb63ea788e19 100644 --- a/drivers/net/ethernet/renesas/ravb_main.c +++ b/drivers/net/ethernet/renesas/ravb_main.c @@ -2892,6 +2892,10 @@ static int ravb_remove(struct platform_device *pdev) struct ravb_private *priv = netdev_priv(ndev); const struct ravb_hw_info *info = priv->info; + netif_carrier_off(ndev); + netif_tx_disable(ndev); + cancel_work_sync(&priv->work); + /* Stop PTP Clock driver */ if (info->ccc_gac) ravb_ptp_stop(ndev);