From patchwork Tue Oct 6 07:41:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Olivier Matz X-Patchwork-Id: 79735 X-Patchwork-Delegate: gakhil@marvell.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 9D0BAA04BB; Tue, 6 Oct 2020 09:42:23 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 6C7E72C54; Tue, 6 Oct 2020 09:42:05 +0200 (CEST) Received: from proxy.6wind.com (host.76.145.23.62.rev.coltfrance.com [62.23.145.76]) by dpdk.org (Postfix) with ESMTP id 58DDC11A4; Tue, 6 Oct 2020 09:42:01 +0200 (CEST) Received: from glumotte.dev.6wind.com. (unknown [10.16.0.195]) by proxy.6wind.com (Postfix) with ESMTP id 2D58946B234; Tue, 6 Oct 2020 09:42:00 +0200 (CEST) From: Olivier Matz To: dev@dpdk.org Cc: Marko Kovacevic , Akhil Goyal , Fan Zhang , Arek Kusztal , stable@dpdk.org Date: Tue, 6 Oct 2020 09:41:41 +0200 Message-Id: <20201006074143.31691-2-olivier.matz@6wind.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201006074143.31691-1-olivier.matz@6wind.com> References: <20201006074143.31691-1-olivier.matz@6wind.com> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH 1/3] examples/fips_validation: fix buffer overflow X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" If the file name is larger than MAX_STRING_SIZE (64), strcpy() will overwrite the content of memory. Replace strcpy() by rte_strscpy(), check its return value, and increase file_name size to 256. Fixes: 3d0fad56b74a ("examples/fips_validation: add crypto FIPS application") Cc: stable@dpdk.org Signed-off-by: Olivier Matz Acked-by: Fan Zhang --- examples/fips_validation/fips_validation.c | 12 ++++++++++-- examples/fips_validation/fips_validation.h | 3 ++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/examples/fips_validation/fips_validation.c b/examples/fips_validation/fips_validation.c index 9bdf257b8b..13f763c9aa 100644 --- a/examples/fips_validation/fips_validation.c +++ b/examples/fips_validation/fips_validation.c @@ -281,7 +281,11 @@ fips_test_init(const char *req_file_path, const char *rsp_file_path, fips_test_clear(); - strcpy(info.file_name, req_file_path); + if (rte_strscpy(info.file_name, req_file_path, + sizeof(info.file_name)) < 0) { + RTE_LOG(ERR, USER1, "Path %s too long\n", req_file_path); + return -EINVAL; + } info.algo = FIPS_TEST_ALGO_MAX; if (parse_file_type(req_file_path) < 0) { RTE_LOG(ERR, USER1, "File %s type not supported\n", @@ -307,7 +311,11 @@ fips_test_init(const char *req_file_path, const char *rsp_file_path, return -ENOMEM; } - strlcpy(info.device_name, device_name, sizeof(info.device_name)); + if (rte_strscpy(info.device_name, device_name, + sizeof(info.device_name)) < 0) { + RTE_LOG(ERR, USER1, "Device name %s too long\n", device_name); + return -EINVAL; + } if (fips_test_parse_header() < 0) { RTE_LOG(ERR, USER1, "Failed parsing header\n"); diff --git a/examples/fips_validation/fips_validation.h b/examples/fips_validation/fips_validation.h index 75fa555fa6..deba83eada 100644 --- a/examples/fips_validation/fips_validation.h +++ b/examples/fips_validation/fips_validation.h @@ -14,6 +14,7 @@ #define MAX_NB_TESTS 10240 #define MAX_BUF_SIZE 2048 #define MAX_STRING_SIZE 64 +#define MAX_FILE_NAME_SIZE 256 #define MAX_DIGEST_SIZE 64 #define POSITIVE_TEST 0 @@ -164,7 +165,7 @@ struct fips_test_interim_info { uint32_t vec_start_off; uint32_t nb_vec_lines; char device_name[MAX_STRING_SIZE]; - char file_name[MAX_STRING_SIZE]; + char file_name[MAX_FILE_NAME_SIZE]; union { struct aesavs_interim_data aes_data; From patchwork Tue Oct 6 07:41:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Olivier Matz X-Patchwork-Id: 79737 X-Patchwork-Delegate: gakhil@marvell.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id E1E74A04BB; Tue, 6 Oct 2020 09:42:57 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 87DD51B28D; Tue, 6 Oct 2020 09:42:08 +0200 (CEST) Received: from proxy.6wind.com (host.76.145.23.62.rev.coltfrance.com [62.23.145.76]) by dpdk.org (Postfix) with ESMTP id 6BF1B1E35; Tue, 6 Oct 2020 09:42:01 +0200 (CEST) Received: from glumotte.dev.6wind.com. (unknown [10.16.0.195]) by proxy.6wind.com (Postfix) with ESMTP id 3B52846B235; Tue, 6 Oct 2020 09:42:00 +0200 (CEST) From: Olivier Matz To: dev@dpdk.org Cc: Marko Kovacevic , Akhil Goyal , Fan Zhang , Arek Kusztal , stable@dpdk.org Date: Tue, 6 Oct 2020 09:41:42 +0200 Message-Id: <20201006074143.31691-3-olivier.matz@6wind.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201006074143.31691-1-olivier.matz@6wind.com> References: <20201006074143.31691-1-olivier.matz@6wind.com> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH 2/3] examples/fips_validation: ignore \r in input files X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Some test vectors contain '\r' before '\n' (see link). Ignore them. Link: https://www.openssl.org/docs/fips/testvectors-linux-2007-10-10.tar.gz Fixes: 3d0fad56b74a ("examples/fips_validation: add crypto FIPS application") Cc: stable@dpdk.org Signed-off-by: Olivier Matz --- examples/fips_validation/fips_validation.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/examples/fips_validation/fips_validation.c b/examples/fips_validation/fips_validation.c index 13f763c9aa..858f581ba3 100644 --- a/examples/fips_validation/fips_validation.c +++ b/examples/fips_validation/fips_validation.c @@ -33,6 +33,8 @@ get_file_line(void) if (loc >= MAX_LINE_CHAR - 1) return -ENOMEM; + if (c == '\r') + continue; if (c == '\n') break; line[loc++] = c; From patchwork Tue Oct 6 07:41:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Olivier Matz X-Patchwork-Id: 79734 X-Patchwork-Delegate: gakhil@marvell.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id E8539A04BB; Tue, 6 Oct 2020 09:42:04 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 4ED2C1E35; Tue, 6 Oct 2020 09:42:03 +0200 (CEST) Received: from proxy.6wind.com (host.76.145.23.62.rev.coltfrance.com [62.23.145.76]) by dpdk.org (Postfix) with ESMTP id 6FA8325B3 for ; Tue, 6 Oct 2020 09:42:01 +0200 (CEST) Received: from glumotte.dev.6wind.com. (unknown [10.16.0.195]) by proxy.6wind.com (Postfix) with ESMTP id 48CC846B236; Tue, 6 Oct 2020 09:42:00 +0200 (CEST) From: Olivier Matz To: dev@dpdk.org Cc: Marko Kovacevic , Akhil Goyal , Fan Zhang , Arek Kusztal Date: Tue, 6 Oct 2020 09:41:43 +0200 Message-Id: <20201006074143.31691-4-olivier.matz@6wind.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201006074143.31691-1-olivier.matz@6wind.com> References: <20201006074143.31691-1-olivier.matz@6wind.com> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH 3/3] examples/fips_validation: support self-test only X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Make it possible to pass the self-tests when no req path is set. Signed-off-by: Olivier Matz Acked-by: Fan Zhang --- examples/fips_validation/main.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/examples/fips_validation/main.c b/examples/fips_validation/main.c index 0a1c8b568c..ee3a890e9e 100644 --- a/examples/fips_validation/main.c +++ b/examples/fips_validation/main.c @@ -315,8 +315,21 @@ cryptodev_fips_validate_parse_args(int argc, char **argv) } } - if (env.req_path == NULL || env.rsp_path == NULL || - env.dev_id == UINT32_MAX) { + if (env.dev_id == UINT32_MAX) { + RTE_LOG(ERR, USER1, "No device specified\n"); + cryptodev_fips_validate_usage(prgname); + return -EINVAL; + } + + if ((env.req_path == NULL && env.rsp_path != NULL) || + (env.req_path != NULL && env.rsp_path == NULL)) { + RTE_LOG(ERR, USER1, "Missing req path or rsp path\n"); + cryptodev_fips_validate_usage(prgname); + return -EINVAL; + } + + if (env.req_path == NULL && env.self_test == 0) { + RTE_LOG(ERR, USER1, "--self-test must be set if req path is missing\n"); cryptodev_fips_validate_usage(prgname); return -EINVAL; } @@ -348,6 +361,11 @@ main(int argc, char *argv[]) return -1; } + if (env.req_path == NULL || env.rsp_path == NULL) { + printf("No request, exit.\n"); + goto exit; + } + if (!env.is_path_folder) { printf("Processing file %s... ", env.req_path);