Skip to contentSkip to conversation

PCI / PM: check all fields in pci_set_platform_pm()

PATCH In review Andy Shevchenko 4 participants 5 messages Jun 6, 2016 – Jul 19, 2016 PCI

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 PCI / PM: check all fields in pci_set_platform_pm()

When assign new PCI platform PM operations check for all mandatory fields to prevent NULL pointer dereference.

---
 drivers/pci/pci.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/pci/pci.c +2 -2
index c8b4dbd..badbddc 100644
@@ -530,8 +530,8 @@ static const struct pci_platform_pm_ops *pci_platform_pm;
 
 int pci_set_platform_pm(const struct pci_platform_pm_ops *ops)
 {
-	if (!ops->is_manageable || !ops->set_state || !ops->choose_state
-	    || !ops->sleep_wake)
+	if (!ops->is_manageable || !ops->set_state || !ops->choose_state ||
+	    !ops->sleep_wake || !ops->run_wake || !ops->need_resume)
 		return -EINVAL;
 	pci_platform_pm = ops;
 	return 0;
Signature · 1 line
2.8.1
#1 lore raw
Quoted 4 lines · Andy Shevchenko

When assign new PCI platform PM operations check for all mandatory fields to prevent NULL pointer dereference.

OK in principle, but what's the motivation?

Quoted 20 lines
---
 drivers/pci/pci.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/pci/pci.c +2 -2
index c8b4dbd..badbddc 100644
@@ -530,8 +530,8 @@ static const struct pci_platform_pm_ops *pci_platform_pm;
 
 int pci_set_platform_pm(const struct pci_platform_pm_ops *ops)
 {
-	if (!ops->is_manageable || !ops->set_state || !ops->choose_state
-	    || !ops->sleep_wake)
+	if (!ops->is_manageable || !ops->set_state || !ops->choose_state ||
+	    !ops->sleep_wake || !ops->run_wake || !ops->need_resume)
 		return -EINVAL;
 	pci_platform_pm = ops;
 	return 0;
#2 lore raw
Quoted 8 lines · Rafael J. Wysocki
Quoted 5 lines · Andy Shevchenko

When assign new PCI platform PM operations check for all mandatory fields to
prevent NULL pointer dereference.

OK in principle, but what's the motivation?

I didn't investigate the guts of the core code, but I'm about to add new module which will use these facilities. Since the module is slightly based on existing code for older kernels I noticed those new callbacks. To prevent potential NULL pointer dereference.

Quoted 25 lines
Quoted 24 lines

---
 drivers/pci/pci.c | 4 ++--

 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/pci/pci.c +0 -0
index c8b4dbd..badbddc 100644
@@ -530,8 +530,8 @@ static const struct pci_platform_pm_ops
 *pci_platform_pm;


 int pci_set_platform_pm(const struct pci_platform_pm_ops *ops) {

drivers/pci/pci.c +0 -1
-	if (!ops->is_manageable || !ops->set_state || !ops-
Quoted 1 line

choose_state

drivers/pci/pci.c +1 -1
-	    || !ops->sleep_wake)
+	if (!ops->is_manageable || !ops->set_state || !ops-
Quoted 1 line

choose_state ||

drivers/pci/pci.c +1 -0
+	    !ops->sleep_wake || !ops->run_wake || !ops-
Quoted 1 line

need_resume)

  return -EINVAL;
  pci_platform_pm = ops;
  return 0;

Signature · 2 lines
Andy Shevchenko <[email protected]>
Intel Finland Oy
#3 lore raw
In reply to Andy Shevchenko
Quoted 13 lines · Andy Shevchenko

When assign new PCI platform PM operations check for all mandatory fields to prevent NULL pointer dereference.

---
 drivers/pci/pci.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/pci/pci.c +0 -0
index c8b4dbd..badbddc 100644

drivers/pci/pci.c static const struct pci_platform_pm_ops *pci_platform_pm; · line 535

Quoted 8 lines
drivers/pci/pci.c +2 -2
@@ -530,8 +530,8 @@ static const struct pci_platform_pm_ops *pci_platform_pm;
 
 int pci_set_platform_pm(const struct pci_platform_pm_ops *ops)
 {
-	if (!ops->is_manageable || !ops->set_state || !ops->choose_state
-	    || !ops->sleep_wake)
+	if (!ops->is_manageable || !ops->set_state || !ops->choose_state ||
+	    !ops->sleep_wake || !ops->run_wake || !ops->need_resume)
 		return -EINVAL;

This looks OK to me. platform_pci_run_wake() and platform_pci_need_resume() assume that if pci_platform_pm is set, pci_platform_pm->run_wake and pci_platform_pm->need_resume are valid function pointers. This is analogous to what we already do for ops->is_manageable, etc.

Rafael, do you want to take this or should I?

Quoted 9 lines
drivers/pci/pci.c +0 -0
 	pci_platform_pm = ops;
 	return 0;
Signature · 6 lines
2.8.1

--
To unsubscribe from this list: send the line "unsubscribe linux-pci" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#4 lore raw
Quoted 29 lines · Bjorn Helgaas
Quoted 13 lines · Andy Shevchenko

When assign new PCI platform PM operations check for all mandatory fields to prevent NULL pointer dereference.

---
 drivers/pci/pci.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/pci/pci.c +0 -0
index c8b4dbd..badbddc 100644

drivers/pci/pci.c static const struct pci_platform_pm_ops *pci_platform_pm; · line 535

Quoted 8 lines
drivers/pci/pci.c +2 -2
@@ -530,8 +530,8 @@ static const struct pci_platform_pm_ops *pci_platform_pm;
 
 int pci_set_platform_pm(const struct pci_platform_pm_ops *ops)
 {
-     if (!ops->is_manageable || !ops->set_state || !ops->choose_state
-         || !ops->sleep_wake)
+     if (!ops->is_manageable || !ops->set_state || !ops->choose_state ||
+         !ops->sleep_wake || !ops->run_wake || !ops->need_resume)
              return -EINVAL;

This looks OK to me. platform_pci_run_wake() and platform_pci_need_resume() assume that if pci_platform_pm is set, pci_platform_pm->run_wake and pci_platform_pm->need_resume are valid function pointers. This is analogous to what we already do for ops->is_manageable, etc.

Quoted 5 lines

Rafael, do you want to take this or should I?

Quoted 3 lines
drivers/pci/pci.c +0 -1
      pci_platform_pm = ops;
      return 0;
--

I can take it.

Thanks,
Rafael