* [PATCH v2 1/2] ACPI: NFIT: Fix incorrect calculation of idt size
@ 2023-08-26 7:16 Yu Liao
2023-08-26 7:16 ` [PATCH v2 2/2] ACPI: NFIT: use struct_size() helper Yu Liao
2023-09-15 16:13 ` [PATCH v2 1/2] ACPI: NFIT: Fix incorrect calculation of idt size Ira Weiny
0 siblings, 2 replies; 4+ messages in thread
From: Yu Liao @ 2023-08-26 7:16 UTC (permalink / raw)
To: dan.j.williams, vishal.l.verma, dave.jiang, ira.weiny, rafael
Cc: liaoyu15, liwei391, lenb, robert.moore, linux-acpi, nvdimm,
linux-kernel
acpi_nfit_interleave's field 'line_offset' is switched to flexible array [1],
but sizeof_idt() still calculates the size in the form of 1-element array.
Therefore, fix incorrect calculation in sizeof_idt().
[1] https://lore.kernel.org/lkml/2652195.BddDVKsqQX@kreacher/
Fixes: 2a5ab99847bd ("ACPICA: struct acpi_nfit_interleave: Replace 1-element array with flexible array")
Cc: stable@vger.kernel.org # v6.4+
Signed-off-by: Yu Liao <liaoyu15@huawei.com>
Reviewed-by: Dave Jiang <dave.jiang@intel.com>
---
v1 -> v2: add Dave's review tag and cc nvdimm@lists.linux.dev
---
drivers/acpi/nfit/core.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/acpi/nfit/core.c b/drivers/acpi/nfit/core.c
index 07204d482968..305f590c54a8 100644
--- a/drivers/acpi/nfit/core.c
+++ b/drivers/acpi/nfit/core.c
@@ -855,7 +855,7 @@ static size_t sizeof_idt(struct acpi_nfit_interleave *idt)
{
if (idt->header.length < sizeof(*idt))
return 0;
- return sizeof(*idt) + sizeof(u32) * (idt->line_count - 1);
+ return sizeof(*idt) + sizeof(u32) * idt->line_count;
}
static bool add_idt(struct acpi_nfit_desc *acpi_desc,
--
2.25.1
^ permalink raw reply related [flat|nested] 4+ messages in thread* [PATCH v2 2/2] ACPI: NFIT: use struct_size() helper 2023-08-26 7:16 [PATCH v2 1/2] ACPI: NFIT: Fix incorrect calculation of idt size Yu Liao @ 2023-08-26 7:16 ` Yu Liao 2023-09-15 16:20 ` Ira Weiny 2023-09-15 16:13 ` [PATCH v2 1/2] ACPI: NFIT: Fix incorrect calculation of idt size Ira Weiny 1 sibling, 1 reply; 4+ messages in thread From: Yu Liao @ 2023-08-26 7:16 UTC (permalink / raw) To: dan.j.williams, vishal.l.verma, dave.jiang, ira.weiny, rafael Cc: liaoyu15, liwei391, lenb, robert.moore, linux-acpi, nvdimm, linux-kernel Make use of the struct_size() helper instead of an open-coded version, in order to avoid any potential type mistakes or integer overflows that, in the worst scenario, could lead to heap overflows. Signed-off-by: Yu Liao <liaoyu15@huawei.com> Reviewed-by: Dave Jiang <dave.jiang@intel.com> --- drivers/acpi/nfit/core.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/drivers/acpi/nfit/core.c b/drivers/acpi/nfit/core.c index 305f590c54a8..2f7217600307 100644 --- a/drivers/acpi/nfit/core.c +++ b/drivers/acpi/nfit/core.c @@ -712,8 +712,7 @@ static bool add_spa(struct acpi_nfit_desc *acpi_desc, } } - nfit_spa = devm_kzalloc(dev, sizeof(*nfit_spa) + sizeof_spa(spa), - GFP_KERNEL); + nfit_spa = devm_kzalloc(dev, struct_size(nfit_spa, spa, 1), GFP_KERNEL); if (!nfit_spa) return false; INIT_LIST_HEAD(&nfit_spa->list); @@ -741,7 +740,7 @@ static bool add_memdev(struct acpi_nfit_desc *acpi_desc, return true; } - nfit_memdev = devm_kzalloc(dev, sizeof(*nfit_memdev) + sizeof(*memdev), + nfit_memdev = devm_kzalloc(dev, struct_size(nfit_memdev, memdev, 1), GFP_KERNEL); if (!nfit_memdev) return false; @@ -812,8 +811,7 @@ static bool add_dcr(struct acpi_nfit_desc *acpi_desc, return true; } - nfit_dcr = devm_kzalloc(dev, sizeof(*nfit_dcr) + sizeof(*dcr), - GFP_KERNEL); + nfit_dcr = devm_kzalloc(dev, struct_size(nfit_dcr, dcr, 1), GFP_KERNEL); if (!nfit_dcr) return false; INIT_LIST_HEAD(&nfit_dcr->list); @@ -855,7 +853,7 @@ static size_t sizeof_idt(struct acpi_nfit_interleave *idt) { if (idt->header.length < sizeof(*idt)) return 0; - return sizeof(*idt) + sizeof(u32) * idt->line_count; + return struct_size(idt, line_offset, idt->line_count); } static bool add_idt(struct acpi_nfit_desc *acpi_desc, -- 2.25.1 ^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v2 2/2] ACPI: NFIT: use struct_size() helper 2023-08-26 7:16 ` [PATCH v2 2/2] ACPI: NFIT: use struct_size() helper Yu Liao @ 2023-09-15 16:20 ` Ira Weiny 0 siblings, 0 replies; 4+ messages in thread From: Ira Weiny @ 2023-09-15 16:20 UTC (permalink / raw) To: Yu Liao, dan.j.williams, vishal.l.verma, dave.jiang, ira.weiny, rafael Cc: liaoyu15, liwei391, lenb, robert.moore, linux-acpi, nvdimm, linux-kernel Yu Liao wrote: > Make use of the struct_size() helper instead of an open-coded version, > in order to avoid any potential type mistakes or integer overflows that, > in the worst scenario, could lead to heap overflows. > > Signed-off-by: Yu Liao <liaoyu15@huawei.com> > Reviewed-by: Dave Jiang <dave.jiang@intel.com> Reviewed-by: Ira Weiny <ira.weiny@intel.com> > --- > drivers/acpi/nfit/core.c | 10 ++++------ > 1 file changed, 4 insertions(+), 6 deletions(-) > > diff --git a/drivers/acpi/nfit/core.c b/drivers/acpi/nfit/core.c > index 305f590c54a8..2f7217600307 100644 > --- a/drivers/acpi/nfit/core.c > +++ b/drivers/acpi/nfit/core.c > @@ -712,8 +712,7 @@ static bool add_spa(struct acpi_nfit_desc *acpi_desc, > } > } > > - nfit_spa = devm_kzalloc(dev, sizeof(*nfit_spa) + sizeof_spa(spa), > - GFP_KERNEL); > + nfit_spa = devm_kzalloc(dev, struct_size(nfit_spa, spa, 1), GFP_KERNEL); > if (!nfit_spa) > return false; > INIT_LIST_HEAD(&nfit_spa->list); > @@ -741,7 +740,7 @@ static bool add_memdev(struct acpi_nfit_desc *acpi_desc, > return true; > } > > - nfit_memdev = devm_kzalloc(dev, sizeof(*nfit_memdev) + sizeof(*memdev), > + nfit_memdev = devm_kzalloc(dev, struct_size(nfit_memdev, memdev, 1), > GFP_KERNEL); > if (!nfit_memdev) > return false; > @@ -812,8 +811,7 @@ static bool add_dcr(struct acpi_nfit_desc *acpi_desc, > return true; > } > > - nfit_dcr = devm_kzalloc(dev, sizeof(*nfit_dcr) + sizeof(*dcr), > - GFP_KERNEL); > + nfit_dcr = devm_kzalloc(dev, struct_size(nfit_dcr, dcr, 1), GFP_KERNEL); > if (!nfit_dcr) > return false; > INIT_LIST_HEAD(&nfit_dcr->list); > @@ -855,7 +853,7 @@ static size_t sizeof_idt(struct acpi_nfit_interleave *idt) > { > if (idt->header.length < sizeof(*idt)) > return 0; > - return sizeof(*idt) + sizeof(u32) * idt->line_count; > + return struct_size(idt, line_offset, idt->line_count); > } > > static bool add_idt(struct acpi_nfit_desc *acpi_desc, > -- > 2.25.1 > ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2 1/2] ACPI: NFIT: Fix incorrect calculation of idt size 2023-08-26 7:16 [PATCH v2 1/2] ACPI: NFIT: Fix incorrect calculation of idt size Yu Liao 2023-08-26 7:16 ` [PATCH v2 2/2] ACPI: NFIT: use struct_size() helper Yu Liao @ 2023-09-15 16:13 ` Ira Weiny 1 sibling, 0 replies; 4+ messages in thread From: Ira Weiny @ 2023-09-15 16:13 UTC (permalink / raw) To: Yu Liao, dan.j.williams, vishal.l.verma, dave.jiang, ira.weiny, rafael Cc: liaoyu15, liwei391, lenb, robert.moore, linux-acpi, nvdimm, linux-kernel Yu Liao wrote: > acpi_nfit_interleave's field 'line_offset' is switched to flexible array [1], > but sizeof_idt() still calculates the size in the form of 1-element array. > > Therefore, fix incorrect calculation in sizeof_idt(). > > [1] https://lore.kernel.org/lkml/2652195.BddDVKsqQX@kreacher/ > > Fixes: 2a5ab99847bd ("ACPICA: struct acpi_nfit_interleave: Replace 1-element array with flexible array") > Cc: stable@vger.kernel.org # v6.4+ > Signed-off-by: Yu Liao <liaoyu15@huawei.com> > Reviewed-by: Dave Jiang <dave.jiang@intel.com> Reviewed-by: Ira Weiny <ira.weiny@intel.com> > --- > v1 -> v2: add Dave's review tag and cc nvdimm@lists.linux.dev > --- > drivers/acpi/nfit/core.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/acpi/nfit/core.c b/drivers/acpi/nfit/core.c > index 07204d482968..305f590c54a8 100644 > --- a/drivers/acpi/nfit/core.c > +++ b/drivers/acpi/nfit/core.c > @@ -855,7 +855,7 @@ static size_t sizeof_idt(struct acpi_nfit_interleave *idt) > { > if (idt->header.length < sizeof(*idt)) > return 0; > - return sizeof(*idt) + sizeof(u32) * (idt->line_count - 1); > + return sizeof(*idt) + sizeof(u32) * idt->line_count; > } > > static bool add_idt(struct acpi_nfit_desc *acpi_desc, > -- > 2.25.1 > ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-09-15 16:21 UTC | newest] Thread overview: 4+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2023-08-26 7:16 [PATCH v2 1/2] ACPI: NFIT: Fix incorrect calculation of idt size Yu Liao 2023-08-26 7:16 ` [PATCH v2 2/2] ACPI: NFIT: use struct_size() helper Yu Liao 2023-09-15 16:20 ` Ira Weiny 2023-09-15 16:13 ` [PATCH v2 1/2] ACPI: NFIT: Fix incorrect calculation of idt size Ira Weiny
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox