Skip to contentSkip to conversation

x86: eas should not be NULL when it is referenced

PATCH Applied [email protected] 5 participants 8 messages Jun 24, 2021 – Jul 5, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86: eas should not be NULL when it is referenced

From: gushengxian <[email protected]>

"eas" should not be NULL when it is referenced.

---
 arch/x86/events/intel/uncore_snbep.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
arch/x86/events/intel/uncore_snbep.c +4 -2
index bb6eb1e5569c..836aa78cd0f3 100644
@@ -3826,8 +3826,10 @@ pmu_iio_set_mapping(struct intel_uncore_type *type, struct attribute_group *ag)
 
 	return 0;
 err:
-	for (; die >= 0; die--)
-		kfree(eas[die].attr.attr.name);
+	if (eas) {
+		for (; die >= 0; die--)
+			kfree(eas[die].attr.attr.name);
+	}
 	kfree(eas);
 	kfree(attrs);
 	kfree(type->topology);
Signature · 1 line
2.25.1
maintainer
#1 lore raw
Quoted 1 line · On Thu, Jun 24, 2021 at 12:04:42AM -0700, [email protected] wrote:

From: gushengxian <[email protected]>

Is ^^^ that you? That is, [email protected] is a bit of a dodgy email address and i've no way of verifying you are the person responsible for the patch.

Could you, if at all possible, please send patches from your yulong.com account such that we have at least a coherent chain of custody?

#2 lore raw
In reply to [email protected]

Hi Shengxian,

Thanks for the patch.

Quoted 4 lines · On 6/24/2021 3:04 AM, [email protected] wrote:

From: gushengxian <[email protected]>

"eas" should not be NULL when it is referenced.

I think the NULL pointer dereference of eas should not happen, because die is -1 if eas is NULL. But the whole error handling path looks fragile.

We already fixed one issue caused by it in commit ID f797f05d917f ("perf/x86/intel/uncore: Fix for iio mapping on Skylake Server")
https://lore.kernel.org/lkml/160149233331.7002.10919231011379055356.tip-bot2@tip-bot2/

Maybe something as below?

From 3de81ba3b04262ef3346297d82f6c4ffb4af7029 Mon Sep 17 00:00:00 2001
From: Kan Liang <[email protected]>
Date: Thu, 24 Jun 2021 11:17:57 -0700
Subject: [PATCH] perf/x86/intel/uncore: Clean up error handling path of iio mapping

