IPV6: make ipv6_getsockopt_sticky honor user's buffer size
Subsystems (3)
Make sure not to copy_to_user more than user's buffer can handle (we already checked the min, just use it) in ipv6_getsockopt_sticky. And while there, minor whitespace cleanup now that ipv6_getsockopt_sticky call can nicely fit on one line.
---
net/ipv6/ipv6_sockglue.c +2 -3
@@ -805,7 +805,7 @@ static int ipv6_getsockopt_sticky(struct sock *sk, struct ipv6_txoptions *opt, hdr = opt->hopopt; len =min_t (int, len,ipv6_optlen (hdr)); -if (copy_to_user (optval, hdr,ipv6_optlen (hdr))) +if (copy_to_user (optval, hdr, len))return -EFAULT ;return len; }
@@ -944,8 +944,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname, {lock_sock (sk); - len =ipv6_getsockopt_sticky (sk, np->opt, - optval, len); + len =ipv6_getsockopt_sticky (sk, np->opt, optval, len);release_sock (sk);return put_user (len, optlen); }
David Miller
maintainerFrom: Chris Wright <[email protected]>
Date: Wed, 7 Mar 2007 23:10:48 -0800
Quoted 6 lines
Make sure not to
copy_to_usermore than user's buffer can handle (we already checked the min, just use it) inipv6_getsockopt_sticky. And while there, minor whitespace cleanup now thatipv6_getsockopt_stickycall can nicely fit on one line.Signed-off-by Chris Wright <[email protected]>
I wonder about this :-)
This gives the user now way to figure out that ipv6_optlen(hdr) is larger than the len they supplied.
In other situations usually we validate the length and return -EINVAL if it is too small.
That might be the thing to do in this case too.
In article <[email protected]> (at Thu, 08 Mar 2007 14:38:04 -0800 (PST)), David Miller <[email protected]> says:
Quoted 12 lines
From: Chris Wright <[email protected]>
Date: Wed, 7 Mar 2007 23:10:48 -0800Quoted 6 lines
Make sure not to
copy_to_usermore than user's buffer can handle (we already checked the min, just use it) inipv6_getsockopt_sticky. And while there, minor whitespace cleanup now thatipv6_getsockopt_stickycall can nicely fit on one line.Signed-off-by Chris Wright <[email protected]>I wonder about this :-)
Quoted 7 lines
This gives the user now way to figure out that
ipv6_optlen(hdr)is larger than the len they supplied.In other situations usually we validate the length and return
-EINVALif it is too small.That might be the thing to do in this case too.
We should give truncated result and return full length from the POSIX POV.
--yoshfuji
David Miller
maintainerFrom: YOSHIFUJI Hideaki / 吉藤英明 <[email protected]>
Date: Fri, 09 Mar 2007 09:49:32 +0900 (JST)
Quoted 2 lines
We should give truncated result and return full length from the POSIX POV.
True, and the user would know what happened because it knows both the original length it gave and the larger one the kernel gave as the return value.