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 13ABB45C07; Tue, 29 Oct 2024 06:48:42 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id A0A374014F; Tue, 29 Oct 2024 06:48:41 +0100 (CET) Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2057.outbound.protection.outlook.com [40.107.93.57]) by mails.dpdk.org (Postfix) with ESMTP id 04B5540144 for ; Tue, 29 Oct 2024 06:48:39 +0100 (CET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=jd7E+aFG7lGGuxxfi8vHChqe0r/G/dWrWVZ7+gfSqT8RRJcsa3ecWDXyIZeMjsFN1mTSqXN83bMJYSt2VlhJLKdWbXcniZbLzg5zrupLbihwCULq8xv92ijs1DQpEAbEmbdYVJxHk+lYZyOQcGNn1vjALxI1PNYo+/6/rrn+nE1G5J8nQbk/UbNMBUqrOKOxkbxlM1qkAjfwJDj3bOBGWrOt5og6NabplFC+FkWoKjaffuwiDWpG8D9u/o+bwViVk85RiDfWBWWKzj1TrVcJ8QgZ9voZAy/JiJOmh7/dJ/k5BgndoU+jvOURcg9RNB1q/j/K5sWsaoK/GMGkhT2fTQ== 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=dL/YIjN5sW4wW9TiIT0XNBkga25nsGNr2AxqH5j7XOI=; b=BoiuD/WAcJNB8N5Fg3FjVISnlPMtTeY3s9CDSkygdDF4wkgRBOzdLyFsE1p3JGCBcsBw4gCw2xyjPxYbAzGFCF62v5pxAAEoFKTl/MM0NXuMMny2ivwyHSwHU691CrQedC5L1WJW96Dmlm/kokR8Nx++zb0CqqjMnuidrfuzLmQi/Zx45Z4V678MIuN6lyWn+xEMNn/7DpHfKDOQrzYJwWp0L4ymMz5ctVbrygiLnawkyyR2xnTX0r6gXTM0JVy207iQt1nKfP2wdPANwgc8V4iRj5E5P3dRxEDKZ7+8pNSejSb1YNBn70d6Ah34TKdXW3eWG9TZ/3aep4Wy76eR1A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=dL/YIjN5sW4wW9TiIT0XNBkga25nsGNr2AxqH5j7XOI=; b=imCGWQgWkuy5wxUjxL4ZCUDTM0tXXYDKgf+z1mTfMUDcPw1RI//ruhwgpDB0ObAIVGlCZHiQFNIjUTKl4VlwViSE8rGCgAfeQMFAXuQ1xwQcEKoJc9ZFM47Ww3WFVE7OvsqCdZVItCJq62p2iThGABFPF3I2wUXftdyLLr0LDpg= Received: from CH3PR12MB8233.namprd12.prod.outlook.com (2603:10b6:610:129::15) by DS0PR12MB7584.namprd12.prod.outlook.com (2603:10b6:8:13b::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.25; Tue, 29 Oct 2024 05:48:37 +0000 Received: from CH3PR12MB8233.namprd12.prod.outlook.com ([fe80::278f:5cc5:549c:3515]) by CH3PR12MB8233.namprd12.prod.outlook.com ([fe80::278f:5cc5:549c:3515%4]) with mapi id 15.20.8093.023; Tue, 29 Oct 2024 05:48:37 +0000 From: "Tummala, Sivaprasad" To: Huisong Li , "dev@dpdk.org" CC: "mb@smartsharesystems.com" , "thomas@monjalon.net" , "Yigit, Ferruh" , "anatoly.burakov@intel.com" , "david.hunt@intel.com" , "stephen@networkplumber.org" , "konstantin.ananyev@huawei.com" , "david.marchand@redhat.com" , "fengchengwen@huawei.com" , "liuyonglong@huawei.com" Subject: RE: [PATCH v13 2/3] examples/l3fwd-power: fix data overflow when parse command line Thread-Topic: [PATCH v13 2/3] examples/l3fwd-power: fix data overflow when parse command line Thread-Index: AQHbJsBuWK+ViTADikW4KJuptsbzaLKdPrqQ Date: Tue, 29 Oct 2024 05:48:37 +0000 Message-ID: References: <20240320105529.5626-1-lihuisong@huawei.com> <20241025091851.19919-1-lihuisong@huawei.com> <20241025091851.19919-3-lihuisong@huawei.com> In-Reply-To: <20241025091851.19919-3-lihuisong@huawei.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: msip_labels: MSIP_Label_dce362fe-1558-4fb5-9f64-8a6240d76441_ActionId=dc801720-b895-4497-bb4c-5b367d05496b; MSIP_Label_dce362fe-1558-4fb5-9f64-8a6240d76441_ContentBits=0; MSIP_Label_dce362fe-1558-4fb5-9f64-8a6240d76441_Enabled=true; MSIP_Label_dce362fe-1558-4fb5-9f64-8a6240d76441_Method=Standard; MSIP_Label_dce362fe-1558-4fb5-9f64-8a6240d76441_Name=AMD Internal Distribution Only; MSIP_Label_dce362fe-1558-4fb5-9f64-8a6240d76441_SetDate=2024-10-29T05:48:01Z; MSIP_Label_dce362fe-1558-4fb5-9f64-8a6240d76441_SiteId=3dd8961f-e488-4e60-8e11-a82d994e183d; authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=amd.com; x-ms-publictraffictype: Email x-ms-traffictypediagnostic: CH3PR12MB8233:EE_|DS0PR12MB7584:EE_ x-ms-office365-filtering-correlation-id: 6e282aa9-eeeb-4157-a7c6-08dcf7dd558c x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; ARA:13230040|1800799024|366016|376014|7416014|38070700018; x-microsoft-antispam-message-info: =?us-ascii?Q?QmmxiTmVZ2sqKcaoJAqgW4rWGIQu4cllFhI6khTuL2iCaJwDUbRYD2etUB1w?= =?us-ascii?Q?21t5ezT12Otan7zHonHaM56CjgYfnwL2OqvDQxS4Tw+AnOs8Q2yE9OgZ38xl?= =?us-ascii?Q?ImKWRbERvC9yLCXw7mBPlu6ts1Evs5nRqIQVsAlz5v/pz7PD6FA6hDpwaqvZ?= =?us-ascii?Q?kl/tnhjs27QmvaD/ZJ9BUyv/Tqm6HbLkIPCn4aXnnlGUds2oVKOHh4m2raCN?= =?us-ascii?Q?ilNRoHGX77iADYmFQHIevT+w0RikZvd7lTjJTvCjQE8aoCv97s0HqZW/GW8t?= =?us-ascii?Q?pWveirUCuywBVtEnciFDmJDehTB6ra/w8/62G8JOXmxioIs34sOFeM+SFrnv?= =?us-ascii?Q?DyDkADU90BbEeb8K7KKCH+IuM7K0JLMutuskSYvJNnlfdHLjCKEVZjeVyIiT?= =?us-ascii?Q?vi7VCEUZINomUsWYkRksSIjlFjdYpV4k3xvf2XeQC7TNELKyBpj36oMnq8E0?= =?us-ascii?Q?B86iI4NQEjakw4oui5rV4mv+BxQlTRzUsfWgmRKWaBvSncO6gUMublXxnw4n?= =?us-ascii?Q?+YKLYZwAnjCxdh+HIIwoECexbDLu282w1ZucEKE/HzLKXqgUcwGV1A47Ocr3?= =?us-ascii?Q?eNHjjtaMwkJU2e38DzbVwmNrcUcyBNTaO5M7DHu9onxJdul04Hc99K5jbJ+A?= =?us-ascii?Q?V05+S1toFTrKVbA4STuHLG+APlqkPTsdWMwrHH50aHD2A2xhIsTVpBmtr5eQ?= =?us-ascii?Q?E8Zr9cyICpMA4meJjvvVp0so0PV3ALCEeVv4yHR2b1O2D/z0bc7kgErsVRH0?= =?us-ascii?Q?RSnc64YHUO32TC36a38/yOE+ULGznP15Z1CVSnRsvV/jS000NyUzd1mf6THS?= =?us-ascii?Q?lhYm2kCQxADqEjPtDxbiclcwAxoERIRup3mUvVNXdHw41YekchvqTtTE+McV?= =?us-ascii?Q?WJ1gsu91mCPSBmWcWJ/Rl+hV2ehu9z0yNCH9VMuC8LP3PqUP52CxT6B8GOwb?= =?us-ascii?Q?i9nwFw5HhtKmKS6kxtjqDbieWcjQtMnjRB7fp4oZqwJPYrVokSgdRKcnRIx1?= =?us-ascii?Q?4SWnxine6oOuJI69kSxCenK26czWv/yYFBQgqE4W6z2AinEcTvyasSyJjO5q?= =?us-ascii?Q?Wicl94g4bYkvCGCOSlxg9RltntXEVetIyeY80EIJuFiy1uFdCUlhc57trXA2?= =?us-ascii?Q?J8utzokmSy64G0Ln3qwF0XK80I1AJSq8FCP4FZ7N9+FcD6CvSDJ5tSfCwwlX?= =?us-ascii?Q?iqa0QhjoSXU0cZbPzJwbdBU5WAUU4NrmD4XEuZ2rFvdcpg87GjUplsPttbB0?= =?us-ascii?Q?uZp6EoTqhNWdEAujMdGgbQ0lfMAvGT1Kk12GgLs26jLpxc1yE12o5YZ8HHMf?= =?us-ascii?Q?6RDPc/1pZ35q9FX5MyTTobnurog2JnJvy3M5eYgy/3IAsa+9TWTw+MdXZK9c?= =?us-ascii?Q?KJfgucE=3D?= x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:CH3PR12MB8233.namprd12.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(1800799024)(366016)(376014)(7416014)(38070700018); DIR:OUT; SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?74e+gHTDOXk5/App5/Z9pyGc2xJP1a0Id5mxeF/FWbOOPanFTvJmu2RpxYKp?= =?us-ascii?Q?rXNzMcQio93I52i9N7Cu+0THdK8FHxjhotgsj2zzEWK3Q4aBVlNayeLMDjpk?= =?us-ascii?Q?BJnty6xs1VELbbJn5Fhi9rzVgIzTviQsRHuOMZs8nr4cEBqjOZ6qUWzIuTAw?= =?us-ascii?Q?0y2rgqJPYzyolcCllnPxU2L9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M7oTosVDG8rFHRFbw5pGWPBLbH+Qwewz5rgXcezk4Bbnd8R4NwQD83+f?= =?us-ascii?Q?nYfaXRd+ySS8RB4uRND9Bv0G2Xbx8SGV2DVu6X71P86pjqDsPWXanDvpdwAd?= =?us-ascii?Q?UFoojkxYUQUiXec9nT3jGak4A9hKMd0x6N14PfZvjsriMwgsRTwMowj/0vv+?= =?us-ascii?Q?2pUTyfHVLN4ssZ7umVnYkCi6diRazADcmRpk8or3e1grvkGHcwm8QJ5VcIzU?= =?us-ascii?Q?rBG/XGwEeCxY3ro8YpWj2fcWqDmDeZpPSjE3+HzjkdkhAA6OReygaQVDBhOM?= =?us-ascii?Q?X6JiDx4MwYkDS450XZ7G9XHQ0c5r7u+4OjN40TvT2Jlx3TUW24yQOwiMyVUo?= =?us-ascii?Q?j0+UjosqJJ1I3z/mkRU4HVXsrnCMjePVbH2vSC6icmR9dMjxlvwKxy0Rl9rg?= =?us-ascii?Q?PO/WzMgHjId+mcvzvpyIvp7KIYqZAy/5bg2s9dJ2y9KYyHkfxjize6U68JDe?= =?us-ascii?Q?wpq3/MlqQxI5fcLmsXM=3D?= Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: CH3PR12MB8233.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6e282aa9-eeeb-4157-a7c6-08dcf7dd558c X-MS-Exchange-CrossTenant-originalarrivaltime: 29 Oct 2024 05:48:37.4721 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: TDYK3EJuy3VbtdZHAQ5tx6/EYUUzxh4pwJguf2Csa/7Ufs49013j1/pJRoz2ECodtuUkfoEKWfIzp5bwIDF91Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB7584 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 [AMD Official Use Only - AMD Internal Distribution Only] Hi Huisong, LGTM! > -----Original Message----- > From: Huisong Li > Sent: Friday, October 25, 2024 2:49 PM > To: dev@dpdk.org > Cc: mb@smartsharesystems.com; thomas@monjalon.net; Yigit, Ferruh > ; anatoly.burakov@intel.com; david.hunt@intel.com; > Tummala, Sivaprasad ; > stephen@networkplumber.org; konstantin.ananyev@huawei.com; > david.marchand@redhat.com; fengchengwen@huawei.com; > liuyonglong@huawei.com; lihuisong@huawei.com > Subject: [PATCH v13 2/3] examples/l3fwd-power: fix data overflow when par= se > command line > > Caution: This message originated from an External Source. Use proper caut= ion > when opening attachments, clicking links, or responding. > > > Many variables are 'uint32_t', like, 'pause_duration', 'scale_freq_min' > and so on. They use parse_int() to parse it from command line. > But overflow problem occurs when this function return. > > Fixes: 59f2853c4cae ("examples/l3fwd_power: add configuration options") > Cc: stable@dpdk.org > > Signed-off-by: Huisong Li > Acked-by: Konstantin Ananyev > --- > examples/l3fwd-power/main.c | 36 ++++++++++++++++-------------------- > 1 file changed, 16 insertions(+), 20 deletions(-) > > diff --git a/examples/l3fwd-power/main.c b/examples/l3fwd-power/main.c in= dex > 2bb6b092c3..0ce4aa04d4 100644 > --- a/examples/l3fwd-power/main.c > +++ b/examples/l3fwd-power/main.c > @@ -1525,7 +1525,7 @@ print_usage(const char *prgname) } > > static int > -parse_int(const char *opt) > +parse_uint32(const char *opt, uint32_t *res) > { > char *end =3D NULL; > unsigned long val; > @@ -1535,23 +1535,14 @@ parse_int(const char *opt) > if ((opt[0] =3D=3D '\0') || (end =3D=3D NULL) || (*end !=3D '\0')= ) > return -1; > > - return val; > -} > - > -static int parse_max_pkt_len(const char *pktlen) -{ > - char *end =3D NULL; > - unsigned long len; > - > - /* parse decimal string */ > - len =3D strtoul(pktlen, &end, 10); > - if ((pktlen[0] =3D=3D '\0') || (end =3D=3D NULL) || (*end !=3D '\= 0')) > + if (val > UINT32_MAX) { > + RTE_LOG(ERR, L3FWD_POWER, "parameter shouldn't exceed > + %u.\n", UINT32_MAX); > return -1; > + } > > - if (len =3D=3D 0) > - return -1; > + *res =3D val; > > - return len; > + return 0; > } > > static int > @@ -1898,8 +1889,9 @@ parse_args(int argc, char **argv) > if (!strncmp(lgopts[option_index].name, > CMD_LINE_OPT_MAX_PKT_LEN, > sizeof(CMD_LINE_OPT_MAX_PKT_LEN))= ) { > + if (parse_uint32(optarg, &max_pkt_len) != =3D 0) > + return -1; > printf("Custom frame size is configured\n= "); > - max_pkt_len =3D parse_max_pkt_len(optarg)= ; > } > > if (!strncmp(lgopts[option_index].name, > @@ -1912,29 +1904,33 @@ parse_args(int argc, char **argv) > if (!strncmp(lgopts[option_index].name, > CMD_LINE_OPT_MAX_EMPTY_POLLS, > sizeof(CMD_LINE_OPT_MAX_EMPTY_POL= LS))) { > + if (parse_uint32(optarg, &max_empty_polls= ) !=3D 0) > + return -1; > printf("Maximum empty polls configured\n"= ); > - max_empty_polls =3D parse_int(optarg); > } > > if (!strncmp(lgopts[option_index].name, > CMD_LINE_OPT_PAUSE_DURATION, > sizeof(CMD_LINE_OPT_PAUSE_DURATIO= N))) { > + if (parse_uint32(optarg, &pause_duration)= !=3D 0) > + return -1; > printf("Pause duration configured\n"); > - pause_duration =3D parse_int(optarg); > } > > if (!strncmp(lgopts[option_index].name, > CMD_LINE_OPT_SCALE_FREQ_MIN, > sizeof(CMD_LINE_OPT_SCALE_FREQ_MI= N))) { > + if (parse_uint32(optarg, &scale_freq_min)= !=3D 0) > + return -1; > printf("Scaling frequency minimum configu= red\n"); > - scale_freq_min =3D parse_int(optarg); > } > > if (!strncmp(lgopts[option_index].name, > CMD_LINE_OPT_SCALE_FREQ_MAX, > sizeof(CMD_LINE_OPT_SCALE_FREQ_MA= X))) { > + if (parse_uint32(optarg, &scale_freq_max)= !=3D 0) > + return -1; > printf("Scaling frequency maximum configu= red\n"); > - scale_freq_max =3D parse_int(optarg); > } > > break; > -- > 2.22.0 Acked-by: Sivaprasad Tummala