From patchwork Fri Jun 18 16:14:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Skripkin X-Patchwork-Id: 463727 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3E059C48BDF for ; Fri, 18 Jun 2021 16:14:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2832761139 for ; Fri, 18 Jun 2021 16:14:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235634AbhFRQQx (ORCPT ); Fri, 18 Jun 2021 12:16:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41084 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235429AbhFRQQq (ORCPT ); Fri, 18 Jun 2021 12:16:46 -0400 Received: from mail-lf1-x12b.google.com (mail-lf1-x12b.google.com [IPv6:2a00:1450:4864:20::12b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AAF0AC061760; Fri, 18 Jun 2021 09:14:35 -0700 (PDT) Received: by mail-lf1-x12b.google.com with SMTP id j2so17559551lfg.9; Fri, 18 Jun 2021 09:14:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=iCNibqVduxNAGNvNvSGxKnoXkViyWCeY8Yq5EDWpyBo=; b=MNcVghv8BjiS2ohbcW8P99fw9nhuAv1NUOyyqKLz0cICZVwHPc4iCXO7x0GEBZvbbT fo/pGytutKhto+A11baqvyBa3LgnB+MK0Yl4ogyLoWQ5xgN9A22Un0fg1mYicz1txphA 6AR5oRl248U5IkPEOHeknPg0GV2dlX0Bx3Jgir+vy7+KJ+CBOlwQ82G6jfu6pdll+uJu k5c28vlyiPtZbuPJtaT/dWrmk7IDxIQGigGmbKiQ+aDhFHw3PrIuolUFPY6mN0+HEKdu nPDkCTiNTSMiIGgTpwTLXkw2uyuSo+J1OU6PSKO9PlGBEGLSFja1OKrJwTog9MyO2C3A VRFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=iCNibqVduxNAGNvNvSGxKnoXkViyWCeY8Yq5EDWpyBo=; b=aUgRWyFRfpsf2ypG2zR21fL5lSDwJoj31WIpAVrQO8Ogn4dIF0YDEe3RILuAYI82M4 g/9WA0xcCAL299b94k4/7xto+Jysb4r7Wh2h89Y5rpJzxe+6dWOEY4CCAXshk6mRD/3E Y6OE/Fax61DeNQTcI5K7yXBPidnliWKFdAUQjqkng8OEyaPiXxl1xLqA9HOrND1IEsjN jUiTCHuFHMA+F7l4asL/SeDrmgt370o3Y9Tk4keCrkWV0n4SAJ7Rf5W9iPb7oTkG1LC0 zXWQhiFx4tS26q07hZeQNAD/a6G6EDguwdIpY7fU3WIDdC1kuibijCvTbA6PkXyGC8ik KZ4A== X-Gm-Message-State: AOAM531zjiHksehrYe4eB6rfrxEiwLK+i6jWXrXEwtaTtxTQoLPVx3gu zWP75IsTCCFJKNSQ0/Omff4= X-Google-Smtp-Source: ABdhPJwC9F7gO/yzdkBKWZXY3kEnos4KgIUY50ScQMqfTt5fgU7x6U7le62lri07CPV+9gLDkKgjBw== X-Received: by 2002:a05:6512:1184:: with SMTP id g4mr3678397lfr.567.1624032874041; Fri, 18 Jun 2021 09:14:34 -0700 (PDT) Received: from localhost.localdomain ([94.103.229.24]) by smtp.gmail.com with ESMTPSA id z16sm951813lfs.24.2021.06.18.09.14.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Jun 2021 09:14:33 -0700 (PDT) From: Pavel Skripkin To: davem@davemloft.net, kuba@kernel.org, andrew@lunn.ch, michael@walle.cc, abrodkin@synopsys.com, talz@ezchip.com, noamc@ezchip.com Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kernel-mentees@lists.linuxfoundation.org, Pavel Skripkin Subject: [PATCH 1/3] net: ethernet: ezchip: fix UAF in nps_enet_remove Date: Fri, 18 Jun 2021 19:14:31 +0300 Message-Id: X-Mailer: git-send-email 2.32.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org priv is netdev private data, but it is used after free_netdev(). It can cause use-after-free when accessing priv pointer. So, fix it by moving free_netdev() after netif_napi_del() call. Fixes: 0dd077093636 ("NET: Add ezchip ethernet driver") Signed-off-by: Pavel Skripkin --- drivers/net/ethernet/ezchip/nps_enet.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/ethernet/ezchip/nps_enet.c b/drivers/net/ethernet/ezchip/nps_enet.c index e3954d8835e7..20d2c2bb26e4 100644 --- a/drivers/net/ethernet/ezchip/nps_enet.c +++ b/drivers/net/ethernet/ezchip/nps_enet.c @@ -642,8 +642,8 @@ static s32 nps_enet_remove(struct platform_device *pdev) struct nps_enet_priv *priv = netdev_priv(ndev); unregister_netdev(ndev); - free_netdev(ndev); netif_napi_del(&priv->napi); + free_netdev(ndev); return 0; } From patchwork Fri Jun 18 16:14:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Skripkin X-Patchwork-Id: 463726 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 68BBDC48BDF for ; Fri, 18 Jun 2021 16:15:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5500761139 for ; Fri, 18 Jun 2021 16:15:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235550AbhFRQRO (ORCPT ); Fri, 18 Jun 2021 12:17:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41172 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235837AbhFRQRD (ORCPT ); Fri, 18 Jun 2021 12:17:03 -0400 Received: from mail-lj1-x22f.google.com (mail-lj1-x22f.google.com [IPv6:2a00:1450:4864:20::22f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 29F12C0617AF; Fri, 18 Jun 2021 09:14:52 -0700 (PDT) Received: by mail-lj1-x22f.google.com with SMTP id d2so14744155ljj.11; Fri, 18 Jun 2021 09:14:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=pmmBYlRHWMosP77C0Ii9Ste9VmkpwQxWPopXChKoX8U=; b=MiWyikh06egv+CM+dP0DpbAtt8nVnjcXBSwZfudsgaHkFKpVWZdO1XgMC8Vfqv87yF kXEDIHkcjUwTI3NI9TFzFxLPuqWp0a0Zizi60a09ip1Fse/VqAclrZd685Gtc+gFfEMh gd8XYo8ZB+Wq7C4e1mB0k53cCnvLWXZHV/hTYCuhPj+j674yehtwuJah9zH3TYCqY/21 jMDkvaf6/wOEd+3cFQRNJsTDAXgeg++xj+y6mj+uzQwo0UttB/pAaStzyqKAgWHYcLHu hZp1buRIco2EGghQKo4zLSdT4HQhOVOxrbCgqGkZ9pcVs6sBUZbQVSlQ0Ys8t5paX6tb JvdQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=pmmBYlRHWMosP77C0Ii9Ste9VmkpwQxWPopXChKoX8U=; b=poCW0ESlWt7tdrWLKmf2rvlExD7SlWa02po/Qi8kXQXzWM7lHjvXj02KaP3qrSD45M ozSK8SfiFCyJ3dOyhErroT9Z3ZKNQWuHdU5JqET63aqMuvmxEObbNCGuyhtUESEz8P4a Uwm2IVMSXeJDAfsnkeoYXGq7yQzVfGBxaYiiWQVYw9MziABOO0Q4PawHZinG0d8yHa25 nuPwPAq3G7xnwnn9HJ1v8V9LuN4BFLAG/bUdanlKgBVQlwK9thAhDIYSuBJcpiAs9sdQ jkJb367HEAn34NEi4erOMPDDrqWjQOfm/jkQdWyvdgjobVKj4Vf9SPvrYERmaH0vzVLF Nhdg== X-Gm-Message-State: AOAM532Gmq55VOITAND5yekRpe0HEKFs/fQUikSzth/h57Tpf5uG7WI3 PP4YfgnH26a7j5g0R/uBo2k= X-Google-Smtp-Source: ABdhPJxfdpCMQB64fi+Tq38fP/1PEKy84mwF7jCmbBdPM+AUz90aStt4Wp6ix1eYPrqW3yEixSjXqg== X-Received: by 2002:a05:651c:201d:: with SMTP id s29mr10262196ljo.258.1624032890195; Fri, 18 Jun 2021 09:14:50 -0700 (PDT) Received: from localhost.localdomain ([94.103.229.24]) by smtp.gmail.com with ESMTPSA id h19sm951025lfc.225.2021.06.18.09.14.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Jun 2021 09:14:49 -0700 (PDT) From: Pavel Skripkin To: davem@davemloft.net, kuba@kernel.org, andrew@lunn.ch, michael@walle.cc, abrodkin@synopsys.com, talz@ezchip.com, noamc@ezchip.com Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kernel-mentees@lists.linuxfoundation.org, Pavel Skripkin Subject: [PATCH 3/3] net: ethernet: ezchip: fix error handling Date: Fri, 18 Jun 2021 19:14:47 +0300 Message-Id: <422b1921ce3ff8f29da93d9a2c99e1d34cf66c77.1624032669.git.paskripkin@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org As documented at drivers/base/platform.c for platform_get_irq: * Gets an IRQ for a platform device and prints an error message if finding the * IRQ fails. Device drivers should check the return value for errors so as to * not pass a negative integer value to the request_irq() APIs. So, the driver should check that platform_get_irq() return value is _negative_, not that it's equal to zero, because -ENXIO (return value from request_irq() if irq was not found) will pass this check and it leads to passing negative irq to request_irq() Fixes: 0dd077093636 ("NET: Add ezchip ethernet driver") Signed-off-by: Pavel Skripkin --- drivers/net/ethernet/ezchip/nps_enet.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/ethernet/ezchip/nps_enet.c b/drivers/net/ethernet/ezchip/nps_enet.c index c562a1e83913..f9a288a6ec8c 100644 --- a/drivers/net/ethernet/ezchip/nps_enet.c +++ b/drivers/net/ethernet/ezchip/nps_enet.c @@ -607,7 +607,7 @@ static s32 nps_enet_probe(struct platform_device *pdev) /* Get IRQ number */ priv->irq = platform_get_irq(pdev, 0); - if (!priv->irq) { + if (priv->irq < 0) { dev_err(dev, "failed to retrieve value from device tree\n"); err = -ENODEV; goto out_netdev;