blob: 755f5bc27ddc36ccdfd841a147a95a31abb18710 [file] [log] [blame]
Ting Xu4ba3c0a2022-05-05 09:12:50 +00001From 794d99b8abeeb401a374489a9e3c629d023c271f Mon Sep 17 00:00:00 2001
2From: Ting Xu <ting.xu@intel.com>
3Date: Fri, 4 Mar 2022 07:26:28 +0000
4Subject: [PATCH v2] net/ice: fix raw flow input pattern value change in FDIR
5
6When parsing raw flow pattern in FDIR, the input parameter spec and
7mask are used directly and the original value will be changed. It
8will cause error if these values are used in other functions. In this
9patch, temporary variables are created to store the spec and mask.
10
11Fixes: 25be39cc1760 ("net/ice: enable protocol agnostic flow offloading in FDIR")
12
13Cc: stable@dpdk.org
14
15Signed-off-by: Ting Xu <ting.xu@intel.com>
16---
17 drivers/net/ice/ice_fdir_filter.c | 25 +++++++++++++++++++------
18 1 file changed, 19 insertions(+), 6 deletions(-)
19
20diff --git a/drivers/net/ice/ice_fdir_filter.c b/drivers/net/ice/ice_fdir_filter.c
21index 7954c6d8ea..5ff1afac90 100644
22--- a/drivers/net/ice/ice_fdir_filter.c
23+++ b/drivers/net/ice/ice_fdir_filter.c
24@@ -1868,10 +1868,11 @@ ice_fdir_parse_pattern(__rte_unused struct ice_adapter *ad,
25 break;
26
27 /* convert raw spec & mask from byte string to int */
28- unsigned char *tmp_spec =
29+ unsigned char *spec_pattern =
30 (uint8_t *)(uintptr_t)raw_spec->pattern;
31- unsigned char *tmp_mask =
32+ unsigned char *mask_pattern =
33 (uint8_t *)(uintptr_t)raw_mask->pattern;
34+ uint8_t *tmp_spec, *tmp_mask;
35 uint16_t udp_port = 0;
36 uint16_t tmp_val = 0;
37 uint8_t pkt_len = 0;
38@@ -1883,8 +1884,18 @@ ice_fdir_parse_pattern(__rte_unused struct ice_adapter *ad,
39 pkt_len)
40 return -rte_errno;
41
42+ tmp_spec = rte_zmalloc(NULL, pkt_len / 2, 0);
43+ if (!tmp_spec)
44+ return -rte_errno;
45+
46+ tmp_mask = rte_zmalloc(NULL, pkt_len / 2, 0);
47+ if (!tmp_mask) {
48+ rte_free(tmp_spec);
49+ return -rte_errno;
50+ }
51+
52 for (i = 0, j = 0; i < pkt_len; i += 2, j++) {
53- tmp = tmp_spec[i];
54+ tmp = spec_pattern[i];
55 if (tmp >= 'a' && tmp <= 'f')
56 tmp_val = tmp - 'a' + 10;
57 if (tmp >= 'A' && tmp <= 'F')
58@@ -1893,7 +1904,7 @@ ice_fdir_parse_pattern(__rte_unused struct ice_adapter *ad,
59 tmp_val = tmp - '0';
60
61 tmp_val *= 16;
62- tmp = tmp_spec[i + 1];
63+ tmp = spec_pattern[i + 1];
64 if (tmp >= 'a' && tmp <= 'f')
65 tmp_spec[j] = tmp_val + tmp - 'a' + 10;
66 if (tmp >= 'A' && tmp <= 'F')
67@@ -1901,7 +1912,7 @@ ice_fdir_parse_pattern(__rte_unused struct ice_adapter *ad,
68 if (tmp >= '0' && tmp <= '9')
69 tmp_spec[j] = tmp_val + tmp - '0';
70
71- tmp = tmp_mask[i];
72+ tmp = mask_pattern[i];
73 if (tmp >= 'a' && tmp <= 'f')
74 tmp_val = tmp - 'a' + 10;
75 if (tmp >= 'A' && tmp <= 'F')
76@@ -1910,7 +1921,7 @@ ice_fdir_parse_pattern(__rte_unused struct ice_adapter *ad,
77 tmp_val = tmp - '0';
78
79 tmp_val *= 16;
80- tmp = tmp_mask[i + 1];
81+ tmp = mask_pattern[i + 1];
82 if (tmp >= 'a' && tmp <= 'f')
83 tmp_mask[j] = tmp_val + tmp - 'a' + 10;
84 if (tmp >= 'A' && tmp <= 'F')
85@@ -1953,6 +1964,8 @@ ice_fdir_parse_pattern(__rte_unused struct ice_adapter *ad,
86
87 filter->parser_ena = true;
88
89+ rte_free(tmp_spec);
90+ rte_free(tmp_mask);
91 break;
92 }
93
94--
952.17.1
96