From mboxrd@z Thu Jan 1 00:00:00 1970 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=-10.1 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable 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 700B8C35669 for ; Sun, 23 Feb 2020 02:29:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3C11420707 for ; Sun, 23 Feb 2020 02:29:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1582424990; bh=3e93H9hKUcz5QbUSGjf9au83mTkA3AVksZMm/ZBw/qE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=Rew/QFua9E+fVoHOvDw5hFPKWlZ41mzRS56mVUthZFNuNRTBzw3W5YAuCtksTu3p9 Y39LOmPPUtNxVnrJ2ajE2o2Q+qh/4cuxDU+Dl2ieSJHiWjfqapy4sN6RaBG5icgc4s 2R415+O7ylZgZtEeonawHBgiU4+fSYiBMzm2Sl7E= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728908AbgBWCX5 (ORCPT ); Sat, 22 Feb 2020 21:23:57 -0500 Received: from mail.kernel.org ([198.145.29.99]:53700 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728801AbgBWCX4 (ORCPT ); Sat, 22 Feb 2020 21:23:56 -0500 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 124C222464; Sun, 23 Feb 2020 02:23:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1582424635; bh=3e93H9hKUcz5QbUSGjf9au83mTkA3AVksZMm/ZBw/qE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JznPPy7peB5U5RT4Smez6ZdF/ROXKFLRqnE3IyJb/sCi1JQX41WBENrMn+e0tLXFF 6dpLg52jp6xGq5j9Y+B1Jql9vPkTyNTBe8F8aIqGpGBbhf9oM+1ox7GH0z6yW50iAe vtj2qHdU+pFlzXMo2Xo9vqz7EtG3Bitb01HEsv4A= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Arthur Kiyanovski , Sameeh Jubran , "David S . Miller" , Sasha Levin , netdev@vger.kernel.org Subject: [PATCH AUTOSEL 4.19 13/25] net: ena: fix potential crash when rxfh key is NULL Date: Sat, 22 Feb 2020 21:23:27 -0500 Message-Id: <20200223022339.1885-13-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200223022339.1885-1-sashal@kernel.org> References: <20200223022339.1885-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Arthur Kiyanovski [ Upstream commit 91a65b7d3ed8450f31ab717a65dcb5f9ceb5ab02 ] When ethtool -X is called without an hkey, ena_com_fill_hash_function() is called with key=NULL, which is passed to memcpy causing a crash. This commit fixes this issue by checking key is not NULL. Fixes: 1738cd3ed342 ("net: ena: Add a driver for Amazon Elastic Network Adapters (ENA)") Signed-off-by: Sameeh Jubran Signed-off-by: Arthur Kiyanovski Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- drivers/net/ethernet/amazon/ena/ena_com.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/drivers/net/ethernet/amazon/ena/ena_com.c b/drivers/net/ethernet/amazon/ena/ena_com.c index 92261c946e2a3..c9b21306cf6c4 100644 --- a/drivers/net/ethernet/amazon/ena/ena_com.c +++ b/drivers/net/ethernet/amazon/ena/ena_com.c @@ -2075,15 +2075,16 @@ int ena_com_fill_hash_function(struct ena_com_dev *ena_dev, switch (func) { case ENA_ADMIN_TOEPLITZ: - if (key_len > sizeof(hash_key->key)) { - pr_err("key len (%hu) is bigger than the max supported (%zu)\n", - key_len, sizeof(hash_key->key)); - return -EINVAL; + if (key) { + if (key_len != sizeof(hash_key->key)) { + pr_err("key len (%hu) doesn't equal the supported size (%zu)\n", + key_len, sizeof(hash_key->key)); + return -EINVAL; + } + memcpy(hash_key->key, key, key_len); + rss->hash_init_val = init_val; + hash_key->keys_num = key_len >> 2; } - - memcpy(hash_key->key, key, key_len); - rss->hash_init_val = init_val; - hash_key->keys_num = key_len >> 2; break; case ENA_ADMIN_CRC32: rss->hash_init_val = init_val; -- 2.20.1