mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Hans de Goede <hdegoede@redhat.com>
To: Dan Carpenter <dan.carpenter@oracle.com>,
	Rajneesh Bhardwaj <irenic.rajneesh@gmail.com>
Cc: David E Box <david.e.box@intel.com>,
	Mark Gross <mgross@linux.intel.com>,
	platform-driver-x86@vger.kernel.org,
	linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org
Subject: Re: [PATCH v2] platform/x86: intel_pmc_core: Uninitialized data in pmc_core_lpm_latch_mode_write()
Date: Wed, 21 Apr 2021 21:32:19 +0200	[thread overview]
Message-ID: <ad05f502-b3dc-b62f-1f9f-ca8c806e1e3c@redhat.com> (raw)
In-Reply-To: <YIBCf+G9Ef8wrGJw@mwanda>

Hi,

On 4/21/21 5:19 PM, Dan Carpenter wrote:
> The simple_write_to_buffer() can return success if even a single byte
> is copied from user space.  In this case it can result in using
> uninitalized data if the buf[] array is not fully initialized.  Really
> we should only succeed if the whole buffer is copied.
> 
> Just using copy_from_user() is simpler and more appropriate.
> 
> Fixes: 8074a79fad2e ("platform/x86: intel_pmc_core: Add option to set/clear LPM mode")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> ---
> v2: The first version of this patch returned -EINVAL if userspace didn't
> give us NUL terminated strings.  That's not necessarily a good
> assumption.
> 
> This patch is just simpler as well.  No need to introduce the "len"
> variable because "count" is capped at the start of the function.

Much better, thank you.

Thank you for your patch, I've applied this patch to my review-hans 
branch:
https://git.kernel.org/pub/scm/linux/kernel/git/pdx86/platform-drivers-x86.git/log/?h=review-hans

Note it will show up in my review-hans branch once I've pushed my
local branch there, which might take a while.

Once I've run some tests on this branch the patches there will be
added to the platform-drivers-x86/for-next branch and eventually
will be included in the pdx86 pull-request to Linus for the next
merge-window.

Regards,

Hans




>  drivers/platform/x86/intel_pmc_core.c | 8 ++------
>  1 file changed, 2 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/platform/x86/intel_pmc_core.c b/drivers/platform/x86/intel_pmc_core.c
> index d174aeb492e0..b0e486a6bdfb 100644
> --- a/drivers/platform/x86/intel_pmc_core.c
> +++ b/drivers/platform/x86/intel_pmc_core.c
> @@ -1360,17 +1360,13 @@ static ssize_t pmc_core_lpm_latch_mode_write(struct file *file,
>  	struct pmc_dev *pmcdev = s->private;
>  	bool clear = false, c10 = false;
>  	unsigned char buf[8];
> -	ssize_t ret;
>  	int idx, m, mode;
>  	u32 reg;
>  
>  	if (count > sizeof(buf) - 1)
>  		return -EINVAL;
> -
> -	ret = simple_write_to_buffer(buf, sizeof(buf) - 1, ppos, userbuf, count);
> -	if (ret < 0)
> -		return ret;
> -
> +	if (copy_from_user(buf, userbuf, count))
> +		return -EFAULT;
>  	buf[count] = '\0';
>  
>  	/*
> 


  reply	other threads:[~2021-04-21 19:32 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-21  9:34 [PATCH] platform/x86: intel_pmc_core: re-write copy " Dan Carpenter
2021-04-21 14:11 ` Hans de Goede
2021-04-21 15:19   ` [PATCH v2] platform/x86: intel_pmc_core: Uninitialized data " Dan Carpenter
2021-04-21 19:32     ` Hans de Goede [this message]
2021-04-21 15:32   ` [PATCH] platform/x86: intel_pmc_core: re-write copy " Dan Carpenter

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=ad05f502-b3dc-b62f-1f9f-ca8c806e1e3c@redhat.com \
    --to=hdegoede@redhat.com \
    --cc=dan.carpenter@oracle.com \
    --cc=david.e.box@intel.com \
    --cc=irenic.rajneesh@gmail.com \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mgross@linux.intel.com \
    --cc=platform-driver-x86@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

all inboxes | Powered by JetHome®