Skip to content

Commit

Permalink
[IPV6]: Check length of optval provided by user in setsockopt().
Browse files Browse the repository at this point in the history
Check length of setsockopt's optval, which provided by user, before copy it
from user space.
For POSIX compliant, return -EINVAL for setsockopt of short lengths.

Signed-off-by: Wang Chen <wangchen@cn.fujitsu.com>
Signed-off-by: YOSHIFUJI Hideaki <yoshfuji@linux-ipv6.org>
  • Loading branch information
Wang Chen authored and YOSHIFUJI Hideaki committed Apr 12, 2008
1 parent 7f1eced commit a28398b
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions net/ipv6/ipv6_sockglue.c
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,9 @@ static int do_ipv6_setsockopt(struct sock *sk, int level, int optname,
{
struct ipv6_mreq mreq;

if (optlen < sizeof(struct ipv6_mreq))
goto e_inval;

retv = -EPROTO;
if (inet_sk(sk)->is_icsk)
break;
Expand All @@ -468,7 +471,7 @@ static int do_ipv6_setsockopt(struct sock *sk, int level, int optname,
{
struct ipv6_mreq mreq;

if (optlen != sizeof(struct ipv6_mreq))
if (optlen < sizeof(struct ipv6_mreq))
goto e_inval;

retv = -EFAULT;
Expand All @@ -487,6 +490,9 @@ static int do_ipv6_setsockopt(struct sock *sk, int level, int optname,
struct group_req greq;
struct sockaddr_in6 *psin6;

if (optlen < sizeof(struct group_req))
goto e_inval;

retv = -EFAULT;
if (copy_from_user(&greq, optval, sizeof(struct group_req)))
break;
Expand All @@ -511,7 +517,7 @@ static int do_ipv6_setsockopt(struct sock *sk, int level, int optname,
struct group_source_req greqs;
int omode, add;

if (optlen != sizeof(struct group_source_req))
if (optlen < sizeof(struct group_source_req))
goto e_inval;
if (copy_from_user(&greqs, optval, sizeof(greqs))) {
retv = -EFAULT;
Expand Down

0 comments on commit a28398b

Please sign in to comment.