mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
To: Abdun Nihaal <nihaal@cse.iitm.ac.in>
Cc: s.shravan@intel.com, Hans de Goede <hansg@kernel.org>,
	 platform-driver-x86@vger.kernel.org,
	LKML <linux-kernel@vger.kernel.org>,
	 stable@vger.kernel.org
Subject: Re: [PATCH v2] platform/x86: int1092: Fix potential memory leak in sar_probe()
Date: Fri, 10 Jul 2026 12:40:32 +0300 (EEST)	[thread overview]
Message-ID: <a83ad3d5-107c-0a24-93f6-44fe64405b02@linux.intel.com> (raw)
In-Reply-To: <20260710052806.100107-1-nihaal@cse.iitm.ac.in>

[-- Attachment #1: Type: text/plain, Size: 4140 bytes --]

On Fri, 10 Jul 2026, Abdun Nihaal wrote:

> The memory allocated for device_mode_info in parse_package() called by
> sar_get_data() is not freed in some of the error paths in sar_probe().
> Fix that by converting to use device managed allocations.
> 
> Fixes: dcfbd31ef4bc ("platform/x86: BIOS SAR driver for Intel M.2 Modem")
> Cc: stable@vger.kernel.org
> Signed-off-by: Abdun Nihaal <nihaal@cse.iitm.ac.in>
> ---
> Compile tested only. Issue found using static analysis.
> 
> v1->v2:
> - Changed the patch to instead use device managed allocations for both
>   the device_mode_info and the context structure, as suggested by Ilpo
>   Järvinen.
> 
> Link to v1: https://patchwork.kernel.org/project/platform-driver-x86/patch/20260707070524.953741-1-nihaal@cse.iitm.ac.in/
> 
>  .../platform/x86/intel/int1092/intel_sar.c    | 30 +++++--------------
>  1 file changed, 8 insertions(+), 22 deletions(-)
> 
> diff --git a/drivers/platform/x86/intel/int1092/intel_sar.c b/drivers/platform/x86/intel/int1092/intel_sar.c
> index 849f7b415c1e..f234e1f55aec 100644
> --- a/drivers/platform/x86/intel/int1092/intel_sar.c
> +++ b/drivers/platform/x86/intel/int1092/intel_sar.c
> @@ -91,8 +91,8 @@ static acpi_status parse_package(struct wwan_sar_context *context, union acpi_ob
>  	    item->package.count <= data->total_dev_mode)
>  		return AE_ERROR;
>  
> -	data->device_mode_info = kmalloc_objs(struct wwan_device_mode_info,
> -					      data->total_dev_mode);
> +	data->device_mode_info = devm_kmalloc_array(&context->sar_device->dev,
> +			data->total_dev_mode, sizeof(*data->device_mode_info), GFP_KERNEL);

Hi,

You could add second patch to this series to convert it into 
devm_kcalloc() to have the memory zeroed. In that patch, please align 
the parameters to (.

sashiko seemed to even find a way to expose the uninitialized memory into 
userspace (Reported-by: sashiko.dev + Closes: https://sashiko.dev/#/patchset/20260710052806.100107-1-nihaal%40cse.iitm.ac.in)

>  	if (!data->device_mode_info)
>  		return AE_ERROR;
>  
> @@ -253,7 +253,7 @@ static int sar_probe(struct platform_device *device)
>  	if (!handle)
>  		return -ENODEV;
>  
> -	context = kzalloc_obj(*context);
> +	context = devm_kzalloc(&device->dev, sizeof(*context), GFP_KERNEL);
>  	if (!context)
>  		return -ENOMEM;
>  
> @@ -264,7 +264,7 @@ static int sar_probe(struct platform_device *device)
>  	result = guid_parse(SAR_DSM_UUID, &context->guid);
>  	if (result) {
>  		dev_err(&device->dev, "SAR UUID parse error: %d\n", result);
> -		goto r_free;
> +		return result;
>  	}
>  
>  	for (reg = 0; reg < MAX_REGULATORY; reg++)
> @@ -272,43 +272,29 @@ static int sar_probe(struct platform_device *device)
>  
>  	if (sar_get_device_mode(device) != AE_OK) {
>  		dev_err(&device->dev, "Failed to get device mode\n");
> -		result = -EIO;
> -		goto r_free;
> +		return -EIO;
>  	}
>  
>  	result = sysfs_create_group(&device->dev.kobj, &intcsar_group);
>  	if (result) {
>  		dev_err(&device->dev, "sysfs creation failed\n");
> -		goto r_free;
> +		return result;
>  	}
>  
>  	if (acpi_install_notify_handler(ACPI_HANDLE(&device->dev), ACPI_DEVICE_NOTIFY,
>  					sar_notify, (void *)device) != AE_OK) {
>  		dev_err(&device->dev, "Failed acpi_install_notify_handler\n");
> -		result = -EIO;
> -		goto r_sys;
> +		sysfs_remove_group(&device->dev.kobj, &intcsar_group);
> +		return -EIO;
>  	}
>  	return 0;
> -
> -r_sys:
> -	sysfs_remove_group(&device->dev.kobj, &intcsar_group);
> -r_free:
> -	kfree(context);
> -	return result;
>  }
>  
>  static void sar_remove(struct platform_device *device)
>  {
> -	struct wwan_sar_context *context = dev_get_drvdata(&device->dev);
> -	int reg;
> -
>  	acpi_remove_notify_handler(ACPI_HANDLE(&device->dev),
>  				   ACPI_DEVICE_NOTIFY, sar_notify);
>  	sysfs_remove_group(&device->dev.kobj, &intcsar_group);
> -	for (reg = 0; reg < MAX_REGULATORY; reg++)
> -		kfree(context->config_data[reg].device_mode_info);
> -
> -	kfree(context);
>  }
>  
>  static struct platform_driver sar_driver = {
> 

-- 
 i.

      reply	other threads:[~2026-07-10  9:40 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-10  5:28 Abdun Nihaal
2026-07-10  9:40 ` Ilpo Järvinen [this message]

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=a83ad3d5-107c-0a24-93f6-44fe64405b02@linux.intel.com \
    --to=ilpo.jarvinen@linux.intel.com \
    --cc=hansg@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nihaal@cse.iitm.ac.in \
    --cc=platform-driver-x86@vger.kernel.org \
    --cc=s.shravan@intel.com \
    --cc=stable@vger.kernel.org \
    /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

Powered by JetHome