X86 platform drivers
 help / color / mirror / Atom feed
From: Hans de Goede <hdegoede@redhat.com>
To: Suma Hegde <suma.hegde@amd.com>, platform-driver-x86@vger.kernel.org
Cc: ilpo.jarvinen@linux.intel.com, kernel test robot <lkp@intel.com>,
	Dan Carpenter <dan.carpenter@linaro.org>,
	Naveen Krishna Chatradhi <naveenkrishna.chatradhi@amd.com>
Subject: Re: [PATCH v2] platform/x86/amd/hsmp: Remove NULL dereferencing code
Date: Mon, 19 Feb 2024 13:48:55 +0100	[thread overview]
Message-ID: <4781fdcf-8a7b-48fa-aa4d-6e7bb7d56eda@redhat.com> (raw)
In-Reply-To: <20240130073415.3391685-2-suma.hegde@amd.com>

Hi Suma,

On 1/30/24 08:34, Suma Hegde wrote:
> Do not log using dev_err() in case of !sock, which causes null pointer
> dereferencing.
> 
> Also remove unnecessary check "boot_cpu_data.x86_model >= 0x00", which is
> always true because its an unsigned type.
> 
> Reported-by: kernel test robot <lkp@intel.com>
> Closes: https://lore.kernel.org/oe-kbuild-all/202401292056.qkUFS09Y-lkp@intel.com/
> Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
> Closes: https://lore.kernel.org/r/202401291311.gzMCj6SP-lkp@intel.com/
> 
> Signed-off-by: Suma Hegde <suma.hegde@amd.com>
> Reviewed-by: Naveen Krishna Chatradhi <naveenkrishna.chatradhi@amd.com>
> ---
> Changes since v1:
> Correct the email id for Naveen Krishna Chatradhi.
> 
>  drivers/platform/x86/amd/hsmp.c | 11 ++++-------
>  1 file changed, 4 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/platform/x86/amd/hsmp.c b/drivers/platform/x86/amd/hsmp.c
> index 1baddf403920..1927be901108 100644
> --- a/drivers/platform/x86/amd/hsmp.c
> +++ b/drivers/platform/x86/amd/hsmp.c
> @@ -566,17 +566,15 @@ static ssize_t hsmp_metric_tbl_read(struct file *filp, struct kobject *kobj,
>  	struct hsmp_message msg = { 0 };
>  	int ret;
>  
> +	if (!sock)
> +		return -EINVAL;
> +
>  	/* Do not support lseek(), reads entire metric table */
>  	if (count < bin_attr->size) {
>  		dev_err(sock->dev, "Wrong buffer size\n");
>  		return -EINVAL;
>  	}
>  
> -	if (!sock) {
> -		dev_err(sock->dev, "Failed to read attribute private data\n");
> -		return -EINVAL;
> -	}
> -
>  	msg.msg_id	= HSMP_GET_METRIC_TABLE;
>  	msg.sock_ind	= sock->sock_ind;
> 

sock gets initialized like this:

        struct hsmp_socket *sock = bin_attr->private;

and bin_attr->private is setup before registering the file
and thus it will never be NULL.

So the correct fix would be to simply drop the check
rather then to move it.

> @@ -739,8 +737,7 @@ static int hsmp_cache_proto_ver(u16 sock_ind)
>  
>  static inline bool is_f1a_m0h(void)
>  {
> -	if (boot_cpu_data.x86 == 0x1A &&
> -	    (boot_cpu_data.x86_model >= 0x00 && boot_cpu_data.x86_model <= 0x0F))
> +	if (boot_cpu_data.x86 == 0x1A && boot_cpu_data.x86_model <= 0x0F)
>  		return true;
>  
>  	return false;

This bit looks fine but this really belongs in a separate patch
as it has nothing to do with "Remove NULL dereferencing code"

Regards,

Hans


  reply	other threads:[~2024-02-19 12:49 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-30  7:34 [PATCH v2] platform/x86/amd/hsmp: Add CONFIG_ACPI dependency Suma Hegde
2024-01-30  7:34 ` [PATCH v2] platform/x86/amd/hsmp: Remove NULL dereferencing code Suma Hegde
2024-02-19 12:48   ` Hans de Goede [this message]
2024-02-20 11:47     ` Hegde, Suma
2024-02-19 12:45 ` [PATCH v2] platform/x86/amd/hsmp: Add CONFIG_ACPI dependency Hans de Goede
2024-02-20 11:54   ` Hegde, Suma
2024-02-20 12:06     ` Ilpo Järvinen
2024-02-20 13:36       ` Hans de Goede

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=4781fdcf-8a7b-48fa-aa4d-6e7bb7d56eda@redhat.com \
    --to=hdegoede@redhat.com \
    --cc=dan.carpenter@linaro.org \
    --cc=ilpo.jarvinen@linux.intel.com \
    --cc=lkp@intel.com \
    --cc=naveenkrishna.chatradhi@amd.com \
    --cc=platform-driver-x86@vger.kernel.org \
    --cc=suma.hegde@amd.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