From patchwork Tue Jun 21 19:09:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thadeu Lima de Souza Cascardo X-Patchwork-Id: 1646180 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.a=rsa-sha256 header.s=20210705 header.b=uXXtIVSU; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LSGLS1f0Fz9sG2 for ; Wed, 22 Jun 2022 05:10:24 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1o3jGU-0003y7-UO; Tue, 21 Jun 2022 19:10:18 +0000 Received: from smtp-relay-canonical-0.internal ([10.131.114.83] helo=smtp-relay-canonical-0.canonical.com) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1o3jGT-0003xZ-NI for kernel-team@lists.ubuntu.com; Tue, 21 Jun 2022 19:10:17 +0000 Received: from localhost.localdomain (1.general.cascardo.us.vpn [10.172.70.58]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-canonical-0.canonical.com (Postfix) with ESMTPSA id 11F163F1AD for ; Tue, 21 Jun 2022 19:10:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1655838615; bh=zp5NSvyYNvHWfRfWJqnDkhSQ7PQH70jMsJVF97wSO7I=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=uXXtIVSUap2qd57WsyFaBsENeBvwuLnsduI8DeXUQzF5RjHAZDj5GEvGzZBHjuBIc QShoRsiqv2fO9Vde5CyfoxHJi9tpLIkU9FqQQQA9AdvK0lpazIbLGPAGAzo8A/idXA 1s5JmPEepmLhcy3d/8k6Dq0xy4RnwEn/BwRjb0RLir6EqjbummRiFRvYu3evt2TG2m kK6dm2t4uv335jUvNHeVoPkU3VMFiLn1kvpJwoUiPJWBOo+kqknZw2idRmlWZaiD6b wY6njCyw/1m+f42Mxce0QXGncBGYvjYoir9Bjoq8h75zp/dPTDCKK1UcRuk7/cYlfR Qh847BsX8KpRg== From: Thadeu Lima de Souza Cascardo To: kernel-team@lists.ubuntu.com Subject: [SRU Impish 1/2] netdevice: add the case if dev is NULL Date: Tue, 21 Jun 2022 16:09:11 -0300 Message-Id: <20220621190912.355417-2-cascardo@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220621190912.355417-1-cascardo@canonical.com> References: <20220621190912.355417-1-cascardo@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Yajun Deng Add the case if dev is NULL in dev_{put, hold}, so the caller doesn't need to care whether dev is NULL or not. Signed-off-by: Yajun Deng Signed-off-by: David S. Miller (cherry picked from commit b37a466837393af72fe8bcb8f1436410f3f173f3) CVE-2022-28356 Signed-off-by: Thadeu Lima de Souza Cascardo --- include/linux/netdevice.h | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index 12852a2d4fa3..34fcd1c67a30 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -4141,11 +4141,13 @@ void netdev_run_todo(void); */ static inline void dev_put(struct net_device *dev) { + if (dev) { #ifdef CONFIG_PCPU_DEV_REFCNT - this_cpu_dec(*dev->pcpu_refcnt); + this_cpu_dec(*dev->pcpu_refcnt); #else - refcount_dec(&dev->dev_refcnt); + refcount_dec(&dev->dev_refcnt); #endif + } } /** @@ -4156,11 +4158,13 @@ static inline void dev_put(struct net_device *dev) */ static inline void dev_hold(struct net_device *dev) { + if (dev) { #ifdef CONFIG_PCPU_DEV_REFCNT - this_cpu_inc(*dev->pcpu_refcnt); + this_cpu_inc(*dev->pcpu_refcnt); #else - refcount_inc(&dev->dev_refcnt); + refcount_inc(&dev->dev_refcnt); #endif + } } /* Carrier loss detection, dial on demand. The functions netif_carrier_on