lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <5d852741-0514-49c2-9c00-ec46860bbaf6@davidwei.uk>
Date: Fri, 15 Nov 2024 16:23:29 -0800
From: David Wei <dw@...idwei.uk>
To: Michal Luczaj <mhal@...x.co>,
 Luiz Augusto von Dentz <luiz.dentz@...il.com>
Cc: Marcel Holtmann <marcel@...tmann.org>,
 Johan Hedberg <johan.hedberg@...il.com>,
 "David S. Miller" <davem@...emloft.net>, Eric Dumazet <edumazet@...gle.com>,
 Paolo Abeni <pabeni@...hat.com>, Simon Horman <horms@...nel.org>,
 David Howells <dhowells@...hat.com>, Marc Dionne <marc.dionne@...istor.com>,
 Luiz Augusto von Dentz <luiz.von.dentz@...el.com>,
 linux-bluetooth@...r.kernel.org, netdev@...r.kernel.org,
 linux-afs@...ts.infradead.org, Jakub Kicinski <kuba@...nel.org>
Subject: Re: [PATCH net 1/4] bluetooth: Improve setsockopt() handling of
 malformed user input

On 2024-11-15 00:31, Michal Luczaj wrote:
> On 11/15/24 04:04, David Wei wrote:
>> On 2024-11-14 18:50, Luiz Augusto von Dentz wrote:
>>> Hi David,
>>> On Thu, Nov 14, 2024 at 9:30 PM David Wei <dw@...idwei.uk> wrote:
>>>> On 2024-11-14 18:15, Luiz Augusto von Dentz wrote:
>>>>> Hi David,
>>>>> On Thu, Nov 14, 2024 at 7:42 PM David Wei <dw@...idwei.uk> wrote:
>>>>>> On 2024-11-14 15:27, Michal Luczaj wrote:
>>>>>> ...
>>>>>>> diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
>>>>>>> index f48250e3f2e103c75d5937e1608e43c123aa3297..1001fb4cc21c0ecc7bcdd3ea9041770ede4f27b8 100644
>>>>>>> --- a/net/bluetooth/rfcomm/sock.c
>>>>>>> +++ b/net/bluetooth/rfcomm/sock.c
>>>>>>> @@ -629,10 +629,9 @@ static int rfcomm_sock_setsockopt_old(struct socket *sock, int optname,
>>>>>>>
>>>>>>>       switch (optname) {
>>>>>>>       case RFCOMM_LM:
>>>>>>> -             if (bt_copy_from_sockptr(&opt, sizeof(opt), optval, optlen)) {
>>>>>>> -                     err = -EFAULT;
>>>>>>> +             err = copy_safe_from_sockptr(&opt, sizeof(opt), optval, optlen);
>>>>>>> +             if (err)
>>>>>>>                       break;
>>>>>>> -             }
>>>>>>
>>>>>> This will return a positive integer if copy_safe_from_sockptr() fails.
>>>>>
>>>>> What are you talking about copy_safe_from_sockptr never returns a
>>>>> positive value:
>>>>>
>>>>>  * Returns:
>>>>>  *  * -EINVAL: @optlen < @ksize
>>>>>  *  * -EFAULT: access to userspace failed.
>>>>>  *  * 0 : @ksize bytes were copied
>>>>
>>>> Isn't this what this series is about? copy_from_sockptr() returns 0 on
>>>> success, or a positive integer for number of bytes NOT copied on error.
>>>> Patch 4 even updates the docs for copy_from_sockptr().
>>>>
>>>> copy_safe_from_sockptr()
>>>>         -> copy_from_sockptr()
>>>>         -> copy_from_sockptr_offset()
>>>>         -> memcpy() for kernel to kernel OR
>>>>         -> copy_from_user() otherwise
>>>
>>> Well except the safe version does check what would otherwise cause a
>>> positive return by the likes of copy_from_user and returns -EINVAL
>>> instead, otherwise the documentation of copy_safe_from_sockptr is just
>>> wrong and shall state that it could return positive as well but I
>>> guess that would just make it as inconvenient so we might as well
>>> detect when a positive value would be returned just return -EFAULT
>>> instead.
>>
>> Yes it checks and returns EINVAL, but not EFAULT which is what my
>> comment on the original patch is about. Most of the calls to
>> bt_copy_from_sockptr() that Michal replaced with
>> copy_safe_from_sockptr() remain incorrect because it is assumed that
>> EFAULT is returned. Only rfcomm_sock_setsockopt_old() was vaguely doing
>> the right thing and the patch changed it back to the incorrect pattern:
>>
>> err = copy_safe_from_sockptr(...);
>> if (err)
>> 	break;
>>
>> But I do agree that making copy_safe_from_sockptr() do the right thing
>> and EFAULT will be easier and prevent future problems given that
>> copy_from_sockptr() is meant to be deprecated anyhow.
> 
> Just to be clear: copy_safe_from_sockptr() was recently fixed to return
> EFAULT:
> https://git.kernel.org/pub/scm/linux/kernel/git/netdev/net.git/commit/?id=eb94b7bb1010
> Sorry, I should have mentioned this series is a follow up to that patch.

I missed that, sorry. In which case this patch looks good.

Reviewed-by: David Wei <dw@...idwei.uk>

> 
> Thanks,
> Michal
> 

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