Linux ACPI
 help / color / mirror / Atom feed
From: Ira Weiny <ira.weiny@intel.com>
To: Yu Liao <liaoyu15@huawei.com>, <dan.j.williams@intel.com>,
	<vishal.l.verma@intel.com>, <dave.jiang@intel.com>,
	<ira.weiny@intel.com>, <rafael@kernel.org>
Cc: <liaoyu15@huawei.com>, <liwei391@huawei.com>, <lenb@kernel.org>,
	<robert.moore@intel.com>, <linux-acpi@vger.kernel.org>,
	<nvdimm@lists.linux.dev>, <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v2 2/2] ACPI: NFIT: use struct_size() helper
Date: Fri, 15 Sep 2023 09:20:07 -0700	[thread overview]
Message-ID: <65048437b07bb_3777b5294c3@iweiny-mobl.notmuch> (raw)
In-Reply-To: <20230826071654.564372-2-liaoyu15@huawei.com>

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
> 



  reply	other threads:[~2023-09-15 16:21 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2023-09-15 16:13 ` [PATCH v2 1/2] ACPI: NFIT: Fix incorrect calculation of idt size Ira Weiny

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=65048437b07bb_3777b5294c3@iweiny-mobl.notmuch \
    --to=ira.weiny@intel.com \
    --cc=dan.j.williams@intel.com \
    --cc=dave.jiang@intel.com \
    --cc=lenb@kernel.org \
    --cc=liaoyu15@huawei.com \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=liwei391@huawei.com \
    --cc=nvdimm@lists.linux.dev \
    --cc=rafael@kernel.org \
    --cc=robert.moore@intel.com \
    --cc=vishal.l.verma@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox