* [PATCH]: SCTP length validation.
@ 2008-06-21 5:12 David Miller
2008-06-21 15:55 ` Vlad Yasevich
0 siblings, 1 reply; 5+ messages in thread
From: David Miller @ 2008-06-21 5:12 UTC (permalink / raw)
To: netdev; +Cc: linux-sctp, vladislav.yasevich
I just checked in the following SCTP bug fix to net-2.6 and will make
sure it gets into -stable as well.
sctp: Make sure N * sizeof(union sctp_addr) does not overflow.
As noticed by Gabriel Campana, the kmalloc() length arg
passed in by sctp_getsockopt_local_addrs_old() can overflow
if ->addr_num is large enough.
Therefore, enforce an appropriate limit.
Signed-off-by: David S. Miller <davem@davemloft.net>
---
net/sctp/socket.c | 4 +++-
1 files changed, 3 insertions(+), 1 deletions(-)
diff --git a/net/sctp/socket.c b/net/sctp/socket.c
index e7e3baf..0dbcde6 100644
--- a/net/sctp/socket.c
+++ b/net/sctp/socket.c
@@ -4401,7 +4401,9 @@ static int sctp_getsockopt_local_addrs_old(struct sock *sk, int len,
if (copy_from_user(&getaddrs, optval, len))
return -EFAULT;
- if (getaddrs.addr_num <= 0) return -EINVAL;
+ if (getaddrs.addr_num <= 0 ||
+ getaddrs.addr_num >= (INT_MAX / sizeof(union sctp_addr)))
+ return -EINVAL;
/*
* For UDP-style sockets, id specifies the association to query.
* If the id field is set to the value '0' then the locally bound
--
1.5.6
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH]: SCTP length validation.
2008-06-21 5:12 [PATCH]: SCTP length validation David Miller
@ 2008-06-21 15:55 ` Vlad Yasevich
2008-06-22 19:32 ` David Miller
0 siblings, 1 reply; 5+ messages in thread
From: Vlad Yasevich @ 2008-06-21 15:55 UTC (permalink / raw)
To: David Miller; +Cc: netdev, linux-sctp
David Miller wrote:
> I just checked in the following SCTP bug fix to net-2.6 and will make
> sure it gets into -stable as well.
>
> sctp: Make sure N * sizeof(union sctp_addr) does not overflow.
>
> As noticed by Gabriel Campana, the kmalloc() length arg
> passed in by sctp_getsockopt_local_addrs_old() can overflow
> if ->addr_num is large enough.
>
> Therefore, enforce an appropriate limit.
Hi David
The same vulnerability also exists in sctp_getsockopt_peer_addrs_old().
It's a bit more difficult to trigger since there is a dependency on
the peer being multihomed as well, but it's still possible to cause the
overwrite.
-vlad
>
> Signed-off-by: David S. Miller <davem@davemloft.net>
> ---
> net/sctp/socket.c | 4 +++-
> 1 files changed, 3 insertions(+), 1 deletions(-)
>
> diff --git a/net/sctp/socket.c b/net/sctp/socket.c
> index e7e3baf..0dbcde6 100644
> --- a/net/sctp/socket.c
> +++ b/net/sctp/socket.c
> @@ -4401,7 +4401,9 @@ static int sctp_getsockopt_local_addrs_old(struct sock *sk, int len,
> if (copy_from_user(&getaddrs, optval, len))
> return -EFAULT;
>
> - if (getaddrs.addr_num <= 0) return -EINVAL;
> + if (getaddrs.addr_num <= 0 ||
> + getaddrs.addr_num >= (INT_MAX / sizeof(union sctp_addr)))
> + return -EINVAL;
> /*
> * For UDP-style sockets, id specifies the association to query.
> * If the id field is set to the value '0' then the locally bound
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH]: SCTP length validation.
2008-06-21 15:55 ` Vlad Yasevich
@ 2008-06-22 19:32 ` David Miller
2008-06-23 15:59 ` Vlad Yasevich
0 siblings, 1 reply; 5+ messages in thread
From: David Miller @ 2008-06-22 19:32 UTC (permalink / raw)
To: vladislav.yasevich; +Cc: netdev, linux-sctp
From: Vlad Yasevich <vladislav.yasevich@hp.com>
Date: Sat, 21 Jun 2008 11:55:19 -0400
> The same vulnerability also exists in sctp_getsockopt_peer_addrs_old().
> It's a bit more difficult to trigger since there is a dependency on
> the peer being multihomed as well, but it's still possible to cause the
> overwrite.
I can't see how that's possible. This case looks harmless to
me.
The kernel side accesses are perfectly protected. The kernel
will only access the actual address list stored via:
list_for_each_entry(from, &asoc->peer.transport_addr_list,
transports) {
...
cnt ++;
if (cnt >= getaddrs.addr_num) break;
}
getaddrs.addr_num = cnt;
Copies are only made to userspace, and the given ->addr_num only
serves as an early break-out from that loop. I mean, take a look,
those lines in the above are the only aaccesses made to the user's
provided addr_num value.
There is no possibility to use strange ->addr_num values
in order to read or write kernel memory outside of the
intended bounds.
I don't even see any value to adding new checks here.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH]: SCTP length validation.
2008-06-22 19:32 ` David Miller
@ 2008-06-23 15:59 ` Vlad Yasevich
2008-06-23 21:42 ` David Miller
0 siblings, 1 reply; 5+ messages in thread
From: Vlad Yasevich @ 2008-06-23 15:59 UTC (permalink / raw)
To: David Miller; +Cc: netdev, linux-sctp
David Miller wrote:
> From: Vlad Yasevich <vladislav.yasevich@hp.com>
> Date: Sat, 21 Jun 2008 11:55:19 -0400
>
>> The same vulnerability also exists in sctp_getsockopt_peer_addrs_old().
>> It's a bit more difficult to trigger since there is a dependency on
>> the peer being multihomed as well, but it's still possible to cause the
>> overwrite.
>
> I can't see how that's possible. This case looks harmless to
> me.
>
> The kernel side accesses are perfectly protected. The kernel
> will only access the actual address list stored via:
>
> list_for_each_entry(from, &asoc->peer.transport_addr_list,
> transports) {
> ...
> cnt ++;
> if (cnt >= getaddrs.addr_num) break;
> }
> getaddrs.addr_num = cnt;
>
> Copies are only made to userspace, and the given ->addr_num only
> serves as an early break-out from that loop. I mean, take a look,
> those lines in the above are the only aaccesses made to the user's
> provided addr_num value.
>
> There is no possibility to use strange ->addr_num values
> in order to read or write kernel memory outside of the
> intended bounds.
>
> I don't even see any value to adding new checks here.
>
You are right. I didn't look far enough. Since there is no kmalloc(),
the overflow of kernel memory is not possible, and copy_to_user should
take care of any overflows of the user memory.
-vlad
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH]: SCTP length validation.
2008-06-23 15:59 ` Vlad Yasevich
@ 2008-06-23 21:42 ` David Miller
0 siblings, 0 replies; 5+ messages in thread
From: David Miller @ 2008-06-23 21:42 UTC (permalink / raw)
To: vladislav.yasevich; +Cc: netdev, linux-sctp
From: Vlad Yasevich <vladislav.yasevich@hp.com>
Date: Mon, 23 Jun 2008 11:59:43 -0400
> David Miller wrote:
> > From: Vlad Yasevich <vladislav.yasevich@hp.com>
> > Date: Sat, 21 Jun 2008 11:55:19 -0400
> >
> >> The same vulnerability also exists in sctp_getsockopt_peer_addrs_old().
> >> It's a bit more difficult to trigger since there is a dependency on
> >> the peer being multihomed as well, but it's still possible to cause the
> >> overwrite.
> >
> > I can't see how that's possible. This case looks harmless to
> > me.
> >
> > The kernel side accesses are perfectly protected. The kernel
> > will only access the actual address list stored via:
...
>
> You are right. I didn't look far enough. Since there is no kmalloc(),
> the overflow of kernel memory is not possible, and copy_to_user should
> take care of any overflows of the user memory.
Thanks for double-checking my analysis Vlad.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2008-06-23 21:42 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-06-21 5:12 [PATCH]: SCTP length validation David Miller
2008-06-21 15:55 ` Vlad Yasevich
2008-06-22 19:32 ` David Miller
2008-06-23 15:59 ` Vlad Yasevich
2008-06-23 21:42 ` David Miller
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).