All of lore.kernel.org
 help / color / mirror / Atom feed
From: Wolfgang Grandegger <wg@grandegger.com>
To: Oliver Hartkopp <oliver.hartkopp@volkswagen.de>
Cc: Pavel Emelyanov <xemul@openvz.org>,
	socketcan-core@lists.berlios.de,
	Linux Netdev List <netdev@vger.kernel.org>,
	David Miller <davem@davemloft.net>,
	"Thuermann, Urs, Dr. \(K-EFFI/I\)" <urs.thuermann@volkswagen.de>
Subject: Re: [PATCH][CAN]: Fix copy_from_user() results interpretation.
Date: Sat, 26 Apr 2008 08:19:31 +0200	[thread overview]
Message-ID: <4812C973.5000504@grandegger.com> (raw)
In-Reply-To: <4811E915.80303@volkswagen.de>

Oliver Hartkopp wrote:
> Pavel Emelyanov wrote:
>> Sorry for the noise, I had to check this right after facing this problem
>> with the copy_to_user()...
>>
>> Both copy_to_ and _from_user return the number of bytes, that failed to
>> reach their destination, not the 0/-EXXX values.
>>
>> Other net/ code handles this correctly.
>>
>> Signed-off-by: Pavel Emelyanov <xemul@openvz.org>
>>
> 
> Thanks very much for catching this, Pavel!
> 
> Acked-by: Oliver Hartkopp <oliver.hartkopp@volkswagen.de>
> 
>> ---
>>
>> diff --git a/net/can/raw.c b/net/can/raw.c
>> index ead50c7..2be8c6e 100644
>> --- a/net/can/raw.c
>> +++ b/net/can/raw.c
>> @@ -438,12 +438,12 @@ static int raw_setsockopt(struct socket *sock, 
>> int level, int optname,
>>                         err = copy_from_user(filter, optval, optlen);
>>                         if (err) {
>>                                 kfree(filter);
>> -                               return err;
>> +                               return -EFAULT;
>>                         }
>>                 } else if (count == 1) {
>>                         err = copy_from_user(&sfilter, optval, optlen);
>>                         if (err)
>> -                               return err;
>> +                               return -EFAULT;
>>                 }
>>  
>>                 lock_sock(sk);
>> @@ -495,7 +495,7 @@ static int raw_setsockopt(struct socket *sock, int 
>> level, int optname,
>>  
>>                 err = copy_from_user(&err_mask, optval, optlen);
>>                 if (err)
>> -                       return err;
>> +                       return -EFAULT;
>>  
>>                 err_mask &= CAN_ERR_MASK;
>>  
>> @@ -531,7 +531,8 @@ static int raw_setsockopt(struct socket *sock, int 
>> level, int optname,
>>                 if (optlen != sizeof(ro->loopback))
>>                         return -EINVAL;
>>  
>> -               err = copy_from_user(&ro->loopback, optval, optlen);
>> +               err = copy_from_user(&ro->loopback, optval, optlen) ?
>> +                       -EFAULT : 0;
>>  
>>                 break;
>>  
>> @@ -539,7 +540,8 @@ static int raw_setsockopt(struct socket *sock, int 
>> level, int optname,
>>                 if (optlen != sizeof(ro->recv_own_msgs))
>>                         return -EINVAL;
>>  
>> -               err = copy_from_user(&ro->recv_own_msgs, optval, optlen);
>> +               err = copy_from_user(&ro->recv_own_msgs, optval, 
>> optlen) ?
>> +                       -EFAULT : 0;
>>  
>>                 break;
>>  
>>

What about removing the assignment "err =" in that case. It's confusing
otherwise and maybe the variable err is even obsolete.

Wolfgang.


  reply	other threads:[~2008-04-26  6:19 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-04-25 12:42 [PATCH][CAN]: Fix copy_from_user() results interpretation Pavel Emelyanov
2008-04-25 14:22 ` Oliver Hartkopp
2008-04-26  6:19   ` Wolfgang Grandegger [this message]
2008-04-26  6:23     ` David Miller
2008-04-26  6:35       ` Wolfgang Grandegger
2008-04-26  6:40     ` Sam Ravnborg
2008-04-26  7:03       ` David Miller
2008-04-26 13:04         ` Wolfgang Grandegger
2008-04-26  8:26       ` Oliver Hartkopp
2008-04-26  9:10         ` David Miller
2008-04-26  9:59           ` Sam Ravnborg
2008-04-26 10:01             ` David Miller
2008-04-26 10:05               ` Sam Ravnborg
2008-04-27  5:57             ` David Miller
     [not found] <mailman.2289.1209191345.4974.socketcan-core@lists.berlios.de>
2008-04-26  6:33 ` David Miller

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=4812C973.5000504@grandegger.com \
    --to=wg@grandegger.com \
    --cc=davem@davemloft.net \
    --cc=netdev@vger.kernel.org \
    --cc=oliver.hartkopp@volkswagen.de \
    --cc=socketcan-core@lists.berlios.de \
    --cc=urs.thuermann@volkswagen.de \
    --cc=xemul@openvz.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 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.