* [PATCH] Fix getsockopt(SO_PEERNAME) buffer size against potential future buffer overflow
@ 2014-09-28 13:55 Samuel Thibault
2014-09-30 4:59 ` David Miller
0 siblings, 1 reply; 2+ messages in thread
From: Samuel Thibault @ 2014-09-28 13:55 UTC (permalink / raw)
To: linux-kernel, davem, netdev; +Cc: akpm
In net/core/sock.c's sock_getsockopt, the address buffer size is
hardcoded to 128. It happens that sizeof(struct sockaddr_storage) is
indeed 128, but that is just luck and would probably not get updated
whenever sockaddr_storage would grow. This patch makes it simply use
sockaddr_storage instead.
Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
--- a/net/core/sock.c
+++ b/net/core/sock.c
@@ -1155,13 +1155,13 @@ int sock_getsockopt(struct socket *sock,
case SO_PEERNAME:
{
- char address[128];
+ struct sockaddr_storage address;
- if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
+ if (sock->ops->getname(sock, (struct sockaddr *)&address, &lv, 2))
return -ENOTCONN;
if (lv < len)
return -EINVAL;
- if (copy_to_user(optval, address, len))
+ if (copy_to_user(optval, &address, len))
return -EFAULT;
goto lenout;
}
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] Fix getsockopt(SO_PEERNAME) buffer size against potential future buffer overflow
2014-09-28 13:55 [PATCH] Fix getsockopt(SO_PEERNAME) buffer size against potential future buffer overflow Samuel Thibault
@ 2014-09-30 4:59 ` David Miller
0 siblings, 0 replies; 2+ messages in thread
From: David Miller @ 2014-09-30 4:59 UTC (permalink / raw)
To: samuel.thibault; +Cc: linux-kernel, netdev, akpm
From: Samuel Thibault <samuel.thibault@ens-lyon.org>
Date: Sun, 28 Sep 2014 15:55:45 +0200
> In net/core/sock.c's sock_getsockopt, the address buffer size is
> hardcoded to 128. It happens that sizeof(struct sockaddr_storage) is
> indeed 128, but that is just luck and would probably not get updated
> whenever sockaddr_storage would grow. This patch makes it simply use
> sockaddr_storage instead.
>
> Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
sockaddr_storage's size is a user exported API and therefore can
never, ever, change.
If you want to change 128 to _K_SS_MAXSIZE or similar, fine.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2014-09-30 4:59 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-09-28 13:55 [PATCH] Fix getsockopt(SO_PEERNAME) buffer size against potential future buffer overflow Samuel Thibault
2014-09-30 4:59 ` 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).