IPv6:remove duplicate check of optlen when setsockopt with IPV6_PKTINFO option
Subsystems (3)
PATCH 1/1 IPv6:remove duplicate check of optlen when setsockopt with IPV6_PKTINFO option
Actually the condition (optlen == 0) is included in (optlen < sizeof(struct in6_pktinfo)), so we do not need to check it separately.
--- net/ipv6/ipv6_sockglue.c | 4 +--- 1 files changed, 1 insertions(+), 3 deletions(-)
net/ipv6/ipv6_sockglue.c +1 -3
@@ -399,9 +399,7 @@ sticky_done: {struct in6_pktinfo pkt; -if (optlen ==0 ) - goto e_inval; -else if (optlen <sizeof (struct in6_pktinfo ) || optval ==NULL ) +if (optlen <sizeof (struct in6_pktinfo ) || optval ==NULL ) goto e_inval;if (copy_from_user (&pkt, optval,sizeof (struct in6_pktinfo ))) {
Signature · 4 lines
1.6.0.3 -- Regards Yang Hongyang
Quoted 2 lines · Yang Hongyang
Actually the condition (optlen == 0) is included in (optlen <
sizeof(struct in6_pktinfo)), so we do not need to check it separately.
You don't need to check optval == NULL either since that's the job of copy_from_user.
Cheers,
Signature · 4 lines
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txtQuoted 6 lines · Herbert Xu
Quoted 2 lines · Yang Hongyang
Actually the condition (optlen == 0) is included in (optlen <
sizeof(struct in6_pktinfo)), so we do not need to check it separately.You don't need to check optval == NULL either since that's the job of
copy_from_user.
If optval==NULL, what we should return?EINVAL or EFAULT? If it is EINVAL,then we should check it .otherwise it's the job of copy_from_user
Quoted 2 lines
Cheers,
Signature · 2 lines
Regards Yang Hongyang
Quoted 7 lines · Yang Hongyang
Quoted 5 lines · Herbert Xu
Quoted 3 lines · Yang Hongyang
Actually the condition (optlen == 0) is included in (optlen <
sizeof(struct in6_pktinfo)), so we do not need to check it separately.
Quoted 7 lines
Quoted 3 lines
You don't need to check optval == NULL either since that's the job of
copy_from_user.If optval==NULL, what we should return?EINVAL or EFAULT?
If it is EINVAL,then we should check it .otherwise it's the job ofcopy_from_user
I think if optval==NULL, the in6_pktinfo which is set should be remove. So, you should handle optval==NULL. Not just return error.
Quoted 6 lines
Quoted 3 lines
Cheers,
Quoted 13 lines · Wei Yongjun
Quoted 12 lines · Yang Hongyang
Quoted 9 lines · Herbert Xu
Quoted 4 lines · Yang Hongyang
Actually the condition (optlen == 0) is included in (optlen <
sizeof(struct in6_pktinfo)),
so we do not need to check it separately.You don't need to check optval == NULL either since that's the job of
copy_from_user.
Quoted 7 lines
Quoted 4 lines
If optval==NULL, what we should return?EINVAL or EFAULT? If it is EINVAL,then we should check it .otherwise it's the job of
copy_from_userI think if optval==NULL, the
in6_pktinfowhich is set should be remove. So, you should handle optval==NULL. Not just return error.
There's no RFC defines the behavior above,but:
RFC3542 said The application can remove any sticky Routing header or sticky
Destination options header or sticky Hop-by-Hop options header by calling setsockopt() with a zero option length.
So,do we need to allow remove any sticky pktinfo option by calling setsockopt() with a zero option length?
Quoted 10 lines
Quoted 7 lines
Quoted 4 lines
Cheers,
Signature · 2 lines
Regards Yang Hongyang
Quoted 20 lines · Yang Hongyang
Quoted 12 lines · Wei Yongjun
Quoted 11 lines · Yang Hongyang
Quoted 9 lines · Herbert Xu
Quoted 4 lines · Yang Hongyang
Actually the condition (optlen == 0) is included in (optlen <
sizeof(struct in6_pktinfo)),
so we do not need to check it separately.You don't need to check optval == NULL either since that's the job of
copy_from_user.Quoted 6 lines
Quoted 4 lines
If optval==NULL, what we should return?EINVAL or EFAULT? If it is EINVAL,then we should check it .otherwise it's the job of
copy_from_userI think if optval==NULL, the
in6_pktinfowhich is set should be remove. So, you should handle optval==NULL. Not just return error.
Quoted 8 lines
There's no RFC defines the behavior above,but:
RFC3542 said The application can remove any sticky Routing header or sticky
Destination options header or sticky Hop-by-Hop options header by callingsetsockopt()with a zero option length.So,do we need to allow remove any sticky pktinfo option by calling
setsockopt()with a zero option length?
Can remove the option using seting in6_pktinfo struct wiht ipi6_ifindex=0,ipi6_ifindex=IN6ADDR_ANY_INIT.
If no RFC definition, not to reset with optlen=0,
for example IPV6_TCLASS, PV6_2292DSTOPTS.
Signature · 2 lines
Best Regards Shan Wei
Re: [PATCHv2]IPv6:remove duplicate check when setsockopt with IPV6_PKTINFO option
Actually the condition (optlen == 0) is included in (optlen < sizeof(struct in6_pktinfo)), so we do not need to check it separately.
We don't need to check (optval==NULL) either,because copy_from_user() will do the job.
--- net/ipv6/ipv6_sockglue.c | 4 +--- 1 files changed, 1 insertions(+), 3 deletions(-)
net/ipv6/ipv6_sockglue.c +1 -3
@@ -399,9 +399,7 @@ sticky_done: {struct in6_pktinfo pkt; -if (optlen ==0 ) - goto e_inval; -else if (optlen <sizeof (struct in6_pktinfo ) || optval ==NULL ) +if (optlen <sizeof (struct in6_pktinfo )) goto e_inval;if (copy_from_user (&pkt, optval,sizeof (struct in6_pktinfo ))) {
Signature · 1 line
1.6.0.3
Quoted 35 lines · Shan Wei
Quoted 19 lines · Yang Hongyang
Quoted 12 lines · Wei Yongjun
Quoted 11 lines · Yang Hongyang
Quoted 9 lines · Herbert Xu
Quoted 4 lines · Yang Hongyang
Actually the condition (optlen == 0) is included in (optlen <
sizeof(struct in6_pktinfo)),
so we do not need to check it separately.You don't need to check optval == NULL either since that's the job of
copy_from_user.Quoted 6 lines
Quoted 4 lines
If optval==NULL, what we should return?EINVAL or EFAULT? If it is EINVAL,then we should check it .otherwise it's the job of
copy_from_userI think if optval==NULL, the
in6_pktinfowhich is set should be remove. So, you should handle optval==NULL. Not just return error.Quoted 8 lines
There's no RFC defines the behavior above,but:
RFC3542 said The application can remove any sticky Routing header or sticky
Destination options header or sticky Hop-by-Hop options header by callingsetsockopt()with a zero option length.So,do we need to allow remove any sticky pktinfo option by calling
setsockopt()with a zero option length?Can remove the option using seting
in6_pktinfostruct wiht ipi6_ifindex=0,ipi6_ifindex=IN6ADDR_ANY_INIT.If no RFC definition, not to reset with optlen=0,
for exampleIPV6_TCLASS,PV6_2292DSTOPTS.
Signature · 2 lines
Regards Yang Hongyang
Quoted 4 lines · Yang Hongyang
If optval==NULL, what we should return?EINVAL or EFAULT? If it is EINVAL,then we should check it .otherwise it's the job of
copy_from_user
I think EFAULT is fine. We return that elsewhere as well.
Cheers,
Signature · 4 lines
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txtDavid Miller
maintainerFrom: Herbert Xu <[email protected]>
Date: Wed, 14 Jan 2009 15:48:56 +1100
Quoted 7 lines
Quoted 4 lines · Yang Hongyang
If optval==NULL, what we should return?EINVAL or EFAULT? If it is EINVAL,then we should check it .otherwise it's the job of
copy_from_userI think EFAULT is fine. We return that elsewhere as well.
Actually, we return EINVAL just a few lines above this code block for some other socket option cases when optval==NULL.
So for consistency I'm applying Yang's original patch to net-next-2.6
Thanks.
Quoted 3 lines · David Miller
Actually, we return EINVAL just a few lines above this code block for some other socket option cases when optval==NULL.
Well the very next option IPV6_2292PKTOPTIONS returns EFAULT by virtue of not explicitly checking optval == NULL :)
Cheers,
Signature · 4 lines
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txtQuoted 7 lines · Herbert Xu
Quoted 3 lines · David Miller
Actually, we return EINVAL just a few lines above this code block for some other socket option cases when optval==NULL.
Well the very next option
IPV6_2292PKTOPTIONSreturns EFAULT by virtue of not explicitly checking optval == NULL :)
In fact checking for a NULL pointer is strictly speaking wrong since NULL may actually have been mapped in user-space :)
Cheers,
Signature · 4 lines
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txtQuoted 9 lines · Herbert Xu
Quoted 5 lines · Herbert Xu
Quoted 2 lines · David Miller
Actually, we return EINVAL just a few lines above this code block for some other socket option cases when optval==NULL.
Well the very next option
IPV6_2292PKTOPTIONSreturns EFAULT by virtue of not explicitly checking optval == NULL :)In fact checking for a NULL pointer is strictly speaking wrong since NULL may actually have been mapped in user-space :)
But there are some cases that user-space passes a NULL pointer to the kernel,Otherwise,copy_from_user needn't to cheak the NULL pointer either.:)
By the way,I think most part of the ipv6 socket option implementation are kind of ugly:)
Quoted 2 lines
Cheers,
Signature · 2 lines
Regards Yang Hongyang
David Miller
maintainerFrom: Herbert Xu <[email protected]>
Date: Thu, 15 Jan 2009 16:04:49 +1100
Quoted 7 lines · David Miller
Quoted 3 lines
Actually, we return EINVAL just a few lines above this code block for some other socket option cases when optval==NULL.
Well the very next option
IPV6_2292PKTOPTIONSreturns EFAULT by virtue of not explicitly checking optval == NULL :)
Touche' :-)
Quoted 7 lines · David Miller
From: Herbert Xu <[email protected]>
Date: Wed, 14 Jan 2009 15:48:56 +1100Quoted 4 lines
Quoted 3 lines · Yang Hongyang
If optval==NULL, what we should return?EINVAL or EFAULT? If it is EINVAL,then we should check it .otherwise it's the job of
copy_from_user
Quoted 7 lines
Quoted 1 line
I think EFAULT is fine. We return that elsewhere as well.
Actually, we return EINVAL just a few lines above this code block for some other socket option cases when optval==NULL.
So for consistency I'm applying Yang's original patch to net-next-2.6
Dave,there are some of the code elsewhere return EFAULT when optval=NULL,I will post a patch to fix them:)
Quoted 4 lines
Thanks.
Signature · 2 lines
Regards Yang Hongyang
Quoted 3 lines · Yang Hongyang
Dave,there are some of the code elsewhere return EFAULT when optval=NULL,I will post a patch to fix them:)
I disagree. The concept of a user-space NULL pointer is different to that of a kernel-space NULL pointer, so the kernel should not be treating a user-space NULL pointer differently than any other pointer.
Cheers,
Signature · 4 lines
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txtDavid Miller
maintainerFrom: Herbert Xu <[email protected]>
Date: Thu, 15 Jan 2009 16:37:02 +1100
Quoted 9 lines · Yang Hongyang
Quoted 3 lines
Dave,there are some of the code elsewhere return EFAULT when optval=NULL,I will post a patch to fix them:)
I disagree. The concept of a user-space NULL pointer is different to that of a kernel-space NULL pointer, so the kernel should not be treating a user-space NULL pointer differently than any other pointer.
I agree with Herbert, but of course we have to adhere to cases where APIs actually define a user NULL pointer to have a specific meaning.
Quoted 4 lines · David Miller
I agree with Herbert, but of course we have to adhere to cases where APIs actually define a user NULL pointer to have a specific meaning.
Absolutely. Although AFAIK the relevant RFCs here only use the notion of a zero option length for such purposes rather than NULL pointers (presumably because the meaning of NULL pointers are context dependent).
Cheers,
Signature · 4 lines
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txtQuoted 6 lines · David Miller
From: Herbert Xu <[email protected]>
Date: Thu, 15 Jan 2009 16:37:02 +1100Quoted 3 lines · Yang Hongyang
Quoted 2 lines
Dave,there are some of the code elsewhere return EFAULT when optval=NULL,I will post a patch to fix them:)
Quoted 10 lines
Quoted 4 lines
I disagree. The concept of a user-space NULL pointer is different to that of a kernel-space NULL pointer, so the kernel should not be treating a user-space NULL pointer differently than any other pointer.
I agree with Herbert, but of course we have to adhere to cases where APIs actually define a user NULL pointer to have a specific meaning.
Agreed.Seems that Patch v2 is correct according to the discussion.^_^
Signature · 2 lines
Regards Yang Hongyang