From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 8EA80A034F for ; Wed, 10 Nov 2021 07:51:16 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 8664A40142; Wed, 10 Nov 2021 07:51:16 +0100 (CET) Received: from NAM04-DM6-obe.outbound.protection.outlook.com (mail-dm6nam08on2067.outbound.protection.outlook.com [40.107.102.67]) by mails.dpdk.org (Postfix) with ESMTP id C97C340142 for ; Wed, 10 Nov 2021 07:51:14 +0100 (CET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kV6jvpbaDpFC/72ggqhLKH3qhKT7t2Mn7QKf/dxjwbgwRSr69/0Z/qDg0+YL1TPZEv2VLTtvMB4iceBg0teGrumrkYVJ7nRW19VUiyV+OvWURt9NOaBzolb2Qw4ScIpmVXh3lLkreL2Pvaneb6ynjdCxauY/BGoyDYw8kaB4dzivj4samXYdnmWW/OsSGi/dLu49gczadXSIMV2FU8lkgVW3dPWpEMrHXjsgWQtPOrYFWv0SdkLCzoZTUiQ8diKfws4tNalQfktcljCaiiCy4MAr6eNDOMXt7MOg8vrrOsLWI0B2hlxI2HR1K/jifpnqxV+V63HrnE7qsSdHwubKlQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=W+oKQaUVUpWgGaBHHWlzXFwi1JjWW9zmeHTO/ICv0bw=; b=ULGDYYaT23d22Dkj1cw07/fKa1QDnW6ahYkFMxvjnX1tL/ZGSna3U/lB66fn8RhHCmIsalapb7w5+nRavVVwZP9QBDhHsv+8k8jxH9aiK3VkEOJHGZICqHQ8F+oFRDRAb2warR9lVQAj1pC9aO6pRjAPPce4jKT8vGV6VeuaFUTk4iO3tf7FJlxUpY4IIA0qivUOmEMrhYe3T1TiXSeZ5qntWsjwFasIKo6jI51gX0uZ2EG0oacQ5BuyiVKbGVQRZMjGWBO9KCdq6xugwncKnRNFFkpCzyFN8BSU4s918M/184bSqshAfnNDdtWxt8Aln0JShw61KChubCyHpiQsyw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.34) smtp.rcpttodomain=intel.com smtp.mailfrom=nvidia.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=W+oKQaUVUpWgGaBHHWlzXFwi1JjWW9zmeHTO/ICv0bw=; b=Po7QWDrHLqB9MX07Jn6q34yJLkLaMre4eJZJv0U8qs3u0WHNPYwmZKHvWlSQZso300SYnRg7KvXBkB5wVdR7ztwuSolNx4bhfD/Wu2YUXFwJk3CaZC1XFgWZEKF8hHwNyMmksX9C9TLkAXU6xgX2PlJ8b/INyK7bw/IJM08vrTjtJu35sLKC44btegjQrVXOrD37I157v8xx227snoHCZkjZ+PabxBR99sMYT0NDpsnY5FCREu02YC+An40SwXgRwCkZ7Jn9uA5s8zxW0C+3pMJfl/nGAf9+c71MbBqirObNfW0HpyhVuIddPbqpZnSGdaAnWvfEKFND5Nt16xeVUQ== Received: from BN8PR04CA0043.namprd04.prod.outlook.com (2603:10b6:408:d4::17) by DM6PR12MB2795.namprd12.prod.outlook.com (2603:10b6:5:41::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4669.13; Wed, 10 Nov 2021 06:51:13 +0000 Received: from BN8NAM11FT037.eop-nam11.prod.protection.outlook.com (2603:10b6:408:d4:cafe::f9) by BN8PR04CA0043.outlook.office365.com (2603:10b6:408:d4::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4669.11 via Frontend Transport; Wed, 10 Nov 2021 06:51:12 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.34) smtp.mailfrom=nvidia.com; intel.com; dkim=none (message not signed) header.d=none;intel.com; dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.112.34 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.112.34; helo=mail.nvidia.com; Received: from mail.nvidia.com (216.228.112.34) by BN8NAM11FT037.mail.protection.outlook.com (10.13.177.182) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4690.15 via Frontend Transport; Wed, 10 Nov 2021 06:51:09 +0000 Received: from nvidia.com (172.20.187.5) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Wed, 10 Nov 2021 06:51:06 +0000 From: Xueming Li To: Vladimir Medvedkin CC: Luca Boccassi , Yipeng Wang , dpdk stable Date: Wed, 10 Nov 2021 14:30:52 +0800 Message-ID: <20211110063216.2744012-169-xuemingl@nvidia.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211110063216.2744012-1-xuemingl@nvidia.com> References: <20211110063216.2744012-1-xuemingl@nvidia.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [172.20.187.5] X-ClientProxiedBy: HQMAIL101.nvidia.com (172.20.187.10) To HQMAIL107.nvidia.com (172.20.187.13) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 53e05590-38f5-4d2f-76b0-08d9a4167a77 X-MS-TrafficTypeDiagnostic: DM6PR12MB2795: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:10000; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: J6t3IXShBWPogNchXdHuuMPFtbdjFx6Woq6vVB+KkZo6LHivgl+g0wlDvGMaq/b6jTpMVWX8wKw8h9ToRd/JQffR+f18HAlNBq2MTp3VbkT+iTiHJFFWczeMBbnEhiLNOUdzcVeJFNzjq4vamTK0+IanCGzvy1XsQ4987YaGVAF3N4XBO/4jg1WP8FZS0BCICFSxh61zKpOVP0h+Rp7qZnN6eUkrM29/w7MBkxaCZpVIIf4B4D2iJdbUbF2DuQEISi44t+qZULQEIF1FnreCOo+UpRyUs+HWFcGZwIw0MmQ+aoWNZ5GS/XTfbWDUtLgOgWP2tHJQQli2G3DJi68+f4xlQwA39G4z5olgpKr6UgDbuLUW8FAsac/wYHmVH1QgB2XeQ7BMYepQH8DXgAm8d6CiYi83lB6wuRq6Y4Zn5TFMxY4WPe9kM3CKXEaV68pRIlFYXqcA8l6MdXU+KhtdFQFXW8mXX3+ib4wq1LVCtBpd/ccx964DNxHjF7L3pzsiEEcXNvYY4Ts6IWuUZ157CQRIq/Vy3IMiQm2jPdiQqzLHKA3V9H5MdaDr04oHQacUnp70W3oqCvpM2o5NZ34FyvmBtEbewmcFlrVrUS5sfORLrApZoBxr8C/eSbg0VlGs5aMN4ZBU3YF9l0/2TVlA5SrPllA4ocaGKcY64ykoBkTieuzSDxfvJ5SIWljj5BvW1xV43O0d7ck22qtvXT1BoEGrcWityL80bLyBGE8UnfJ61PNxJJe34rF8hRUEWPoJEyMGIrCFaR/5Ty2OEUYXHrZ6lZgStpm7TbFs2Yo0mwihhhiJ9i436UyEf142oegC/KR7J5QyXebW213lscZSQA== X-Forefront-Antispam-Report: CIP:216.228.112.34; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:schybrid03.nvidia.com; CAT:NONE; SFS:(4636009)(46966006)(36840700001)(26005)(426003)(6666004)(316002)(53546011)(2616005)(16526019)(70206006)(82310400003)(336012)(36756003)(8936002)(70586007)(6286002)(86362001)(186003)(7636003)(8676002)(1076003)(47076005)(5660300002)(7696005)(4326008)(6916009)(54906003)(55016002)(356005)(4001150100001)(36860700001)(83380400001)(508600001)(2906002)(966005); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Nov 2021 06:51:09.8842 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 53e05590-38f5-4d2f-76b0-08d9a4167a77 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.112.34]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT037.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB2795 Subject: [dpdk-stable] patch 'test/hash: fix buffer overflow with jhash' has been queued to stable release 20.11.4 X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: stable-bounces@dpdk.org Sender: "stable" Hi, FYI, your patch has been queued to stable release 20.11.4 Note it hasn't been pushed to http://dpdk.org/browse/dpdk-stable yet. It will be pushed if I get no objections before 11/12/21. So please shout if anyone has objections. Also note that after the patch there's a diff of the upstream commit vs the patch applied to the branch. This will indicate if there was any rebasing needed to apply to the stable branch. If there were code changes for rebasing (ie: not only metadata diffs), please double check that the rebase was correctly done. Queued patches are on a temporary branch at: https://github.com/steevenlee/dpdk This queued commit can be viewed at: https://github.com/steevenlee/dpdk/commit/936f56164e3e98ca53b1b4b26558e4919c6a37ce Thanks. Xueming Li --- >From 936f56164e3e98ca53b1b4b26558e4919c6a37ce Mon Sep 17 00:00:00 2001 From: Vladimir Medvedkin Date: Thu, 14 Oct 2021 18:48:19 +0100 Subject: [PATCH] test/hash: fix buffer overflow with jhash Cc: Xueming Li [ upstream commit e30ef3a3a032875cc4bc395dc13201a11b110f9f ] This patch fixes buffer overflow reported by ASAN, please reference https://bugs.dpdk.org/show_bug.cgi?id=818 Some tests for the rte_hash table use the rte_jhash_32b() as the hash function. This hash function interprets the length argument in units of 4 bytes. This patch adds a wrapper function around rte_jhash_32b() to reflect API differences regarding the length argument, effectively dividing it by 4. For some tests rte_jhash() is used with keys of length not a multiple of 4 bytes. From the rte_jhash() documentation: If input key is not aligned to four byte boundaries or a multiple of four bytes in length, the memory region just after may be read (but not used in the computation). This patch increases the size of the proto field of the flow_key struct up to uint32_t. Bugzilla ID: 818 Fixes: af75078fece3 ("first public release") Signed-off-by: Vladimir Medvedkin Acked-by: Yipeng Wang --- app/test/test_hash.c | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/app/test/test_hash.c b/app/test/test_hash.c index bd4d0cb722..b99e8de1db 100644 --- a/app/test/test_hash.c +++ b/app/test/test_hash.c @@ -74,13 +74,17 @@ static uint32_t hashtest_key_lens[] = {0, 2, 4, 5, 6, 7, 8, 10, 11, 15, 16, 21, } \ } while (0) -/* 5-tuple key type */ +/* + * 5-tuple key type. + * Should be packed to avoid holes with potentially + * undefined content in the middle. + */ struct flow_key { uint32_t ip_src; uint32_t ip_dst; uint16_t port_src; uint16_t port_dst; - uint8_t proto; + uint32_t proto; } __rte_packed; /* @@ -147,7 +151,7 @@ static struct flow_key keys[5] = { { /* Parameters used for hash table in unit test functions. Name set later. */ static struct rte_hash_parameters ut_params = { .entries = 64, - .key_len = sizeof(struct flow_key), /* 13 */ + .key_len = sizeof(struct flow_key), .hash_func = rte_jhash, .hash_func_init_val = 0, .socket_id = 0, @@ -792,7 +796,7 @@ static int test_full_bucket(void) struct rte_hash_parameters params_pseudo_hash = { .name = "test4", .entries = 64, - .key_len = sizeof(struct flow_key), /* 13 */ + .key_len = sizeof(struct flow_key), .hash_func = pseudo_hash, .hash_func_init_val = 0, .socket_id = 0, @@ -895,7 +899,7 @@ static int test_extendable_bucket(void) struct rte_hash_parameters params_pseudo_hash = { .name = "test5", .entries = 64, - .key_len = sizeof(struct flow_key), /* 13 */ + .key_len = sizeof(struct flow_key), .hash_func = pseudo_hash, .hash_func_init_val = 0, .socket_id = 0, @@ -1606,6 +1610,17 @@ static struct rte_hash_parameters hash_params_ex = { .socket_id = 0, }; +/* + * Wrapper function around rte_jhash_32b. + * It is required because rte_jhash_32b() accepts the length + * as size of 4-byte units. + */ +static inline uint32_t +test_jhash_32b(const void *k, uint32_t length, uint32_t initval) +{ + return rte_jhash_32b(k, length >> 2, initval); +} + /* * add/delete key with jhash2 */ @@ -1618,7 +1633,7 @@ test_hash_add_delete_jhash2(void) hash_params_ex.name = "hash_test_jhash2"; hash_params_ex.key_len = 4; - hash_params_ex.hash_func = (rte_hash_function)rte_jhash_32b; + hash_params_ex.hash_func = (rte_hash_function)test_jhash_32b; handle = rte_hash_create(&hash_params_ex); if (handle == NULL) { @@ -1657,7 +1672,7 @@ test_hash_add_delete_2_jhash2(void) hash_params_ex.name = "hash_test_2_jhash2"; hash_params_ex.key_len = 8; - hash_params_ex.hash_func = (rte_hash_function)rte_jhash_32b; + hash_params_ex.hash_func = (rte_hash_function)test_jhash_32b; handle = rte_hash_create(&hash_params_ex); if (handle == NULL) @@ -1915,7 +1930,7 @@ test_hash_rcu_qsbr_dq_mode(uint8_t ext_bkt) struct rte_hash_parameters params_pseudo_hash = { .name = "test_hash_rcu_qsbr_dq_mode", .entries = total_entries, - .key_len = sizeof(struct flow_key), /* 13 */ + .key_len = sizeof(struct flow_key), .hash_func = pseudo_hash, .hash_func_init_val = 0, .socket_id = 0, @@ -2085,7 +2100,7 @@ test_hash_rcu_qsbr_sync_mode(uint8_t ext_bkt) struct rte_hash_parameters params_pseudo_hash = { .name = "test_hash_rcu_qsbr_sync_mode", .entries = total_entries, - .key_len = sizeof(struct flow_key), /* 13 */ + .key_len = sizeof(struct flow_key), .hash_func = pseudo_hash, .hash_func_init_val = 0, .socket_id = 0, @@ -2180,6 +2195,8 @@ test_hash_rcu_qsbr_sync_mode(uint8_t ext_bkt) static int test_hash(void) { + RTE_BUILD_BUG_ON(sizeof(struct flow_key) % sizeof(uint32_t) != 0); + if (test_add_delete() < 0) return -1; if (test_hash_add_delete_jhash2() < 0) -- 2.33.0 --- Diff of the applied patch vs upstream commit (please double-check if non-empty: --- --- - 2021-11-10 14:17:09.402785798 +0800 +++ 0168-test-hash-fix-buffer-overflow-with-jhash.patch 2021-11-10 14:17:01.980745191 +0800 @@ -1 +1 @@ -From e30ef3a3a032875cc4bc395dc13201a11b110f9f Mon Sep 17 00:00:00 2001 +From 936f56164e3e98ca53b1b4b26558e4919c6a37ce Mon Sep 17 00:00:00 2001 @@ -4,0 +5,3 @@ +Cc: Xueming Li + +[ upstream commit e30ef3a3a032875cc4bc395dc13201a11b110f9f ] @@ -28 +30,0 @@ -Cc: stable@dpdk.org