* [PATCH 0/2] cxl/region: Fix a couple memory safety bugs
@ 2022-12-15 1:33 Dan Williams
2022-12-15 1:33 ` [PATCH 1/2] cxl/region: Fix memdev_filter_pos() memory leak Dan Williams
2022-12-15 1:33 ` [PATCH 2/2] cxl/region: Fix memdev_filter_pos() separator detection Dan Williams
0 siblings, 2 replies; 5+ messages in thread
From: Dan Williams @ 2022-12-15 1:33 UTC (permalink / raw)
To: vishal.l.verma; +Cc: Luis Chamberlain, linux-cxl
memdev_filter_pos() has 2 issues surfaced by unit testing, a leak, and
incorrect sort results.
---
Dan Williams (2):
cxl/region: Fix memdev_filter_pos() memory leak
cxl/region: Fix memdev_filter_pos() separator detection
cxl/region.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 1/2] cxl/region: Fix memdev_filter_pos() memory leak
2022-12-15 1:33 [PATCH 0/2] cxl/region: Fix a couple memory safety bugs Dan Williams
@ 2022-12-15 1:33 ` Dan Williams
2022-12-16 4:08 ` Alison Schofield
2022-12-15 1:33 ` [PATCH 2/2] cxl/region: Fix memdev_filter_pos() separator detection Dan Williams
1 sibling, 1 reply; 5+ messages in thread
From: Dan Williams @ 2022-12-15 1:33 UTC (permalink / raw)
To: vishal.l.verma; +Cc: linux-cxl
Arrange to free the temporary duplicate of @_csv in all exit paths. Just
share a common exit path.
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
---
cxl/region.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/cxl/region.c b/cxl/region.c
index 15cac64a158c..2202afa440ef 100644
--- a/cxl/region.c
+++ b/cxl/region.c
@@ -183,7 +183,7 @@ static int memdev_filter_pos(struct json_object *jobj, const char *_csv)
for (pos = 0, arg = strtok_r(csv, which_sep(csv), &save); arg;
arg = strtok_r(NULL, which_sep(csv), &save), pos++)
if (util_cxl_memdev_filter(memdev, arg, NULL))
- return pos;
+ break;
free(csv);
return pos;
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 2/2] cxl/region: Fix memdev_filter_pos() separator detection
2022-12-15 1:33 [PATCH 0/2] cxl/region: Fix a couple memory safety bugs Dan Williams
2022-12-15 1:33 ` [PATCH 1/2] cxl/region: Fix memdev_filter_pos() memory leak Dan Williams
@ 2022-12-15 1:33 ` Dan Williams
2022-12-16 4:06 ` Alison Schofield
1 sibling, 1 reply; 5+ messages in thread
From: Dan Williams @ 2022-12-15 1:33 UTC (permalink / raw)
To: vishal.l.verma; +Cc: Luis Chamberlain, linux-cxl
Stop using the modified version of the @_csv as the string to determine
the separator it may cause which_sep() to get different answers each
iteration. Moreover there is no need to retrieve the separator each
iteration, so just retrieve it once from @_csv.
If the separator is mismatched it can lead to the sort not following the
specified device order for create-region.
Reported-by: Luis Chamberlain <mcgrof@kernel.org>
Link: https://gist.github.com/mcgrof/aeac639365a651bd77f143cf38eb7493
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
---
cxl/region.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/cxl/region.c b/cxl/region.c
index 2202afa440ef..bb3a10a7713c 100644
--- a/cxl/region.c
+++ b/cxl/region.c
@@ -172,6 +172,7 @@ static struct sort_context {
static int memdev_filter_pos(struct json_object *jobj, const char *_csv)
{
struct cxl_memdev *memdev = json_object_get_userdata(jobj);
+ const char *sep = which_sep(_csv);
char *csv, *save;
const char *arg;
int pos;
@@ -180,8 +181,8 @@ static int memdev_filter_pos(struct json_object *jobj, const char *_csv)
if (!csv)
return -1;
- for (pos = 0, arg = strtok_r(csv, which_sep(csv), &save); arg;
- arg = strtok_r(NULL, which_sep(csv), &save), pos++)
+ for (pos = 0, arg = strtok_r(csv, sep, &save); arg;
+ arg = strtok_r(NULL, sep, &save), pos++)
if (util_cxl_memdev_filter(memdev, arg, NULL))
break;
free(csv);
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 2/2] cxl/region: Fix memdev_filter_pos() separator detection
2022-12-15 1:33 ` [PATCH 2/2] cxl/region: Fix memdev_filter_pos() separator detection Dan Williams
@ 2022-12-16 4:06 ` Alison Schofield
0 siblings, 0 replies; 5+ messages in thread
From: Alison Schofield @ 2022-12-16 4:06 UTC (permalink / raw)
To: Dan Williams; +Cc: vishal.l.verma, Luis Chamberlain, linux-cxl
On Wed, Dec 14, 2022 at 05:33:57PM -0800, Dan Williams wrote:
> Stop using the modified version of the @_csv as the string to determine
> the separator it may cause which_sep() to get different answers each
> iteration. Moreover there is no need to retrieve the separator each
> iteration, so just retrieve it once from @_csv.
>
> If the separator is mismatched it can lead to the sort not following the
> specified device order for create-region.
>
Tested-by: Alison Schofield <alison.schofield@intel.com>
> Reported-by: Luis Chamberlain <mcgrof@kernel.org>
> Link: https://gist.github.com/mcgrof/aeac639365a651bd77f143cf38eb7493
> Signed-off-by: Dan Williams <dan.j.williams@intel.com>
> ---
> cxl/region.c | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/cxl/region.c b/cxl/region.c
> index 2202afa440ef..bb3a10a7713c 100644
> --- a/cxl/region.c
> +++ b/cxl/region.c
> @@ -172,6 +172,7 @@ static struct sort_context {
> static int memdev_filter_pos(struct json_object *jobj, const char *_csv)
> {
> struct cxl_memdev *memdev = json_object_get_userdata(jobj);
> + const char *sep = which_sep(_csv);
> char *csv, *save;
> const char *arg;
> int pos;
> @@ -180,8 +181,8 @@ static int memdev_filter_pos(struct json_object *jobj, const char *_csv)
> if (!csv)
> return -1;
>
> - for (pos = 0, arg = strtok_r(csv, which_sep(csv), &save); arg;
> - arg = strtok_r(NULL, which_sep(csv), &save), pos++)
> + for (pos = 0, arg = strtok_r(csv, sep, &save); arg;
> + arg = strtok_r(NULL, sep, &save), pos++)
> if (util_cxl_memdev_filter(memdev, arg, NULL))
> break;
> free(csv);
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 1/2] cxl/region: Fix memdev_filter_pos() memory leak
2022-12-15 1:33 ` [PATCH 1/2] cxl/region: Fix memdev_filter_pos() memory leak Dan Williams
@ 2022-12-16 4:08 ` Alison Schofield
0 siblings, 0 replies; 5+ messages in thread
From: Alison Schofield @ 2022-12-16 4:08 UTC (permalink / raw)
To: Dan Williams; +Cc: vishal.l.verma, linux-cxl
On Wed, Dec 14, 2022 at 05:33:52PM -0800, Dan Williams wrote:
> Arrange to free the temporary duplicate of @_csv in all exit paths. Just
> share a common exit path.
>
Reviewed-by: Alison Schofield <alison.schofield@intel.com>
> Signed-off-by: Dan Williams <dan.j.williams@intel.com>
> ---
> cxl/region.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/cxl/region.c b/cxl/region.c
> index 15cac64a158c..2202afa440ef 100644
> --- a/cxl/region.c
> +++ b/cxl/region.c
> @@ -183,7 +183,7 @@ static int memdev_filter_pos(struct json_object *jobj, const char *_csv)
> for (pos = 0, arg = strtok_r(csv, which_sep(csv), &save); arg;
> arg = strtok_r(NULL, which_sep(csv), &save), pos++)
> if (util_cxl_memdev_filter(memdev, arg, NULL))
> - return pos;
> + break;
> free(csv);
>
> return pos;
>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2022-12-16 4:08 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-12-15 1:33 [PATCH 0/2] cxl/region: Fix a couple memory safety bugs Dan Williams
2022-12-15 1:33 ` [PATCH 1/2] cxl/region: Fix memdev_filter_pos() memory leak Dan Williams
2022-12-16 4:08 ` Alison Schofield
2022-12-15 1:33 ` [PATCH 2/2] cxl/region: Fix memdev_filter_pos() separator detection Dan Williams
2022-12-16 4:06 ` Alison Schofield
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox