[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <bc8422a8bf3ff99809413eb62dd12aacc85a9950.1683356951.git.christophe.jaillet@wanadoo.fr>
Date: Sat, 6 May 2023 09:11:09 +0200
From: Christophe JAILLET <christophe.jaillet@...adoo.fr>
To: Bjorn Helgaas <bhelgaas@...gle.com>,
Thomas Gleixner <tglx@...utronix.de>,
Ingo Molnar <mingo@...hat.com>, Borislav Petkov <bp@...en8.de>,
Dave Hansen <dave.hansen@...ux.intel.com>, x86@...nel.org,
"H. Peter Anvin" <hpa@...or.com>,
"Maciej W. Rozycki" <macro@...am.me.uk>
Cc: linux-kernel@...r.kernel.org, kernel-janitors@...r.kernel.org,
Christophe JAILLET <christophe.jaillet@...adoo.fr>,
linux-pci@...r.kernel.org
Subject: [PATCH 1/2] x86/PCI: Fix a sanity check in pirq_convert_irt_table()
We compare the size in bytes of a struct (and its ending flexible array)
with the number of elements in a flexible array.
This is wrong and "ir->size < ir->used" is likely to be always false.
Compute the number of possible entries instead, as already done in other
places, and compare it to the number of used entries.
Fixes: b584db0c84db ("x86/PCI: Add $IRT PIRQ routing table support")
Signed-off-by: Christophe JAILLET <christophe.jaillet@...adoo.fr>
---
/!\ This patch is speculative. Review with care /!\
I'm not sure that this sanity check is needed at all.
If 'used' was the size of the flexible array, I think it would simplify
the code in other places. It will also help scripts when __counted_by macro
will be added.
See [1].
[1]: https://lore.kernel.org/all/6453f739.170a0220.62695.7785@mx.google.com/
---
arch/x86/pci/irq.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/arch/x86/pci/irq.c b/arch/x86/pci/irq.c
index a498b847d740..e29b487cc069 100644
--- a/arch/x86/pci/irq.c
+++ b/arch/x86/pci/irq.c
@@ -128,12 +128,16 @@ static inline struct irq_routing_table *pirq_convert_irt_table(u8 *addr,
{
struct irt_routing_table *ir;
struct irq_routing_table *rt;
+ int entries;
u16 size;
u8 sum;
int i;
ir = (struct irt_routing_table *)addr;
- if (ir->signature != IRT_SIGNATURE || !ir->used || ir->size < ir->used)
+ entries = (ir->size - sizeof(struct irq_routing_table)) /
+ sizeof(struct irq_info);
+
+ if (ir->signature != IRT_SIGNATURE || !ir->used || entries < ir->used)
return NULL;
size = sizeof(*ir) + ir->used * sizeof(ir->slots[0]);
--
2.34.1
Powered by blists - more mailing lists