All of lore.kernel.org
 help / color / mirror / Atom feed
From: Lars-Peter Clausen <lars@metafoo.de>
To: Dan Carpenter <dan.carpenter@oracle.com>,
	Daniel Baluta <daniel.baluta@gmail.com>
Cc: "aybüke özdemir" <aybuke.147@gmail.com>,
	"Hartmut Knaack" <knaack.h@gmx.de>,
	"Peter Meerwald" <pmeerw@pmeerw.net>,
	"linux-iio@vger.kernel.org" <linux-iio@vger.kernel.org>
Subject: Re: staging: iio: accel: Use __be16 instead of u16
Date: Fri, 07 Aug 2015 13:38:42 +0200	[thread overview]
Message-ID: <55C498C2.1070709@metafoo.de> (raw)
In-Reply-To: <20150807112733.GI5096@mwanda>

On 08/07/2015 01:27 PM, Dan Carpenter wrote:
> On Fri, Aug 07, 2015 at 01:59:40PM +0300, Daniel Baluta wrote:
>>>    119          for (i = 0; i < num_read; i++)
>>>    120                  *(((u16 *)rx) + i) = be16_to_cpup((__be16 *)rx + i);
>>>                           ^^^^^^^^^^^^^^^
>>>
>>> We're writing beyond the end of the array here because of the pointer
>>> math issue.  The fix is probably to say:
>>>
>>>                 for (i = 0; i < num_read / sizeof(u16); i++)
>>>                         *(((u16 *)rx) + i) = be16_to_cpup((__be16 *)rx + i);
>>>
>>>    121
>>>    122          if (copy_to_user(buf, rx, num_read))
>>>    123                  ret = -EFAULT;
>>
>> Looks good to me. Please send a formal patch.
> 
> It's weird that no one has noticed this bug in testing because we end
> up corrupting memory every time this function is called.

The buffers are probably smaller than the minimum allocation size so there
is a bit of unused space after the buffer and overwriting it will not result
in a corruption of used memory and nobody ever noticed.

But in any way we should just drop the endianness conversion in kernelspace
and advertise the data as big-endian to userspace.

- Lars


      reply	other threads:[~2015-08-07 11:38 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-15 19:36 staging: iio: accel: Use __be16 instead of u16 Dan Carpenter
2015-08-07 10:47 ` Dan Carpenter
2015-08-07 10:59 ` Daniel Baluta
2015-08-07 11:27   ` Dan Carpenter
2015-08-07 11:38     ` Lars-Peter Clausen [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=55C498C2.1070709@metafoo.de \
    --to=lars@metafoo.de \
    --cc=aybuke.147@gmail.com \
    --cc=dan.carpenter@oracle.com \
    --cc=daniel.baluta@gmail.com \
    --cc=knaack.h@gmx.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=pmeerw@pmeerw.net \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.