kernelnewbies.kernelnewbies.org archive mirror
 help / color / mirror / Atom feed
From: sateesh.kumar@redpinesignals.com (Sateesh Kumar)
To: kernelnewbies@lists.kernelnewbies.org
Subject: Issue with copy_from_user() function in kernel 3.6.10
Date: Fri, 26 Jul 2013 18:48:32 +0530	[thread overview]
Message-ID: <51F27728.5090004@redpinesignals.com> (raw)
In-Reply-To: <CADVatmNGnBnX3KsKWEyahAt1YfjN9onM4MGdz=mw5tJpogEAOg@mail.gmail.com>

Hi,

         Earlier i used local buffer of array causes issue to me. 
Instead of local buffer array, i declared buffer as a pointer and 
allocating a memory of wrq->u.data.length using kmalloc. This change 
fixed my issue.

Thanks & Regards,
Sateesh.

On 07/20/2013 01:21 PM, Sudip Mukherjee wrote:
> Hi Sateesh
> Apart from the simple check as Kristof has suggested , you can also
> print the value of wrq->u.data.length to see exactly how much data you
> are receiving from the user.
>
> Regards
> Sudip
>
> On Fri, Jul 19, 2013 at 9:28 PM, Kristof Provost <kristof@sigsegv.be> wrote:
>> On 2013-07-19 21:20:07 (+0530), Sateesh Kumar <sateesh.kumar@redpinesignals.com> wrote:
>>>       I am declaring an array of 200 bytes as destination in ioctl
>>> processing function itself even i am sending 12 bytes from application.
>>> Here is the sample code how i am doing in kernel.
>>>
>>>       ioctl_process(struct iwreq *wrq)
>>>       {
>>>           uint8 buffer[200];
>>>           copy_from_user(buffer, wrq->u.data.pointer,
>>> wrq->u.data.length); //This line itself is causing the problem for me.
>>>       }
>>>
>> I'll quote the error message you got here:
>>
>>>>> "call to ?copy_from_user_overflow? declared with attribute warning:
>>>>> copy_from_user() buffer size is not provably correct"
>>>>>
>> It looks very much like you're taking a user supplied size
>> (wrq->u.data.length) and trusting it to be less than 200. That's bad.
>> Don't do that. It'll let any user panic or exploit your system.
>>
>> A simple check (if wrq->u.data.length > 200 return -E2BIG;) would
>> probably be sufficient.
>>
>> (You'll also want to check the return value of copy_from_user().)
>>
>> Regards,
>> Kristof
>>
>

      reply	other threads:[~2013-07-26 13:18 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-07-19 14:18 Issue with copy_from_user() function in kernel 3.6.10 Sateesh Kumar
2013-07-19 14:56 ` Sudip Mukherjee
2013-07-19 15:50   ` Sateesh Kumar
2013-07-19 15:58     ` Kristof Provost
2013-07-20  7:51       ` Sudip Mukherjee
2013-07-26 13:18         ` Sateesh Kumar [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=51F27728.5090004@redpinesignals.com \
    --to=sateesh.kumar@redpinesignals.com \
    --cc=kernelnewbies@lists.kernelnewbies.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;
as well as URLs for NNTP newsgroup(s).