From patchwork Mon Sep 27 03:34:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: MichelleJin X-Patchwork-Id: 12519051 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1E3CFC433F5 for ; Mon, 27 Sep 2021 03:35:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 04DEC60E52 for ; Mon, 27 Sep 2021 03:35:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232557AbhI0Dgw (ORCPT ); Sun, 26 Sep 2021 23:36:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50350 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231892AbhI0Dgv (ORCPT ); Sun, 26 Sep 2021 23:36:51 -0400 Received: from mail-pj1-x102c.google.com (mail-pj1-x102c.google.com [IPv6:2607:f8b0:4864:20::102c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3BA8BC061575; Sun, 26 Sep 2021 20:35:14 -0700 (PDT) Received: by mail-pj1-x102c.google.com with SMTP id k23so11467466pji.0; Sun, 26 Sep 2021 20:35:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=m5WZR48joH/DWIfUQt3Hj/snlovzm3leyn1lmRhg9Lw=; b=dFTPmmsXNA/a6MEeNigL/5ywUT5tdtMx+y1xbDJoryTtV7kexubc+zCL84/XjCm4u/ DQyB2ALmI2GvQSAfp9NQzsawiPMi+JI6/PUGV/YcT4zb7VR3GeKbxhIbMNR88IOBNCha JMvXp6eKW8eOoF0M/xANxOh67IFtE8QgLjg/GZx4rc+1+cy0uJ6DQnbv57agYQVqW0dE lnj/vKeIRedjQdHFkHKxat0WdjUUQ6wcctjETycumsgHrxTdpWbw1ZxfQ8+UA9e44ujK Dc55ycm+CLyFOHleTNhwiqWWV9TkWUV9jOAhshbz2xW5la2onp4OAOkb9ILEDXre2r2c PiCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=m5WZR48joH/DWIfUQt3Hj/snlovzm3leyn1lmRhg9Lw=; b=NV6pQI8emlBCOBi7RG1yLInvlYf9SqGoggMIbWfAtbqZt2v87WcNIbLrCeauo8DFEo 9ZrtsdKCxOamKPC7vqi5lTplIoO2dMVIPK0loJy14dXdYRnxldsEwV8Aqd1+NZYiYmW2 P/Ep+r8aJwCZDqTxVmBSWpklfoQ+9G2gCaqGqEPdhw2uRahlpRAgd5xjKUME/qDW41eK tgk23neYfO2TPN2I4/++NdCaMQCjrw7fIAsKD77jpbdePaZFMfFBGKliMuVBNpGxnCCO +VicGKbgfZjrD8Nl9J5ajCtTixBw6aIQG4HKXK5EP+PoyO8HTGaMGo1M/6e5ov9fQc5o 0yog== X-Gm-Message-State: AOAM533oAAP+xatL6BAHOCODqMWUpxQaiVkaS/eN2+hirvnazOp/RYPF TXhPmG/sRTVQ48wqWd3KcmboejsQN2CC/DoZ X-Google-Smtp-Source: ABdhPJzbYff7CI1vCp8skAgZ2uT+hAYeyl8COT3SM9aXHaTe6Wt5be8QriWyZwCovv7bAqJapbbtLw== X-Received: by 2002:a17:90a:ba14:: with SMTP id s20mr17492220pjr.20.1632713713597; Sun, 26 Sep 2021 20:35:13 -0700 (PDT) Received: from localhost.localdomain ([210.99.160.97]) by smtp.googlemail.com with ESMTPSA id r206sm1404320pfc.218.2021.09.26.20.35.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 Sep 2021 20:35:13 -0700 (PDT) From: MichelleJin To: davem@davemloft.net, kuba@kernel.org, yoshfuji@linux-ipv6.org, dsahern@kernel.org, johannes@sipsolutions.net Cc: saeedm@nvidia.com, leon@kernel.org, roid@nvidia.com, paulb@nvidia.com, ozsh@nvidia.com, lariel@nvidia.com, cmi@nvidia.com, netdev@vger.kernel.org, linux-rdma@vger.kernel.org, linux-wireless@vger.kernel.org Subject: [PATCH net-next v4 1/3] net/mlx5e: check return value of rhashtable_init Date: Mon, 27 Sep 2021 03:34:55 +0000 Message-Id: <20210927033457.1020967-2-shjy180909@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210927033457.1020967-1-shjy180909@gmail.com> References: <20210927033457.1020967-1-shjy180909@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org When rhashtable_init() fails, it returns -EINVAL. However, since error return value of rhashtable_init is not checked, it can cause use of uninitialized pointers. So, fix unhandled errors of rhashtable_init. Signed-off-by: MichelleJin Reviewed-by: Roi Dayan --- v1->v2: - change commit message - fix unneeded destroying of ht v2->v3: - nothing changed v3->v4: - nothing changed drivers/net/ethernet/mellanox/mlx5/core/en/tc_ct.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/tc_ct.c b/drivers/net/ethernet/mellanox/mlx5/core/en/tc_ct.c index 6c949abcd2e1..225748a9e52a 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en/tc_ct.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en/tc_ct.c @@ -2127,12 +2127,20 @@ mlx5_tc_ct_init(struct mlx5e_priv *priv, struct mlx5_fs_chains *chains, ct_priv->post_act = post_act; mutex_init(&ct_priv->control_lock); - rhashtable_init(&ct_priv->zone_ht, &zone_params); - rhashtable_init(&ct_priv->ct_tuples_ht, &tuples_ht_params); - rhashtable_init(&ct_priv->ct_tuples_nat_ht, &tuples_nat_ht_params); + if (rhashtable_init(&ct_priv->zone_ht, &zone_params)) + goto err_ct_zone_ht; + if (rhashtable_init(&ct_priv->ct_tuples_ht, &tuples_ht_params)) + goto err_ct_tuples_ht; + if (rhashtable_init(&ct_priv->ct_tuples_nat_ht, &tuples_nat_ht_params)) + goto err_ct_tuples_nat_ht; return ct_priv; +err_ct_tuples_nat_ht: + rhashtable_destroy(&ct_priv->ct_tuples_ht); +err_ct_tuples_ht: + rhashtable_destroy(&ct_priv->zone_ht); +err_ct_zone_ht: err_ct_nat_tbl: mlx5_chains_destroy_global_table(chains, ct_priv->ct); err_ct_tbl: From patchwork Mon Sep 27 03:34:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: MichelleJin X-Patchwork-Id: 12519053 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D786BC433EF for ; Mon, 27 Sep 2021 03:35:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B769160FED for ; Mon, 27 Sep 2021 03:35:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232585AbhI0Dg6 (ORCPT ); Sun, 26 Sep 2021 23:36:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50378 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232574AbhI0Dgz (ORCPT ); Sun, 26 Sep 2021 23:36:55 -0400 Received: from mail-pj1-x1034.google.com (mail-pj1-x1034.google.com [IPv6:2607:f8b0:4864:20::1034]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F2657C061570; Sun, 26 Sep 2021 20:35:17 -0700 (PDT) Received: by mail-pj1-x1034.google.com with SMTP id h12so1084489pjj.1; Sun, 26 Sep 2021 20:35:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=VHvBgXQTEmDe94oFEb/1mhIUaXdt/Kv7BDHynzU+GkM=; b=b1XQjFtBLOyS9/Un8W4eCeIgeARpoBY1O9JSqsQTSpuObf7/XmEUXkv/8Kg66Mr4jB pdd6OVomEq9RjDBu/SNyjUuOjMY+jPW/ZatqNKlTKFoCCWKe9ajQb1mZLkmKrjsVhg84 n+MEw4NMxIaevmHwa0wtG7SipAxr0oh5E1jrhKRTreBEj+AT86duvWrCgXE7xocyp5W1 en3az1zM9b5IPd9ExdCnHYP+WAAnwisgWmzRTAdF1hxTK2Rr0sFxv3Hvug16dARHjQH2 2RMg7byNgVIqzEiYI8BUuCNzAN5M05R0GsPgfxsZff+Wzzqs4kLnE7tqEQhmp49BgC/5 u4gA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=VHvBgXQTEmDe94oFEb/1mhIUaXdt/Kv7BDHynzU+GkM=; b=hWq5GuUl6bw2Uxi1Bbri8r/behv1F1oty++EEWcwVGxh1HPnxNeyZNgSjMcwPPgkqI D1h5yorlS1UFOqEUUfGCwl7CW8cfUPBbAbP1qnG+K6Qr1fOAJZ0Z1lkyNz1Rrg6zPqU4 /R/1ArDcYXgX/U1RMh1LljGyfKFE7/OUZwdeduaRcx2KbMszN/3hWmrRRPbhQFpHfRG4 +trXy6ul/ZJJxwwuVF0xDShLAmLLainWGgK1rgipIgfPtiSgQWObm9sE8fQDJ3nYHtQ2 1PumT3Y+D4di43p1dZgL8lYiHJXcNkQ2cjq0lIvPRUlvDfDdwZgCSK0tBwPZEIOCOvLa mnbQ== X-Gm-Message-State: AOAM530A0JfUiFFi7hdj/eaWl8P9HxwKi0CVXEvPgMsYoVQnmeyjinps XjtRjOL3dMUHHTM6a1jtaPc= X-Google-Smtp-Source: ABdhPJzqekQ+Zq9/ZFV7pY7+1JxGzAW31Y7dDpg537PtjQ+u5rZ9S0bRlhE6Ti9AXzKewkwM2jxoAA== X-Received: by 2002:a17:903:1112:b0:13d:ce49:e275 with SMTP id n18-20020a170903111200b0013dce49e275mr20905901plh.5.1632713717447; Sun, 26 Sep 2021 20:35:17 -0700 (PDT) Received: from localhost.localdomain ([210.99.160.97]) by smtp.googlemail.com with ESMTPSA id r206sm1404320pfc.218.2021.09.26.20.35.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 Sep 2021 20:35:17 -0700 (PDT) From: MichelleJin To: davem@davemloft.net, kuba@kernel.org, yoshfuji@linux-ipv6.org, dsahern@kernel.org, johannes@sipsolutions.net Cc: saeedm@nvidia.com, leon@kernel.org, roid@nvidia.com, paulb@nvidia.com, ozsh@nvidia.com, lariel@nvidia.com, cmi@nvidia.com, netdev@vger.kernel.org, linux-rdma@vger.kernel.org, linux-wireless@vger.kernel.org Subject: [PATCH net-next v4 2/3] net: ipv6: check return value of rhashtable_init Date: Mon, 27 Sep 2021 03:34:56 +0000 Message-Id: <20210927033457.1020967-3-shjy180909@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210927033457.1020967-1-shjy180909@gmail.com> References: <20210927033457.1020967-1-shjy180909@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org When rhashtable_init() fails, it returns -EINVAL. However, since error return value of rhashtable_init is not checked, it can cause use of uninitialized pointers. So, fix unhandled errors of rhashtable_init. Signed-off-by: MichelleJin Reviewed-by: David Ahern --- v1->v2: - change commit message - fix possible memory leaks v2->v3: - nothing changed v3->v4: - fix newly created warnings due to patches net/ipv6/ila/ila_xlat.c | 6 +++++- net/ipv6/seg6.c | 8 ++++++-- net/ipv6/seg6_hmac.c | 4 +--- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/net/ipv6/ila/ila_xlat.c b/net/ipv6/ila/ila_xlat.c index a1ac0e3d8c60..47447f0241df 100644 --- a/net/ipv6/ila/ila_xlat.c +++ b/net/ipv6/ila/ila_xlat.c @@ -610,7 +610,11 @@ int ila_xlat_init_net(struct net *net) if (err) return err; - rhashtable_init(&ilan->xlat.rhash_table, &rht_params); + err = rhashtable_init(&ilan->xlat.rhash_table, &rht_params); + if (err) { + free_bucket_spinlocks(ilan->xlat.locks); + return err; + } return 0; } diff --git a/net/ipv6/seg6.c b/net/ipv6/seg6.c index e412817fba2f..65744f2d38da 100644 --- a/net/ipv6/seg6.c +++ b/net/ipv6/seg6.c @@ -374,7 +374,11 @@ static int __net_init seg6_net_init(struct net *net) net->ipv6.seg6_data = sdata; #ifdef CONFIG_IPV6_SEG6_HMAC - seg6_hmac_net_init(net); + if (seg6_hmac_net_init(net)) { + kfree(sdata); + kfree(rcu_dereference_raw(sdata->tun_src)); + return -ENOMEM; + }; #endif return 0; @@ -388,7 +392,7 @@ static void __net_exit seg6_net_exit(struct net *net) seg6_hmac_net_exit(net); #endif - kfree(sdata->tun_src); + kfree(rcu_dereference_raw(sdata->tun_src)); kfree(sdata); } diff --git a/net/ipv6/seg6_hmac.c b/net/ipv6/seg6_hmac.c index 687d95dce085..29bc4e7c3046 100644 --- a/net/ipv6/seg6_hmac.c +++ b/net/ipv6/seg6_hmac.c @@ -405,9 +405,7 @@ int __net_init seg6_hmac_net_init(struct net *net) { struct seg6_pernet_data *sdata = seg6_pernet(net); - rhashtable_init(&sdata->hmac_infos, &rht_params); - - return 0; + return rhashtable_init(&sdata->hmac_infos, &rht_params); } EXPORT_SYMBOL(seg6_hmac_net_init); From patchwork Mon Sep 27 03:34:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: MichelleJin X-Patchwork-Id: 12519055 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E3206C4332F for ; Mon, 27 Sep 2021 03:35:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C394460E52 for ; Mon, 27 Sep 2021 03:35:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232577AbhI0DhA (ORCPT ); Sun, 26 Sep 2021 23:37:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50408 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232600AbhI0Dg6 (ORCPT ); Sun, 26 Sep 2021 23:36:58 -0400 Received: from mail-pj1-x102a.google.com (mail-pj1-x102a.google.com [IPv6:2607:f8b0:4864:20::102a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C6C26C061570; Sun, 26 Sep 2021 20:35:21 -0700 (PDT) Received: by mail-pj1-x102a.google.com with SMTP id nn5-20020a17090b38c500b0019af1c4b31fso12289539pjb.3; Sun, 26 Sep 2021 20:35:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=h8lwQC5CtdK50mFU0zB09Pdklmp5zNmyWjC5W17/O0I=; b=YcSSPeP8hdBlnjQPVmyuLpNxPmXrTUu9QNWRzZ7qd+RFnQvB+Nepijb0ZIWpVReSCb CU/4gJ4t1EF21XrnNK7UvkoL4XkThdXiDJeN3er9dBAP58CUcwG5lA7qlRkghGI1NolT cdD9U3XLeEubpcJ/aE25PE/0aKuhNCLBBXelRiAilo6P+5XFmr6L4rN/PWdpv7n8iNRc jCPHigsTnGoHUEYiw7R/3CFiy83F0hZFgeZ9TH7giSJNOlbcf7AxRy6Cdy4lcV58Q1R+ e3bSgf3/0K2MYWXJZ6lMSHmfpdqpIY/S6eXR/h1KNz5ElXkOOjb75H0vqw+CGH36jkow bUMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=h8lwQC5CtdK50mFU0zB09Pdklmp5zNmyWjC5W17/O0I=; b=6e4TvQSoC5uukccwS6bbsIPpR0FZEhsBjl3+Haz33LzmYpLm7qhVgAtza/2hVQjhbI PnkmjBBG1oMx7zwZb8ziWqDK4uRhWrk6SW3NiFmk4BBVKrL54pGLmkoQ+aXm1/QRJa7y 9uRKikf808vFYlbILbTCzd7JvdTCP/MUF3DsQEY8uGPg/slBF8aT6OjHsytVQwuh74cw YG/5VtiaJvObSnPdZ6PmaJcJY+yMeoSZEanMFnSHYrCAQQ7Gb/nBmzFMS0f61aD2V/9Y 4mgk2mbU4zXukPbITz6HEJ5JVufW0Pt0s9DJROEhs8sY9WQgCxbfE7Pn6EMakaJjL+w+ s5SA== X-Gm-Message-State: AOAM531fuOiV3GjTLg8KavT8AbWfh02TS7+SuMYtMvfXHIhIchBIc72B 2HFKJs2DcqjjQ2J8cjwg2ts= X-Google-Smtp-Source: ABdhPJywH6xwy7TFmWZjSl9IAk4nkwohPB/1fyxngIhJwsU6b3voy3eqpu6+Wm5LG3Ck/l/wZ5Ww4g== X-Received: by 2002:a17:902:6e02:b0:13a:41f5:1666 with SMTP id u2-20020a1709026e0200b0013a41f51666mr20719619plk.39.1632713721297; Sun, 26 Sep 2021 20:35:21 -0700 (PDT) Received: from localhost.localdomain ([210.99.160.97]) by smtp.googlemail.com with ESMTPSA id r206sm1404320pfc.218.2021.09.26.20.35.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 Sep 2021 20:35:20 -0700 (PDT) From: MichelleJin To: davem@davemloft.net, kuba@kernel.org, yoshfuji@linux-ipv6.org, dsahern@kernel.org, johannes@sipsolutions.net Cc: saeedm@nvidia.com, leon@kernel.org, roid@nvidia.com, paulb@nvidia.com, ozsh@nvidia.com, lariel@nvidia.com, cmi@nvidia.com, netdev@vger.kernel.org, linux-rdma@vger.kernel.org, linux-wireless@vger.kernel.org Subject: [PATCH net-next v4 3/3] net: mac80211: check return value of rhashtable_init Date: Mon, 27 Sep 2021 03:34:57 +0000 Message-Id: <20210927033457.1020967-4-shjy180909@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210927033457.1020967-1-shjy180909@gmail.com> References: <20210927033457.1020967-1-shjy180909@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org When rhashtable_init() fails, it returns -EINVAL. However, since error return value of rhashtable_init is not checked, it can cause use of uninitialized pointers. So, fix unhandled errors of rhashtable_init. Signed-off-by: MichelleJin --- v1->v2: - change commit message - fix possible memory leaks v2->v3: - nothing changed v3-> v4: - nothing changed net/mac80211/mesh_pathtbl.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/net/mac80211/mesh_pathtbl.c b/net/mac80211/mesh_pathtbl.c index efbefcbac3ac..7cab1cf09bf1 100644 --- a/net/mac80211/mesh_pathtbl.c +++ b/net/mac80211/mesh_pathtbl.c @@ -60,7 +60,10 @@ static struct mesh_table *mesh_table_alloc(void) atomic_set(&newtbl->entries, 0); spin_lock_init(&newtbl->gates_lock); spin_lock_init(&newtbl->walk_lock); - rhashtable_init(&newtbl->rhead, &mesh_rht_params); + if (rhashtable_init(&newtbl->rhead, &mesh_rht_params)) { + kfree(newtbl); + return NULL; + } return newtbl; }