PCI / PM: check all fields in pci_set_platform_pm()
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
@@ -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
Quoted 4 lines · Andy Shevchenko
When assign new PCI platform PM operations check for all mandatory fields to prevent NULL pointer dereference.
Signed-off-by Andy Shevchenko <[email protected]>
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@@ -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 ;
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.Signed-off-by Andy Shevchenko <[email protected]>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@@ -530,8 +530,8 @@ static const struct pci_platform_pm_ops *pci_platform_pm;
intpci_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_statedrivers/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
Quoted 13 lines · Andy Shevchenko
When assign new PCI platform PM operations check for all mandatory fields to prevent NULL pointer dereference.
Signed-off-by Andy Shevchenko <[email protected]>--- drivers/pci/pci.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/pci/pci.c +0
-0
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
-0pci_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
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.
Signed-off-by Andy Shevchenko <[email protected]>--- drivers/pci/pci.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/pci/pci.c +0
-0drivers/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()andplatform_pci_need_resume()assume that ifpci_platform_pmis set,pci_platform_pm->run_wakeandpci_platform_pm->need_resumeare valid function pointers. This is analogous to what we already do forops->is_manageable, etc.
Quoted 5 lines
Rafael, do you want to take this or should I?
Quoted 3 lines
drivers/pci/pci.c +0
-1pci_platform_pm = ops;return 0 ; --
I can take it.
Thanks,
Rafael