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 19625460D6; Tue, 21 Jan 2025 18:08:54 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 67E8E40649; Tue, 21 Jan 2025 18:08:32 +0100 (CET) Received: from egress-ip11a.ess.de.barracuda.com (egress-ip11a.ess.de.barracuda.com [18.184.203.234]) by mails.dpdk.org (Postfix) with ESMTP id B4D904042C for ; Tue, 21 Jan 2025 18:08:27 +0100 (CET) Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05lp2104.outbound.protection.outlook.com [104.47.18.104]) by mx-outbound11-0.eu-central-1a.ess.aws.cudaops.com (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Tue, 21 Jan 2025 17:08:27 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=VG+NA6UXyG+y9YQ1wztQCooKZ4wmQAEXNHI3aKbXu6BPWwfZEHun2AMkfTIVx5lvZbDC5WU5UEs92d85v/bWR16RiP2hZ1FemiPzPHq8EZmNDho/R8hoVQHEgww3f5g3LO/cWaXKDafTE8PZgLAt1KmGlbP6ru8mH6LL/T71VYo9D15+C6h2AVy/R0YRile7suraZihUJPkcB6k889keUy5MxIBrvL9v80V49w/kEczMAFVJaPeLwK++Pik4RVOhqxyO9BAdUDO7ZFzIWFJrulNVV+RQ3mkh0CrBpE1E5whxdP6a7fMsMDoxN2Z8A4CuaXqPfHRulfZAZZv6Dyppzg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=SkNidEHEOTLd84GD9ArcbZWOvIXiuZEOEV2ZnDIP+/c=; b=EgGUPpWY9glxBOhNcjUt47uaNt2+4CBtm78/J2gQxdJx29KkJzRFmA5oQ3MmzWmUxKxf8k2ZFOUapxBhYl3uH7sIHAGsWV9ywD9RTH6trOOhSeSEV/R2HqDCRdJBjYGaEPGUnDwD4iJ8GTnXPRKBmeyVZcQ+b+M3tQNFOoY8N3AQnI3yrp4ox1KMf2JNjSNDd0Pkr0XNM24M+F2ZsZdQe01djlKp5v3EoEOXQYzWYmkBqD3p/BkXjuBhzZw5sx2fwfgdA+ZIw0iNpx9dFe1SSoyC+ikH2dn0lK3J8PWYTr27c6P177uhRX+/L/8tJALJkB/n6pmXWjPT3xV1BOtY7Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=fail (sender ip is 178.72.21.4) smtp.rcpttodomain=dpdk.org smtp.mailfrom=napatech.com; dmarc=fail (p=reject sp=reject pct=100) action=oreject header.from=napatech.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=napatech.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=SkNidEHEOTLd84GD9ArcbZWOvIXiuZEOEV2ZnDIP+/c=; b=PMVuH0P03PHf2PaaTKFpJSrveGuyd4iQcx2uLGIDPvWb2Ar6wAtMEKV2n7HtePnzoMPzoEDunGbxCF9Okir71wUyQCEysY65icDb8vwnqb7K7BPxjk8RgVSLbB7ejJF7INMpZ6NZ/VfLdTXqOvwJbnsKz5m5lqz0YmPYdZKKTEU= Received: from AS4P251CA0029.EURP251.PROD.OUTLOOK.COM (2603:10a6:20b:5d3::19) by PR3P190MB0828.EURP190.PROD.OUTLOOK.COM (2603:10a6:102:80::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8356.22; Tue, 21 Jan 2025 17:08:25 +0000 Received: from AM2PEPF0001C70A.eurprd05.prod.outlook.com (2603:10a6:20b:5d3:cafe::8) by AS4P251CA0029.outlook.office365.com (2603:10a6:20b:5d3::19) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8356.22 via Frontend Transport; Tue, 21 Jan 2025 17:08:25 +0000 X-MS-Exchange-Authentication-Results: spf=fail (sender IP is 178.72.21.4) smtp.mailfrom=napatech.com; dkim=none (message not signed) header.d=none;dmarc=fail action=oreject header.from=napatech.com; Received-SPF: Fail (protection.outlook.com: domain of napatech.com does not designate 178.72.21.4 as permitted sender) receiver=protection.outlook.com; client-ip=178.72.21.4; helo=localhost.localdomain; Received: from localhost.localdomain (178.72.21.4) by AM2PEPF0001C70A.mail.protection.outlook.com (10.167.16.198) with Microsoft SMTP Server id 15.20.8377.8 via Frontend Transport; Tue, 21 Jan 2025 17:08:25 +0000 From: Serhii Iliushyk To: dev@dpdk.org Cc: mko-plv@napatech.com, sil-plv@napatech.com, ckm@napatech.com, stephen@networkplumber.org, Danylo Vodopianov , Oleksandr Kolomeiets Subject: [PATCH v1 04/31] net/ntnic: add array index verification Date: Tue, 21 Jan 2025 18:07:42 +0100 Message-ID: <20250121170814.3252171-5-sil-plv@napatech.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20250121170814.3252171-1-sil-plv@napatech.com> References: <20250121170814.3252171-1-sil-plv@napatech.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM2PEPF0001C70A:EE_|PR3P190MB0828:EE_ Content-Type: text/plain X-MS-Office365-Filtering-Correlation-Id: 86827ff4-da03-40db-b222-08dd3a3e37c2 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|1800799024|36860700013|376014|82310400026; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?gxkJf6drvpB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OQ9biA?= =?us-ascii?Q?gSPH1+Z/ieT/7ZIOPvJOuQ8ra7AV4vuAyaIwubPIfcXuIkQ54P1c/NzG4NtK?= =?us-ascii?Q?a4+bWAEjhEQNkSKdo5nWNG8MjPHs5nAGN1yKOYa8PesSDa5c1RZiciSuA5a7?= =?us-ascii?Q?I5njCXEF0DOv945gIn1RPh3r6wAEJKuLMbjKgPjNbIVKzcaLmlmhIz1V9m+/?= =?us-ascii?Q?MBIDdRdlQPRXA2Cf0BZda05FxKwCIuBch+kVz2FEpq5BdXSR3oIuAMv+A4zm?= =?us-ascii?Q?JntaQ07AGHB1G2U2Qde3x1bFYQ8QHE0dEbPLpuZ5QsZeEvxNaJ0mSZ5pHLW1?= =?us-ascii?Q?C4i5VHd3L+pNByh5q7RtRgznb5bGl002XSk+2mvSsZiA4OgaEvF2nlf2BM6W?= =?us-ascii?Q?eS1SoNWFvaR+YfU/8b/9h7QvcMW7ksZrLS2zaobxiP0YBvsVAu/gGwP89C/N?= =?us-ascii?Q?MGFA6lzREE/4YZ2tr1tJPYuMAZuhbaf8JPdbYq5EHvjPw9qkW8Z39AnggLQD?= =?us-ascii?Q?IzdJS6QS8liF1mRwzTKHOznWYsRm5+OBFdo0aQ4MNwUO8TJiWdv7tr1eLo2O?= =?us-ascii?Q?R6GQHs+C/9C4RBMVYsHtQGSlkU66b7UD+sD3t8leKCeGzwecHc4BhVkV/CjK?= =?us-ascii?Q?K08+eljwISESfFM=3D?= X-Forefront-Antispam-Report: CIP:178.72.21.4; CTRY:DK; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:localhost.localdomain; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230040)(1800799024)(36860700013)(376014)(82310400026); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: ceIbYqg5psFhbLdHthTSXIU29jOjesQZ5vNKf8lP+DMMZXDOV84aPUk8bvS4ubxJvqMoEx1bCr8PLMESDaJhGbmyKMBYe8SM+CvoY6JHKxL1CZxUgVD2qJzL/ispdWzk7hh1OqSxDdMKetNwVVIqQ+yPlJ4JG0ttlW0E768RsHK/KWujwialivAKHzeLFgelZhAq/iCLZ0TwKnEuaGec9In9S4PDN5Hf9PJwLVXGZ2oaoz2FtcIjoPLrqHnvs2+w6+jxcpBJC4C4AmljyKAbg1bTJ2ElB7t/wPhTyjUCTJ1UPyhBBxde6iWBRzrfNMTPJX4FFVkfyBBlbbTE7kweV4M1VKUqT5ApuEtUqiKvWBHprDhZT8ooWzjrIn09fAql6aZTgNhIv82dlNrcCBXn2gzg+wLMcYV6ft87XrPbp/8IvBqGAhDvBQIjR1y7n8tKQEozopJv/OGGbU4QabQ8FVIDDsfNaqpQgEhJ+3+60G6y2mvNZqF55T5Jih1sJGx9Nu2Jx4sm0JPwybcvUCRehlmDI07wdWXrz91bxkY4/6F5eA7zF3TqSp4DYSwR24/aN2a/wIY8BXaHOEO2TZV4xfMa+sGyqhIeGAxNfrXrzeb+bI+zOL/+p7pBO3YsZ2fT+4Cmdjv7F07wTZmxuweYLQ== X-OriginatorOrg: napatech.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Jan 2025 17:08:25.2962 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 86827ff4-da03-40db-b222-08dd3a3e37c2 X-MS-Exchange-CrossTenant-Id: c4540d0b-728a-4233-9da5-9ea30c7ec3ed X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=c4540d0b-728a-4233-9da5-9ea30c7ec3ed; Ip=[178.72.21.4]; Helo=[localhost.localdomain] X-MS-Exchange-CrossTenant-AuthSource: AM2PEPF0001C70A.eurprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PR3P190MB0828 X-BESS-ID: 1737479307-302816-13349-7963-1 X-BESS-VER: 2019.1_20250117.1903 X-BESS-Apparent-Source-IP: 104.47.18.104 X-BESS-Parts: H4sIAAAAAAACA4uuVkqtKFGyUioBkjpK+cVKVkYWpmZAVgZQMMncwMLS1DI5NT HRyNTCMNHQONk8xcjM0iIlOdkkKc1UqTYWALA9U/BBAAAA X-BESS-Outbound-Spam-Score: 0.00 X-BESS-Outbound-Spam-Report: Code version 3.2, rules version 3.2.2.261957 [from cloudscan20-53.eu-central-1b.ess.aws.cudaops.com] Rule breakdown below pts rule name description ---- ---------------------- -------------------------------- 0.00 BSF_BESS_OUTBOUND META: BESS Outbound X-BESS-Outbound-Spam-Status: SCORE=0.00 using account:ESS113687 scores of KILL_LEVEL=7.0 tests=BSF_BESS_OUTBOUND X-BESS-BRTS-Status: 1 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org From: Danylo Vodopianov CI found couple coverity problems which were fixed in this commit. CID: 448983, 448980 Memory - corruptions (OVERRUN) Add check both indices within bounds before calling the macro Coverity issue: 448983 Fixes: 6e8b7f11205f ("net/ntnic: add categorizer (CAT) FPGA module") Signed-off-by: Danylo Vodopianov --- .../ntnic/nthw/flow_api/hw_mod/hw_mod_hsh.c | 17 ++++++++++++++++- .../ntnic/nthw/flow_api/hw_mod/hw_mod_pdb.c | 18 ++++++++++++++++-- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/drivers/net/ntnic/nthw/flow_api/hw_mod/hw_mod_hsh.c b/drivers/net/ntnic/nthw/flow_api/hw_mod/hw_mod_hsh.c index 1750d09afb..cc8db2fae5 100644 --- a/drivers/net/ntnic/nthw/flow_api/hw_mod/hw_mod_hsh.c +++ b/drivers/net/ntnic/nthw/flow_api/hw_mod/hw_mod_hsh.c @@ -121,8 +121,23 @@ static int hw_mod_hsh_rcp_mod(struct flow_api_backend_s *be, enum hw_hsh_e field INDEX_TOO_LARGE_LOG; return INDEX_TOO_LARGE; } + /* Size of the structure */ + size_t element_size = sizeof(struct hsh_v5_rcp_s); + /* Size of the buffer */ + size_t buffer_size = sizeof(be->hsh.v5.rcp); - DO_COMPARE_INDEXS(be->hsh.v5.rcp, struct hsh_v5_rcp_s, index, word_off); + /* Calculate the maximum valid index (number of elements in the buffer) */ + size_t max_idx = buffer_size / element_size; + + /* Check that both indices are within bounds before calling the macro */ + if (index < max_idx && word_off < max_idx) { + DO_COMPARE_INDEXS(be->hsh.v5.rcp, struct hsh_v5_rcp_s, index, + word_off); + + } else { + INDEX_TOO_LARGE_LOG; + return INDEX_TOO_LARGE; + } break; case HW_HSH_RCP_FIND: diff --git a/drivers/net/ntnic/nthw/flow_api/hw_mod/hw_mod_pdb.c b/drivers/net/ntnic/nthw/flow_api/hw_mod/hw_mod_pdb.c index 59285405ba..147a06ac2b 100644 --- a/drivers/net/ntnic/nthw/flow_api/hw_mod/hw_mod_pdb.c +++ b/drivers/net/ntnic/nthw/flow_api/hw_mod/hw_mod_pdb.c @@ -131,8 +131,22 @@ static int hw_mod_pdb_rcp_mod(struct flow_api_backend_s *be, enum hw_pdb_e field INDEX_TOO_LARGE_LOG; return INDEX_TOO_LARGE; } - - DO_COMPARE_INDEXS(be->pdb.v9.rcp, struct pdb_v9_rcp_s, index, *value); + /* Size of the structure */ + size_t element_size = sizeof(struct pdb_v9_rcp_s); + /* Size of the buffer */ + size_t buffer_size = sizeof(be->pdb.v9.rcp); + + /* Calculate the maximum valid index (number of elements in the buffer) */ + size_t max_idx = buffer_size / element_size; + + /* Check that both indices are within bounds before calling the macro */ + if (index < max_idx && *value < max_idx) { + DO_COMPARE_INDEXS(be->pdb.v9.rcp, struct pdb_v9_rcp_s, index, + *value); + } else { + INDEX_TOO_LARGE_LOG; + return INDEX_TOO_LARGE; + } break; case HW_PDB_RCP_DESCRIPTOR: -- 2.45.0