* [PATCH net] net: socket: add check for negative optlen in compat setsockopt
@ 2019-02-20 21:34 Jann Horn
2019-02-22 19:50 ` David Miller
0 siblings, 1 reply; 2+ messages in thread
From: Jann Horn @ 2019-02-20 21:34 UTC (permalink / raw)
To: David S. Miller, jannh; +Cc: netdev, linux-kernel
__sys_setsockopt() already checks for `optlen < 0`. Add an equivalent check
to the compat path for robustness. This has to be `> INT_MAX` instead of
`< 0` because the signedness of `optlen` is different here.
Signed-off-by: Jann Horn <jannh@google.com>
---
net/compat.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/net/compat.c b/net/compat.c
index 959d1c51826d..3d348198004f 100644
--- a/net/compat.c
+++ b/net/compat.c
@@ -388,8 +388,12 @@ static int __compat_sys_setsockopt(int fd, int level, int optname,
char __user *optval, unsigned int optlen)
{
int err;
- struct socket *sock = sockfd_lookup(fd, &err);
+ struct socket *sock;
+
+ if (optlen > INT_MAX)
+ return -EINVAL;
+ sock = sockfd_lookup(fd, &err);
if (sock) {
err = security_socket_setsockopt(sock, level, optname);
if (err) {
--
2.21.0.rc0.258.g878e2cd30e-goog
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH net] net: socket: add check for negative optlen in compat setsockopt
2019-02-20 21:34 [PATCH net] net: socket: add check for negative optlen in compat setsockopt Jann Horn
@ 2019-02-22 19:50 ` David Miller
0 siblings, 0 replies; 2+ messages in thread
From: David Miller @ 2019-02-22 19:50 UTC (permalink / raw)
To: jannh; +Cc: netdev, linux-kernel
From: Jann Horn <jannh@google.com>
Date: Wed, 20 Feb 2019 22:34:54 +0100
> __sys_setsockopt() already checks for `optlen < 0`. Add an equivalent check
> to the compat path for robustness. This has to be `> INT_MAX` instead of
> `< 0` because the signedness of `optlen` is different here.
>
> Signed-off-by: Jann Horn <jannh@google.com>
Applied and queued up for -stable, thanks Jann.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2019-02-22 19:50 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-20 21:34 [PATCH net] net: socket: add check for negative optlen in compat setsockopt Jann Horn
2019-02-22 19:50 ` 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).