PCI: Prevent out of bounds access in numa_node override - part 2
PATCH v2 1/1 PCI: Prevent out of bounds access in numa_node override - part 2
Commit 1266963170f5 ("PCI: Prevent out of bounds access in numa_node override") missed that the user provided node could also be negative. Handle this case as well to avoid out-of-bounds accesses to the node_states[] array. However, allow the special value -1, i.e. NUMA_NO_NODE, to be able to set the 'no specific node' configuration.
---
v2: allow NUMA_NO_NODE
drivers/pci/pci-sysfs.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/pci/pci-sysfs.c +4 -1
@@ -216,7 +216,10 @@ static ssize_t numa_node_store(struct device *dev,if (ret)return ret; -if (node >=MAX_NUMNODES || !node_online (node)) +if (node <NUMA_NO_NODE || node >=MAX_NUMNODES ) +return -EINVAL ; + +if (node !=NUMA_NO_NODE && !node_online (node))return -EINVAL ;add_taint (TAINT_FIRMWARE_WORKAROUND ,LOCKDEP_STILL_OK );
Signature · 1 line
1.7.10.4
Bjorn Helgaas
AppliedQuoted 11 lines · Mathias Krause
Commit
1266963170f5("PCI: Prevent out of bounds access innuma_nodeoverride") missed that the user provided node could also be negative. Handle this case as well to avoid out-of-bounds accesses to the node_states[] array. However, allow the special value -1, i.e.NUMA_NO_NODE, to be able to set the 'no specific node' configuration.Fixes 1266963170f5 ("PCI: Prevent out of bounds access in numa_node...")Signed-off-by Mathias Krause <[email protected]>Cc Sasha Levin <[email protected]>Cc Prarit Bhargava <[email protected]>Cc [email protected] # v3.19+
Applied as tweaked below to for-linus for v4.4, thanks! As written, if NUMA_NO_NODE were defined as -2, we would incorrectly accept -1. Let me know if you disagree with my fix.
Quoted 12 lines
---
v2: allowNUMA_NO_NODEdrivers/pci/pci-sysfs.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)drivers/pci/pci-sysfs.c +0
-0@@ -216,7 +216,10 @@ static ssize_t numa_node_store(struct device *dev,if (ret)
drivers/pci/pci-sysfs.c static ssize_t numa_node_store(struct device *dev, · line 225
Quoted 10 lines
drivers/pci/pci-sysfs.c +4
-1return ret; -if (node >=MAX_NUMNODES || !node_online (node)) +if (node <NUMA_NO_NODE || node >=MAX_NUMNODES ) +return -EINVAL ; + +if (node !=NUMA_NO_NODE && !node_online (node))return -EINVAL ;add_taint (TAINT_FIRMWARE_WORKAROUND ,LOCKDEP_STILL_OK );
commit 2a35194c5a45fbb9ca1d88bc56804dfb51a75233
Author: Mathias Krause <[email protected]> Date: Mon Nov 9 20:00:27 2015 +0100
PCI: Prevent out of bounds access in numa_node override
Commit 1266963170f5 ("PCI: Prevent out of bounds access in numa_node override") missed that the user-provided node could also be negative. Handle this case as well to avoid out-of-bounds accesses to the node_states[] array. However, allow the special value -1, i.e. NUMA_NO_NODE, to be able to set the 'no specific node' configuration.
drivers/pci/pci-sysfs.c +6 -1
@@ -216,7 +216,12 @@ static ssize_t numa_node_store(struct device *dev,if (ret)return ret; -if (node >=MAX_NUMNODES || !node_online (node)) +if (node <0 || node >=MAX_NUMNODES ) { +if (node !=NUMA_NO_NODE ) +return -EINVAL ; + } + +if (node !=NUMA_NO_NODE && !node_online (node))return -EINVAL ;add_taint (TAINT_FIRMWARE_WORKAROUND ,LOCKDEP_STILL_OK );
Quoted 3 lines · Bjorn Helgaas
Applied as tweaked below to for-linus for v4.4, thanks! As written, if
NUMA_NO_NODEwere defined as -2, we would incorrectly accept -1. Let me know if you disagree with my fix.
I don't think the value of NUMA_NO_NODE will (or even has to) ever change, as we're already exporting that value to userland via sysfs. But you're right, the code shouldn't make any assumptions about the concrete value of NUMA_NO_NODE and just handle it as a special symbolic value.
Quoted 26 lines
commit
2a35194c5a45fbb9ca1d88bc56804dfb51a75233Author: Mathias Krause <[email protected]> Date: Mon Nov 9 20:00:27 2015 +0100PCI: Prevent out of bounds access in
numa_nodeoverrideCommit
1266963170f5("PCI: Prevent out of bounds access innuma_nodeoverride") missed that the user-provided node could also be negative. Handle this case as well to avoid out-of-bounds accesses to the node_states[] array. However, allow the special value -1, i.e.NUMA_NO_NODE, to be able to set the 'no specific node' configuration.[bhelgaas: remove assumption that NUMA_NO_NODE == -1]Fixes 1266963170f5 ("PCI: Prevent out of bounds access in numa_node override")Fixes 63692df103e9 ("PCI: Allow numa_node override via sysfs")Signed-off-by Mathias Krause <[email protected]>Signed-off-by Bjorn Helgaas <[email protected]>CC Sasha Levin <[email protected]>CC Prarit Bhargava <[email protected]>CC [email protected] # v3.19+drivers/pci/pci-sysfs.c +0
-0
drivers/pci/pci-sysfs.c static ssize_t numa_node_store(struct device *dev, · line 222
Quoted 8 lines
drivers/pci/pci-sysfs.c +4
-1@@ -216,7 +216,12 @@ static ssize_t numa_node_store(struct device *dev,if (ret)return ret; -if (node >=MAX_NUMNODES || !node_online (node)) +if (node <0 || node >=MAX_NUMNODES ) { +if (node !=NUMA_NO_NODE ) +return -EINVAL ; + }
I would have written something like this:
if ((node < 0 && node != NUMA_NO_NODE) || node >= MAX_NUMNODES)
return -EINVAL;It's more compact, but your solution is essentially the same, so I'm fine with it.
drivers/pci/pci-sysfs.c static ssize_t numa_node_store(struct device *dev, · line 227
Quoted 5 lines
drivers/pci/pci-sysfs.c +2
-0+ +if (node !=NUMA_NO_NODE && !node_online (node))return -EINVAL ;add_taint (TAINT_FIRMWARE_WORKAROUND ,LOCKDEP_STILL_OK );
Thanks,
Mathias
Quoted 48 lines · Mathias Krause
Quoted 3 lines · Bjorn Helgaas
Applied as tweaked below to for-linus for v4.4, thanks! As written, if
NUMA_NO_NODEwere defined as -2, we would incorrectly accept -1. Let me know if you disagree with my fix.I don't think the value of
NUMA_NO_NODEwill (or even has to) ever change, as we're already exporting that value to userland via sysfs. But you're right, the code shouldn't make any assumptions about the concrete value ofNUMA_NO_NODEand just handle it as a special symbolic value.Quoted 26 lines
commit
2a35194c5a45fbb9ca1d88bc56804dfb51a75233Author: Mathias Krause <[email protected]> Date: Mon Nov 9 20:00:27 2015 +0100PCI: Prevent out of bounds access in
numa_nodeoverrideCommit
1266963170f5("PCI: Prevent out of bounds access innuma_nodeoverride") missed that the user-provided node could also be negative. Handle this case as well to avoid out-of-bounds accesses to the node_states[] array. However, allow the special value -1, i.e.NUMA_NO_NODE, to be able to set the 'no specific node' configuration.[bhelgaas: remove assumption that NUMA_NO_NODE == -1]Fixes 1266963170f5 ("PCI: Prevent out of bounds access in numa_node override")Fixes 63692df103e9 ("PCI: Allow numa_node override via sysfs")Signed-off-by Mathias Krause <[email protected]>Signed-off-by Bjorn Helgaas <[email protected]>CC Sasha Levin <[email protected]>CC Prarit Bhargava <[email protected]>CC [email protected] # v3.19+drivers/pci/pci-sysfs.c +0
-0drivers/pci/pci-sysfs.c static ssize_t numa_node_store(struct device *dev, · line 222
Quoted 8 lines
drivers/pci/pci-sysfs.c +4
-1@@ -216,7 +216,12 @@ static ssize_t numa_node_store(struct device *dev,if (ret)return ret; -if (node >=MAX_NUMNODES || !node_online (node)) +if (node <0 || node >=MAX_NUMNODES ) { +if (node !=NUMA_NO_NODE ) +return -EINVAL ; + }I would have written something like this:
Quoted 2 lines
if ((node < 0 && node != NUMA_NO_NODE) || node >= MAX_NUMNODES)
return -EINVAL;I adopted that, thanks!