PCI: prevent out of bounds access in numa_node override
PATCH 1/1 PCI: prevent out of bounds access in numa_node override
Commit 63692df1 ("PCI: Allow numa_node override via sysfs") didn't check that the numa node provided by userspace is valid. Passing a node number too high would attempt to access invalid memory and trigger a kernel panic.
--- drivers/pci/pci-sysfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pci/pci-sysfs.c +1 -1
@@ -216,7 +216,7 @@ static ssize_t numa_node_store(struct device *dev,if (ret)return ret; -if (!node_online (node)) +if (node >MAX_NUMNODES || !node_online (node))return -EINVAL ;add_taint (TAINT_FIRMWARE_WORKAROUND ,LOCKDEP_STILL_OK );
Signature · 1 line
1.7.10.4
Hi Sasha,
Quoted 15 lines · Sasha Levin
Commit
63692df1("PCI: Allownuma_nodeoverride via sysfs") didn't check that the numa node provided by userspace is valid. Passing a node number too high would attempt to access invalid memory and trigger a kernel panic.Fixes 63692df1 ("PCI: Allow numa_node override via sysfs")Signed-off-by Sasha Levin <[email protected]>--- drivers/pci/pci-sysfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/pci/pci-sysfs.c +0
-0
drivers/pci/pci-sysfs.c static ssize_t numa_node_store(struct device *dev, · line 219
Quoted 5 lines
drivers/pci/pci-sysfs.c +1
-1@@ -216,7 +216,7 @@ static ssize_t numa_node_store(struct device *dev,if (ret)return ret; -if (!node_online (node)) +if (node >MAX_NUMNODES || !node_online (node))
This needs to be "node >= MAX_NUMNODES", doesn't it? I'll fix it up if you agree.
Looks like a candidate for stable.
Quoted 10 lines
drivers/pci/pci-sysfs.c +0
-0return -EINVAL ;add_taint (TAINT_FIRMWARE_WORKAROUND ,LOCKDEP_STILL_OK );Signature · 6 lines
1.7.10.4 -- 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 21 lines · Bjorn Helgaas
Hi Sasha,
Quoted 18 lines · Sasha Levin
Commit
63692df1("PCI: Allownuma_nodeoverride via sysfs") didn't check that the numa node provided by userspace is valid. Passing a node number too high would attempt to access invalid memory and trigger a kernel panic.Fixes 63692df1 ("PCI: Allow numa_node override via sysfs")Signed-off-by Sasha Levin <[email protected]>--- drivers/pci/pci-sysfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/pci/pci-sysfs.c +0
-0@@ -216,7 +216,7 @@ static ssize_t numa_node_store(struct device *dev,if (ret)return ret;
Quoted 5 lines
drivers/pci/pci-sysfs.c static ssize_t numa_node_store(struct device *dev, · line 219
Quoted 2 lines
drivers/pci/pci-sysfs.c +1
-1-if (!node_online (node)) +if (node >MAX_NUMNODES || !node_online (node))This needs to be "node >=
MAX_NUMNODES", doesn't it? I'll fix it up if you agree.
Not a strenuous objection, but I don't see much bound checking using MAX_NUMNODES in the kernel outside of the core numa area. Is fixing node_online() with bounds checking a better option here so that other callers get the fix? I would have thought that calling node_online() with node > MAX_NUMNODES should be safe to call.
P.
Quoted 18 lines
Looks like a candidate for stable.
Quoted 10 lines
drivers/pci/pci-sysfs.c +0
-0return -EINVAL ;add_taint (TAINT_FIRMWARE_WORKAROUND ,LOCKDEP_STILL_OK );Signature · 6 lines
1.7.10.4 -- 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--
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 24 lines · Prarit Bhargava
Quoted 21 lines · Bjorn Helgaas
Hi Sasha,
Quoted 18 lines · Sasha Levin
Commit
63692df1("PCI: Allownuma_nodeoverride via sysfs") didn't check that the numa node provided by userspace is valid. Passing a node number too high would attempt to access invalid memory and trigger a kernel panic.Fixes 63692df1 ("PCI: Allow numa_node override via sysfs")Signed-off-by Sasha Levin <[email protected]>--- drivers/pci/pci-sysfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/pci/pci-sysfs.c +0
-0@@ -216,7 +216,7 @@ static ssize_t numa_node_store(struct device *dev,if (ret)return ret;
Quoted 5 lines
Quoted 5 lines
drivers/pci/pci-sysfs.c static ssize_t numa_node_store(struct device *dev, · line 219
Quoted 2 lines
drivers/pci/pci-sysfs.c +1
-1-if (!node_online (node)) +if (node >MAX_NUMNODES || !node_online (node))This needs to be "node >=
MAX_NUMNODES", doesn't it? I'll fix it up if you agree.
Yup, you're right.
Quoted 6 lines
Not a strenuous objection, but I don't see much bound checking using
MAX_NUMNODESin the kernel outside of the core numa area. Is fixingnode_online()with bounds checking a better option here so that other callers get the fix? I would have thought that callingnode_online()with node >MAX_NUMNODESshould be safe to call.
I don't know, this will add overhead to node_online(), and isn't really done in any other similar function. For example, cpu_online() isn't safe to call with cpu > NR_CPUS either.
Thanks,
Sasha
Quoted 22 lines · Sasha Levin
Quoted 22 lines · Bjorn Helgaas
Quoted 21 lines
Hi Sasha,
Quoted 18 lines · Sasha Levin
Commit
63692df1("PCI: Allownuma_nodeoverride via sysfs") didn't check that the numa node provided by userspace is valid. Passing a node number too high would attempt to access invalid memory and trigger a kernel panic.Fixes 63692df1 ("PCI: Allow numa_node override via sysfs")Signed-off-by Sasha Levin <[email protected]>--- drivers/pci/pci-sysfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/pci/pci-sysfs.c +0
-0@@ -216,7 +216,7 @@ static ssize_t numa_node_store(struct device *dev,if (ret)return ret;
Quoted 7 lines
Quoted 5 lines
Quoted 5 lines
drivers/pci/pci-sysfs.c static ssize_t numa_node_store(struct device *dev, · line 219
Quoted 2 lines
drivers/pci/pci-sysfs.c +1
-1-if (!node_online (node)) +if (node >MAX_NUMNODES || !node_online (node))This needs to be "node >=
MAX_NUMNODES", doesn't it? I'll fix it up if you agree.Yup, you're right.
OK, applied to for-linus for v4.3 as follows. Thanks a lot, Sasha!
commit 0f7b9ad7477f7ce9b30e9ab0048f6e726f11a08a
Author: Sasha Levin <[email protected]> Date: Sun Oct 4 17:49:29 2015 -0400
PCI: Prevent out of bounds access in numa_node override
63692df103e9 ("PCI: Allow numa_node override via sysfs") didn't check that the numa node provided by userspace is valid. Passing a node number too high would attempt to access invalid memory and trigger a kernel panic.
drivers/pci/pci-sysfs.c +1 -1
@@ -216,7 +216,7 @@ static ssize_t numa_node_store(struct device *dev,if (ret)return ret; -if (!node_online (node)) +if (node >=MAX_NUMNODES || !node_online (node))return -EINVAL ;add_taint (TAINT_FIRMWARE_WORKAROUND ,LOCKDEP_STILL_OK );
Hi Prarit,
Quoted 26 lines · Prarit Bhargava
Quoted 19 lines · Bjorn Helgaas
Quoted 18 lines · Sasha Levin
Commit
63692df1("PCI: Allownuma_nodeoverride via sysfs") didn't check that the numa node provided by userspace is valid. Passing a node number too high would attempt to access invalid memory and trigger a kernel panic.Fixes 63692df1 ("PCI: Allow numa_node override via sysfs")Signed-off-by Sasha Levin <[email protected]>--- drivers/pci/pci-sysfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/pci/pci-sysfs.c +0
-0@@ -216,7 +216,7 @@ static ssize_t numa_node_store(struct device *dev,if (ret)return ret;Quoted 5 lines
drivers/pci/pci-sysfs.c static ssize_t numa_node_store(struct device *dev, · line 219
Quoted 2 lines
drivers/pci/pci-sysfs.c +1
-1-if (!node_online (node)) +if (node >MAX_NUMNODES || !node_online (node))This needs to be "node >=
MAX_NUMNODES", doesn't it? I'll fix it up if you agree.
Quoted 5 lines
Not a strenuous objection, but I don't see much bound checking using
MAX_NUMNODESin the kernel outside of the core numa area. Is fixingnode_online()with bounds checking a better option here so that other callers get the fix? I would have thought that callingnode_online()with node >MAX_NUMNODESshould be safe to call.
Yes, that would certainly be an option. I don't feel super strongly either way, but one argument in favor of Sasha's approach is that the validation of user input is nice and obvious right at the point where we process the input.
Bjorn