The error handling path of iio mapping looks fragile. We already fixed one issue caused by it, commit ID f797f05d917f ("perf/x86/intel/uncore:
Fix for iio mapping on Skylake Server"). Clean up the error handling path and make the code robust.

---
 arch/x86/events/intel/uncore_snbep.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
arch/x86/events/intel/uncore_snbep.c +4 -2
index 7622762..6d4a5a9 100644
@@ -3802,11 +3802,11 @@ pmu_iio_set_mapping(struct intel_uncore_type *type, struct attribute_group *ag)
 	/* One more for NULL. */
 	attrs = kcalloc((uncore_max_dies() + 1), sizeof(*attrs), GFP_KERNEL);
 	if (!attrs)
-		goto err;
+		goto clear_topology;
 
 	eas = kcalloc(uncore_max_dies(), sizeof(*eas), GFP_KERNEL);
 	if (!eas)
-		goto err;
+		goto clear_attrs;
 
 	for (die = 0; die < uncore_max_dies(); die++) {
 		sprintf(buf, "die%ld", die);
@@ -3827,7 +3827,9 @@ pmu_iio_set_mapping(struct intel_uncore_type *type, struct attribute_group *ag)
 	for (; die >= 0; die--)
 		kfree(eas[die].attr.attr.name);
 	kfree(eas);
+clear_attrs:
 	kfree(attrs);
+clear_topology:
 	kfree(type->topology);
 clear_attr_update:
 	type->attr_update = NULL;
Signature · 3 lines
2.7.4
Thanks,
Kan
#3 lore raw

Oops, forgot to add Peter.

Quoted 65 lines · Kan

Hi Shengxian,

Thanks for the patch.

Quoted 4 lines · On 6/24/2021 3:04 AM, [email protected] wrote:

From: gushengxian <[email protected]>

"eas" should not be NULL when it is referenced.

I think the NULL pointer dereference of eas should not happen, because die is -1 if eas is NULL. But the whole error handling path looks fragile.

We already fixed one issue caused by it in commit ID f797f05d917f ("perf/x86/intel/uncore: Fix for iio mapping on Skylake Server")
https://lore.kernel.org/lkml/160149233331.7002.10919231011379055356.tip-bot2@tip-bot2/

Maybe something as below?

From 3de81ba3b04262ef3346297d82f6c4ffb4af7029 Mon Sep 17 00:00:00 2001
From: Kan Liang <[email protected]>
Date: Thu, 24 Jun 2021 11:17:57 -0700
Subject: [PATCH] perf/x86/intel/uncore: Clean up error handling path of iio mapping

The error handling path of iio mapping looks fragile. We already fixed one issue caused by it, commit ID f797f05d917f ("perf/x86/intel/uncore:
Fix for iio mapping on Skylake Server"). Clean up the error handling path and make the code robust.

---
  arch/x86/events/intel/uncore_snbep.c | 6 ++++--
  1 file changed, 4 insertions(+), 2 deletions(-)
arch/x86/events/intel/uncore_snbep.c +2 -2
index 7622762..6d4a5a9 100644
@@ -3802,11 +3802,11 @@ pmu_iio_set_mapping(struct intel_uncore_type 
 *type, struct attribute_group *ag)
      /* One more for NULL. */
      attrs = kcalloc((uncore_max_dies() + 1), sizeof(*attrs), GFP_KERNEL);
      if (!attrs)
-        goto err;
+        goto clear_topology;
 
      eas = kcalloc(uncore_max_dies(), sizeof(*eas), GFP_KERNEL);
      if (!eas)
-        goto err;
+        goto clear_attrs;
 
      for (die = 0; die < uncore_max_dies(); die++) {

         sprintf(buf, "die%ld", die);

arch/x86/events/intel/uncore_snbep.c +2 -0
@@ -3827,7 +3827,9 @@ pmu_iio_set_mapping(struct intel_uncore_type 
 *type, struct attribute_group *ag)
      for (; die >= 0; die--)
          kfree(eas[die].attr.attr.name);
      kfree(eas);
+clear_attrs:
      kfree(attrs);
+clear_topology:
      kfree(type->topology);
  clear_attr_update:

     type->attr_update = NULL;

#4 lore raw

Hello Kan,

Quoted 14 lines · Kan
Quoted 13 lines

I think the NULL pointer dereference of eas should not happen, because die is -1 if eas is NULL. But the whole error handling path looks fragile.

We already fixed one issue caused by it in commit ID f797f05d917f ("perf/x86/intel/uncore: Fix for iio mapping on Skylake Server")
https://lore.kernel.org/lkml/160149233331.7002.10919231011379055356.tip-bot2@tip-bot2/

Maybe something as below?

 From 3de81ba3b04262ef3346297d82f6c4ffb4af7029 Mon Sep 17 00:00:00 2001
From: Kan Liang <[email protected]>
Date: Thu, 24 Jun 2021 11:17:57 -0700
Subject: [PATCH] perf/x86/intel/uncore: Clean up error handling path of iio mapping

Quoted 4 lines
Quoted 4 lines

The error handling path of iio mapping looks fragile. We already fixed one issue caused by it, commit ID f797f05d917f ("perf/x86/intel/uncore:
Fix for iio mapping on Skylake Server"). Clean up the error handling path and make the code robust.

I didn't catch why does the current error handling path look fragile? Are there cases when it works incorrect?

Thanks,
Alexander

Quoted 37 lines
Quoted 37 lines

---
  arch/x86/events/intel/uncore_snbep.c | 6 ++++--

  1 file changed, 4 insertions(+), 2 deletions(-)
arch/x86/events/intel/uncore_snbep.c +2 -2
index 7622762..6d4a5a9 100644
@@ -3802,11 +3802,11 @@ pmu_iio_set_mapping(struct intel_uncore_type 
 *type, struct attribute_group *ag)
       /* One more for NULL. */
       attrs = kcalloc((uncore_max_dies() + 1), sizeof(*attrs), GFP_KERNEL);
       if (!attrs)
-        goto err;
+        goto clear_topology;
 
       eas = kcalloc(uncore_max_dies(), sizeof(*eas), GFP_KERNEL);
       if (!eas)
-        goto err;
+        goto clear_attrs;
 
       for (die = 0; die < uncore_max_dies(); die++) {

          sprintf(buf, "die%ld", die);

arch/x86/events/intel/uncore_snbep.c +2 -0
@@ -3827,7 +3827,9 @@ pmu_iio_set_mapping(struct intel_uncore_type 
 *type, struct attribute_group *ag)
       for (; die >= 0; die--)
           kfree(eas[die].attr.attr.name);
       kfree(eas);
+clear_attrs:
       kfree(attrs);
+clear_topology:
       kfree(type->topology);

  clear_attr_update:
      type->attr_update = NULL;

#5 lore raw
Quoted 15 lines · Alexander Antonov

Hello Kan,

Quoted 14 lines · Kan
Quoted 13 lines

I think the NULL pointer dereference of eas should not happen, because die is -1 if eas is NULL. But the whole error handling path looks fragile.

We already fixed one issue caused by it in commit ID f797f05d917f ("perf/x86/intel/uncore: Fix for iio mapping on Skylake Server")
https://lore.kernel.org/lkml/160149233331.7002.10919231011379055356.tip-bot2@tip-bot2/

Maybe something as below?

 From 3de81ba3b04262ef3346297d82f6c4ffb4af7029 Mon Sep 17 00:00:00 2001
From: Kan Liang <[email protected]>
Date: Thu, 24 Jun 2021 11:17:57 -0700
Subject: [PATCH] perf/x86/intel/uncore: Clean up error handling path of iio mapping

Quoted 7 lines
Quoted 4 lines
Quoted 4 lines

The error handling path of iio mapping looks fragile. We already fixed one issue caused by it, commit ID f797f05d917f ("perf/x86/intel/uncore:
Fix for iio mapping on Skylake Server"). Clean up the error handling path and make the code robust.

I didn't catch why does the current error handling path look fragile? Are there cases when it works incorrect?

I don't think it causes any severe problem for now, e.g., crash, because current code checks die before the dereference. But I think it violates the Linux kernel coding style (one err bug) and may bring potential issues.

https://www.kernel.org/doc/html/v4.10/process/coding-style.html

Thanks,
Kan

Quoted 39 lines

Thanks,
Alexander

Quoted 37 lines
Quoted 37 lines

---
  arch/x86/events/intel/uncore_snbep.c | 6 ++++--

  1 file changed, 4 insertions(+), 2 deletions(-)
arch/x86/events/intel/uncore_snbep.c +2 -2
index 7622762..6d4a5a9 100644
@@ -3802,11 +3802,11 @@ pmu_iio_set_mapping(struct intel_uncore_type 
 *type, struct attribute_group *ag)
       /* One more for NULL. */
       attrs = kcalloc((uncore_max_dies() + 1), sizeof(*attrs), GFP_KERNEL);
       if (!attrs)
-        goto err;
+        goto clear_topology;
 
       eas = kcalloc(uncore_max_dies(), sizeof(*eas), GFP_KERNEL);
       if (!eas)
-        goto err;
+        goto clear_attrs;
 
       for (die = 0; die < uncore_max_dies(); die++) {

          sprintf(buf, "die%ld", die);

arch/x86/events/intel/uncore_snbep.c +2 -0
@@ -3827,7 +3827,9 @@ pmu_iio_set_mapping(struct intel_uncore_type 
 *type, struct attribute_group *ag)
       for (; die >= 0; die--)
           kfree(eas[die].attr.attr.name);
       kfree(eas);
+clear_attrs:
       kfree(attrs);
+clear_topology:
       kfree(type->topology);

  clear_attr_update:
      type->attr_update = NULL;

#6 lore raw
Quoted 27 lines · Kan
Quoted 15 lines · Alexander Antonov

Hello Kan,

Quoted 14 lines · Kan
Quoted 13 lines

I think the NULL pointer dereference of eas should not happen, because die is -1 if eas is NULL. But the whole error handling path looks fragile.

We already fixed one issue caused by it in commit ID f797f05d917f ("perf/x86/intel/uncore: Fix for iio mapping on Skylake Server")
https://lore.kernel.org/lkml/160149233331.7002.10919231011379055356.tip-bot2@tip-bot2/

Maybe something as below?

 From 3de81ba3b04262ef3346297d82f6c4ffb4af7029 Mon Sep 17 00:00:00 2001
From: Kan Liang <[email protected]>
Date: Thu, 24 Jun 2021 11:17:57 -0700
Subject: [PATCH] perf/x86/intel/uncore: Clean up error handling path of iio mapping

Quoted 7 lines
Quoted 4 lines
Quoted 4 lines

The error handling path of iio mapping looks fragile. We already fixed one issue caused by it, commit ID f797f05d917f ("perf/x86/intel/uncore:
Fix for iio mapping on Skylake Server"). Clean up the error handling path and make the code robust.

I didn't catch why does the current error handling path look fragile? Are there cases when it works incorrect?

Quoted 7 lines

I don't think it causes any severe problem for now, e.g., crash, because current code checks die before the dereference. But I think it violates the Linux kernel coding style (one err bug) and may bring potential issues.

https://www.kernel.org/doc/html/v4.10/process/coding-style.html

Thanks,
Kan

OK,
Thank you for the explanation.

- Alexander

Quoted 40 lines
Quoted 40 lines

Thanks,
Alexander

Quoted 37 lines
Quoted 37 lines

---
  arch/x86/events/intel/uncore_snbep.c | 6 ++++--

  1 file changed, 4 insertions(+), 2 deletions(-)
arch/x86/events/intel/uncore_snbep.c +2 -2
index 7622762..6d4a5a9 100644
@@ -3802,11 +3802,11 @@ pmu_iio_set_mapping(struct 
 intel_uncore_type *type, struct attribute_group *ag)
       /* One more for NULL. */
       attrs = kcalloc((uncore_max_dies() + 1), sizeof(*attrs), GFP_KERNEL);
       if (!attrs)
-        goto err;
+        goto clear_topology;
 
       eas = kcalloc(uncore_max_dies(), sizeof(*eas), GFP_KERNEL);
       if (!eas)
-        goto err;
+        goto clear_attrs;
 
       for (die = 0; die < uncore_max_dies(); die++) {

          sprintf(buf, "die%ld", die);

arch/x86/events/intel/uncore_snbep.c +2 -0
@@ -3827,7 +3827,9 @@ pmu_iio_set_mapping(struct intel_uncore_type 
 *type, struct attribute_group *ag)
       for (; die >= 0; die--)
           kfree(eas[die].attr.attr.name);
       kfree(eas);
+clear_attrs:
       kfree(attrs);
+clear_topology:
       kfree(type->topology);

  clear_attr_update:
      type->attr_update = NULL;

merge bot Applied
#7 lore raw

[tip: perf/urgent] perf/x86/intel/uncore: Clean up error handling path of iio mapping

In reply to Liang, Kan
The following commit has been merged into the perf/urgent branch of tip:

The following commit has been merged into the perf/urgent branch of tip:

Commit-ID:     d4ba0b06306a70c99a43f9d452886a86e2d3bd26
Gitweb:        https://git.kernel.org/tip/d4ba0b06306a70c99a43f9d452886a86e2d3bd26
Author:        Kan Liang <[email protected]>
AuthorDate:    Thu, 24 Jun 2021 11:17:57 -07:00
Committer:     Peter Zijlstra <[email protected]>
CommitterDate: Fri, 02 Jul 2021 15:58:33 +02:00

perf/x86/intel/uncore: Clean up error handling path of iio mapping

The error handling path of iio mapping looks fragile. We already fixed one issue caused by it, commit f797f05d917f ("perf/x86/intel/uncore:
Fix for iio mapping on Skylake Server"). Clean up the error handling path and make the code robust.

---
 arch/x86/events/intel/uncore_snbep.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
arch/x86/events/intel/uncore_snbep.c +4 -2
index 3a75a2c..1f7bb48 100644
@@ -3789,11 +3789,11 @@ static int skx_iio_set_mapping(struct intel_uncore_type *type)
 	/* One more for NULL. */
 	attrs = kcalloc((uncore_max_dies() + 1), sizeof(*attrs), GFP_KERNEL);
 	if (!attrs)
-		goto err;
+		goto clear_topology;
 
 	eas = kcalloc(uncore_max_dies(), sizeof(*eas), GFP_KERNEL);
 	if (!eas)
-		goto err;
+		goto clear_attrs;
 
 	for (die = 0; die < uncore_max_dies(); die++) {
 		sprintf(buf, "die%ld", die);
@@ -3814,7 +3814,9 @@ err:
 	for (; die >= 0; die--)
 		kfree(eas[die].attr.attr.name);
 	kfree(eas);
+clear_attrs:
 	kfree(attrs);
+clear_topology:
 	kfree(type->topology);
 clear_attr_update:
 	type->attr_update = NULL;