Skip to contentSkip to conversation

powerpc/powernv: Restrict OPAL symbol map to only be readable by root

PATCH Applied Andrew Donnellan 4 participants 8 messages May 3, 2019 – Aug 10, 2019

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

PATCH v2 1/1 powerpc/powernv: Restrict OPAL symbol map to only be readable by root

Currently the OPAL symbol map is globally readable, which seems bad as it contains physical addresses.

Restrict it to root.

Cc Jordan Niethe <[email protected]>
Cc Stewart Smith <[email protected]>
Fixes c8742f85125d ("powerpc/powernv: Expose OPAL firmware symbol map")

---

v1->v2:

- fix tabs vs spaces (Greg)

---
 arch/powerpc/platforms/powernv/opal.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
arch/powerpc/platforms/powernv/opal.c +7 -4
index 2b0eca104f86..0582a02623d0 100644
@@ -681,7 +681,10 @@ static ssize_t symbol_map_read(struct file *fp, struct kobject *kobj,
 				       bin_attr->size);
 }
 
-static BIN_ATTR_RO(symbol_map, 0);
+static struct bin_attribute symbol_map_attr = {
+	.attr = {.name = "symbol_map", .mode = 0400},
+	.read = symbol_map_read
+};
 
 static void opal_export_symmap(void)
 {
@@ -698,10 +701,10 @@ static void opal_export_symmap(void)
 		return;
 
 	/* Setup attributes */
-	bin_attr_symbol_map.private = __va(be64_to_cpu(syms[0]));
-	bin_attr_symbol_map.size = be64_to_cpu(syms[1]);
+	symbol_map_attr.private = __va(be64_to_cpu(syms[0]));
+	symbol_map_attr.size = be64_to_cpu(syms[1]);
 
-	rc = sysfs_create_bin_file(opal_kobj, &bin_attr_symbol_map);
+	rc = sysfs_create_bin_file(opal_kobj, &symbol_map_attr);
 	if (rc)
 		pr_warn("Error %d creating OPAL symbols file\n", rc);
 }
Signature · 1 line
2.20.1
maintainer
#1 lore raw
Quoted 26 lines · Andrew Donnellan

Currently the OPAL symbol map is globally readable, which seems bad as it contains physical addresses.

Restrict it to root.

Cc Jordan Niethe <[email protected]>
Cc Stewart Smith <[email protected]>
Fixes c8742f85125d ("powerpc/powernv: Expose OPAL firmware symbol map")

---

v1->v2:

- fix tabs vs spaces (Greg)

---
 arch/powerpc/platforms/powernv/opal.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
arch/powerpc/platforms/powernv/opal.c +0 -0
index 2b0eca104f86..0582a02623d0 100644

arch/powerpc/platforms/powernv/opal.c static ssize_t symbol_map_read(struct file *fp, struct kobject *kobj, · line 687

Quoted 8 lines
arch/powerpc/platforms/powernv/opal.c +4 -1
@@ -681,7 +681,10 @@ static ssize_t symbol_map_read(struct file *fp, struct kobject *kobj,
 				       bin_attr->size);
 }
 
-static BIN_ATTR_RO(symbol_map, 0);
+static struct bin_attribute symbol_map_attr = {
+	.attr = {.name = "symbol_map", .mode = 0400},
+	.read = symbol_map_read
+};

There's no real need to rename the structure, right? Why not just keep the bin_attr_symbol_map name? That would make this patch even smaller.

arch/powerpc/platforms/powernv/opal.c static void opal_export_symmap(void) · line 707

