From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E0A09606A322 for ; Sat, 5 Dec 2026 06:27:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=networkplumber-org.20260707.gappssmtp.com header.i=@networkplumber-org.20260707.gappssmtp.com header.a=rsa-sha256 header.s=20260707 header.b=COr8cNbH Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id AD48C40E64; Sat, 5 Dec 2026 07:26:08 +0100 (CET) Received: from mail-pg1-f178.google.com (mail-pg1-f178.google.com [209.85.215.178]) by mails.dpdk.org (Postfix) with ESMTPS id 1522240E38 for ; Sat, 5 Dec 2026 07:26:05 +0100 (CET) Received: by mail-pg1-f178.google.com with SMTP id 41be03b00d2f7-cded697ba49so763118a12.1 for ; Fri, 04 Dec 2026 22:26:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20260707.gappssmtp.com; s=20260707; t=1796451963; x=1797056763; darn=dpdk.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=uJNwyLKINn/D6Q4Xru+5loUiPPRqYNDBmeeMg2BNJps=; b=COr8cNbHBBz8EuWHn1PEFjzIatBewcIkHqMIQMafSK2Ov/Kr5MWZh6hCuUU4rm5fcu bkQy+0dTeHCxrrRpWp8ayktbqKC2+oaAdtj4hLeLMwM+E9U3QK7NxtidYs89mvcwc2Oh 6MHD07JMxP0xu78LqJt4MfcC1g1yTC/YKxPLTWtA2UnQyzT3/KP/t6GcNhlqnI/JBwHC fighknkVYkTdUzxU8ECxmWhF6A01wsPn6opG7uMP7cIZXKVZclP7bthrSGSteIodU6zk 5aq0i1UDiy33T+4YpjebdPSGT3uNAqFB2M3euOmR+KjmJVdxDK5rZ+EC7viILyq+6Uhw H1Kw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796451963; x=1797056763; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=uJNwyLKINn/D6Q4Xru+5loUiPPRqYNDBmeeMg2BNJps=; b=ZuqkWrtiuOyiIKIgJZIqVL6mUftvC4t7czS8g8q28IkBKKVAq3sKEqAcmSwJVULxN9 XK2JadJ8A+vUrk/BNR0NoLiTrtm0+8r3lKb8OC3iwBlu09iCsDvJJ9Xbd/iy+9fzbeKe OYnJ3Nt/qXbf+HRBPSmKjYRspNvMc8NjTLwVWuMMr4FqF5Lz8hIZGIWi8EuPCirJNPOb BGNGQ17zZWEckrObpfw9Fd7j3/tYygVjW6akumTr43yoZGWdI5AUnh8BIRCzA0k1ffXZ JPf+zYQS7RO6k4AcSTzCs/HxBmZoDQvaRIdVFcvBX8RP9A7XC6E4tJcJ2CYCu8yMgaYQ Wj+g== X-Gm-Message-State: AB4q+uGLqDSdDb1yRS5iZmFi6ozpVAffl0H4AUiFo+VZk5tkUutMs3Vc nA6kJPQsc3AG9cb1GGgP6JLujkrlkhoYFsvHcJQkUAUUn29Aa2sPTl3l3vnIjuMLmnKjwNERgWI ZVysDoRM= X-Gm-Gg: AZFdTZdmiCYxxsev8EtN4Hph27+gZmimXJDm4yJJyKIA1pnOWEKmOQEJFrhWUKL3Gbf lfRMaBq7MeghJsT2KlxGukXNrjYa/u8t84jFt03idMz4rpJ0HHv81WARoOUgQopRef9TPt9+egs 7BD4hf8jmd38MiOrvyRngi4+7U9mK3sVm/qjru6f0XO9v/n1tWWpgL6jiHmrmA+cFcHFRc3TFJV 3n0PTHIy2Yr5/J/C8Yk7VFsZxvqgrBp+EyyYrWC+hHWoHaE4oNWa81LCj2PBwn+o/ixnevLJilm EWcffBl/N6PF9ouNsB9Apx9n71w/w6ffRlZapY1JT0ZlPYdKpY5OKWj3giZvDx+QvWuegkS407W BqKxDmZMajjn7/anpzjHrQtz8paPaRptEvE5PiPg42pJqeOk2OXylgryT/4cyLs/m/CIEy4o6wo G4ws66wZY9qqSS9UtkC9Aeg5fjDVjGGC2mQ4yxSVLF1od0mn449AjCRPZSRomnmft8jgfrCG0n8 tRe3xefoi+dXvGDKlsNR0SmakO5vqJosasb9pJ85LO6kn2K83pEdvGdtxpZd8bOQRARf8+AGaQh SpmNELturpz5RvOIuSGZxBWe3dGffK9fX8Y3WIipxqDaIfl12eCnehVxNg5dnkJORBogx44Bvn2 wuZh7Int0uOK1fQ== X-Received: by 2002:a17:90b:5904:b0:3ab:1b1c:8a70 with SMTP id 98e67ed59e1d1-3b5e06bbad5mr3698837a91.38.1796451963520; Fri, 04 Dec 2026 22:26:03 -0800 (PST) Received: from phoenix.lan (204-195-112-43.wavecable.com. [204.195.112.43]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3b6168d3e2fsm1162797a91.2.2026.12.04.22.26.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Dec 2026 22:26:03 -0800 (PST) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Subject: [PATCH v4 12/68] eal: validate memory size arguments Date: Fri, 4 Dec 2026 22:19:49 -0800 Message-ID: <20261205062551.19553-13-stephen@networkplumber.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261205062551.19553-1-stephen@networkplumber.org> References: <20260914054912.755403-1-stephen@networkplumber.org> <20261205062551.19553-1-stephen@networkplumber.org> X-Archived-By: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Archive: List-Post: List-Help: List-Subscribe: , X-Spam-Status: No, score=-17.0 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 The -m, -n and -r options are converted with atoi(), which does not detect any error: it returns zero for a string that is not a number at all, and its behaviour on overflow is undefined. So "-m foo" is silently taken as zero rather than rejected, and "-m 99999999999999999999" is undefined. The -n and -r cases are partly covered by their existing checks for zero, but only because a garbage value happens to convert to zero; "-n 4x" is accepted as four. The -m value is also scaled by 1024 * 1024 with no check, so a large enough value wraps around and asks for a small amount of memory. Use rte_kvargs_to_uint() for the three options, which converts the whole string and checks it against a range. EAL already depends on kvargs, so no new dependency is introduced. Note that this now bounds -m so that the scaled value cannot overflow size_t, which on a 32-bit build limits it to just under 4G; previously such a value was accepted and wrapped. Signed-off-by: Stephen Hemminger --- lib/eal/common/eal_common_options.c | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/lib/eal/common/eal_common_options.c b/lib/eal/common/eal_common_options.c index b2c0744447..6d809912ff 100644 --- a/lib/eal/common/eal_common_options.c +++ b/lib/eal/common/eal_common_options.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #ifndef RTE_EXEC_ENV_WINDOWS @@ -29,6 +30,7 @@ #include #include #include +#include #include #ifndef RTE_EXEC_ENV_WINDOWS #include @@ -2209,23 +2211,34 @@ eal_parse_args(void) /* memory options */ if (args.memory_size != NULL) { - int_cfg->memory = atoi(args.memory_size); - int_cfg->memory *= 1024ULL; - int_cfg->memory *= 1024ULL; + uint64_t mem; + + /* value is in megabytes, and must not overflow when scaled */ + if (rte_kvargs_to_uint(args.memory_size, 0, + SIZE_MAX / (1024 * 1024), &mem) < 0) { + EAL_LOG(ERR, "invalid memory size parameter"); + return -1; + } + int_cfg->memory = (size_t)mem * 1024 * 1024; } if (args.memory_channels != NULL) { - int_cfg->force_nchannel = atoi(args.memory_channels); - if (int_cfg->force_nchannel == 0) { + uint64_t channels; + + if (rte_kvargs_to_uint(args.memory_channels, 1, UINT_MAX, + &channels) < 0) { EAL_LOG(ERR, "invalid memory channel parameter"); return -1; } + int_cfg->force_nchannel = channels; } if (args.memory_ranks != NULL) { - int_cfg->force_nrank = atoi(args.memory_ranks); - if (int_cfg->force_nrank == 0 || int_cfg->force_nrank > 16) { + uint64_t ranks; + + if (rte_kvargs_to_uint(args.memory_ranks, 1, 16, &ranks) < 0) { EAL_LOG(ERR, "invalid memory rank parameter"); return -1; } + int_cfg->force_nrank = ranks; } if (args.no_huge) { int_cfg->no_hugetlbfs = 1; -- 2.53.0