Quoted 13 lines
arch/powerpc/platforms/powernv/opal.c +3 -3
 static void opal_export_symmap(void)
 {
@@ -698,10 +701,10 @@ static void opal_export_symmap(void)
 		return;
 
 	/* Setup attributes */
-	bin_attr_symbol_map.private = __va(be64_to_cpu(syms[0]));
-	bin_attr_symbol_map.size = be64_to_cpu(syms[1]);
+	symbol_map_attr.private = __va(be64_to_cpu(syms[0]));
+	symbol_map_attr.size = be64_to_cpu(syms[1]);
 
-	rc = sysfs_create_bin_file(opal_kobj, &bin_attr_symbol_map);
+	rc = sysfs_create_bin_file(opal_kobj, &symbol_map_attr);

Meta-comment, odds are you are racing userspace when you create this sysfs file, why not add it to the device's default attributes so the driver core creates it for you at the correct time?

thanks,

greg k-h

#2 lore raw

On 3/5/19 5:59 pm, Greg KH wrote:>> -static BIN_ATTR_RO(symbol_map, 0);

Quoted 7 lines

arch/powerpc/platforms/powernv/opal.c static ssize_t symbol_map_read(struct file *fp, struct kobject *kobj, · line 687

Quoted 4 lines
arch/powerpc/platforms/powernv/opal.c +4 -0
+static struct bin_attribute symbol_map_attr = {
+	.attr = {.name = "symbol_map", .mode = 0400},
+	.read = symbol_map_read
+};

There's no real need to rename the structure, right? Why not just keep the bin_attr_symbol_map name? That would make this patch even smaller.

No real need but it's locally more consistent with the rest of the PPC code. (Though perhaps the other cases should use the BIN_ATTR macro...)

Given this is for stable I'm happy to change that if the smaller patch is more acceptable.

Quoted 12 lines
Quoted 12 lines
  static void opal_export_symmap(void)
  {
arch/powerpc/platforms/powernv/opal.c +2 -2
@@ -698,10 +701,10 @@ static void opal_export_symmap(void)
  		return;
 
  	/* Setup attributes */
-	bin_attr_symbol_map.private = __va(be64_to_cpu(syms[0]));
-	bin_attr_symbol_map.size = be64_to_cpu(syms[1]);
+	symbol_map_attr.private = __va(be64_to_cpu(syms[0]));
+	symbol_map_attr.size = be64_to_cpu(syms[1]);
 
Quoted 6 lines

arch/powerpc/platforms/powernv/opal.c static void opal_export_symmap(void) · line 707

Quoted 2 lines
arch/powerpc/platforms/powernv/opal.c +1 -1
-	rc = sysfs_create_bin_file(opal_kobj, &bin_attr_symbol_map);
+	rc = sysfs_create_bin_file(opal_kobj, &symbol_map_attr);

Meta-comment, odds are you are racing userspace when you create this sysfs file, why not add it to the device's default attributes so the driver core creates it for you at the correct time?

I was not previously aware of default attributes...

Are we actually racing against userspace in a subsys initcall?

Signature · 2 lines
Andrew Donnellan              OzLabs, ADL Canberra
[email protected]             IBM Australia Limited
maintainer
#3 lore raw
Quoted 9 lines · Andrew Donnellan

On 3/5/19 5:59 pm, Greg KH wrote:>> -static BIN_ATTR_RO(symbol_map, 0);

Quoted 7 lines

arch/powerpc/platforms/powernv/opal.c static ssize_t symbol_map_read(struct file *fp, struct kobject *kobj, · line 687

Quoted 4 lines
arch/powerpc/platforms/powernv/opal.c +4 -0
+static struct bin_attribute symbol_map_attr = {
+	.attr = {.name = "symbol_map", .mode = 0400},
+	.read = symbol_map_read
+};

There's no real need to rename the structure, right? Why not just keep the bin_attr_symbol_map name? That would make this patch even smaller.

Quoted 5 lines

No real need but it's locally more consistent with the rest of the PPC code. (Though perhaps the other cases should use the BIN_ATTR macro...)

Given this is for stable I'm happy to change that if the smaller patch is more acceptable.

stable doesn't care, and if this is more consistent, that's fine with me, I didn't see the larger picture here, just providing unsolicited patch review :)

Quoted 16 lines
Quoted 7 lines
Quoted 7 lines
  static void opal_export_symmap(void)
  {
arch/powerpc/platforms/powernv/opal.c +0 -2
@@ -698,10 +701,10 @@ static void opal_export_symmap(void)
  		return;
  	/* Setup attributes */
-	bin_attr_symbol_map.private = __va(be64_to_cpu(syms[0]));
-	bin_attr_symbol_map.size = be64_to_cpu(syms[1]);
Quoted 8 lines

arch/powerpc/platforms/powernv/opal.c static void opal_export_symmap(void) · line 707

Quoted 4 lines
arch/powerpc/platforms/powernv/opal.c +3 -1
+	symbol_map_attr.private = __va(be64_to_cpu(syms[0]));
+	symbol_map_attr.size = be64_to_cpu(syms[1]);
-	rc = sysfs_create_bin_file(opal_kobj, &bin_attr_symbol_map);
+	rc = sysfs_create_bin_file(opal_kobj, &symbol_map_attr);

Meta-comment, odds are you are racing userspace when you create this sysfs file, why not add it to the device's default attributes so the driver core creates it for you at the correct time?

Quoted 3 lines

I was not previously aware of default attributes...

Are we actually racing against userspace in a subsys initcall?

You can be, if you subsys is a module :)

thanks,

greg k-h

#4 lore raw
Quoted 3 lines · Greg KH
Quoted 1 line

Are we actually racing against userspace in a subsys initcall?

You can be, if you subsys is a module :)

For various reasons, we don't compile core system firmware interfaces into modules... that could be an interesting exercise. :D

Signature · 2 lines
Andrew Donnellan              OzLabs, ADL Canberra
[email protected]             IBM Australia Limited
#5 lore raw
In reply to Andrew Donnellan
Quoted 11 lines · Andrew Donnellan

Currently the OPAL symbol map is globally readable, which seems bad as it contains physical addresses.

Restrict it to root.

Cc Jordan Niethe <[email protected]>
Cc Stewart Smith <[email protected]>
Fixes c8742f85125d ("powerpc/powernv: Expose OPAL firmware symbol map")

mpe: ping?

Quoted 41 lines

---

v1->v2:

- fix tabs vs spaces (Greg)

---
  arch/powerpc/platforms/powernv/opal.c | 11 +++++++----
  1 file changed, 7 insertions(+), 4 deletions(-)
arch/powerpc/platforms/powernv/opal.c +7 -4
index 2b0eca104f86..0582a02623d0 100644
@@ -681,7 +681,10 @@ static ssize_t symbol_map_read(struct file *fp, struct kobject *kobj,
  				       bin_attr->size);
  }
 
-static BIN_ATTR_RO(symbol_map, 0);
+static struct bin_attribute symbol_map_attr = {
+	.attr = {.name = "symbol_map", .mode = 0400},
+	.read = symbol_map_read
+};
 
  static void opal_export_symmap(void)
  {
@@ -698,10 +701,10 @@ static void opal_export_symmap(void)
  		return;
 
  	/* Setup attributes */
-	bin_attr_symbol_map.private = __va(be64_to_cpu(syms[0]));
-	bin_attr_symbol_map.size = be64_to_cpu(syms[1]);
+	symbol_map_attr.private = __va(be64_to_cpu(syms[0]));
+	symbol_map_attr.size = be64_to_cpu(syms[1]);
 
-	rc = sysfs_create_bin_file(opal_kobj, &bin_attr_symbol_map);
+	rc = sysfs_create_bin_file(opal_kobj, &symbol_map_attr);
  	if (rc)
  		pr_warn("Error %d creating OPAL symbols file\n", rc);
  }
Signature · 2 lines
Andrew Donnellan              OzLabs, ADL Canberra
[email protected]             IBM Australia Limited
#6 lore raw
Quoted 6 lines · Andrew Donnellan
Quoted 5 lines · Andrew Donnellan

Currently the OPAL symbol map is globally readable, which seems bad as it contains physical addresses.

Restrict it to root.

Quoted 8 lines
Quoted 6 lines
Cc Jordan Niethe <[email protected]>
Cc Stewart Smith <[email protected]>
Fixes c8742f85125d ("powerpc/powernv: Expose OPAL firmware symbol map")

mpe: ping?

Picked up for v5.4.

cheers

#7 lore raw
In reply to Andrew Donnellan
Quoted 11 lines · Andrew Donnellan

Currently the OPAL symbol map is globally readable, which seems bad as it contains physical addresses.

Restrict it to root.

Cc Jordan Niethe <[email protected]>
Cc Stewart Smith <[email protected]>
Fixes c8742f85125d ("powerpc/powernv: Expose OPAL firmware symbol map")

Applied to powerpc next, thanks.

https://git.kernel.org/powerpc/c/e7de4f7b64c23e503a8c42af98d56f2a7462bd6d

cheers