netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] net: error on unsupported IP setsockopts in IPv6
@ 2022-06-09 15:26 Richard Gobert
  2022-06-11  5:16 ` Jakub Kicinski
  0 siblings, 1 reply; 3+ messages in thread
From: Richard Gobert @ 2022-06-09 15:26 UTC (permalink / raw)
  To: davem, yoshfuji, dsahern, kuba, pabeni, netdev

The IP_TTL and IP_TOS sockopts are unsupported for IPv6 sockets,
this bug was reported previously to the kernel bugzilla [1].
Make the IP_TTL and IP_TOS sockopts return an error for AF_INET6 sockets.

[1] https://bugzilla.kernel.org/show_bug.cgi?id=212585

Signed-off-by: Richard Gobert <richardbgobert@gmail.com>
---
 net/ipv6/ipv6_sockglue.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
index 222f6bf220ba..2cdaa8f3a8f2 100644
--- a/net/ipv6/ipv6_sockglue.c
+++ b/net/ipv6/ipv6_sockglue.c
@@ -1012,8 +1012,16 @@ int ipv6_setsockopt(struct sock *sk, int level, int optname, sockptr_t optval,
 {
 	int err;
 
-	if (level == SOL_IP && sk->sk_type != SOCK_RAW)
-		return udp_prot.setsockopt(sk, level, optname, optval, optlen);
+	if (level == SOL_IP && sk->sk_type != SOCK_RAW) {
+		switch (optname) {
+		/* Some IP opts are not supported for IPv6 sockets */
+		case IP_TTL:
+		case IP_TOS:
+			return -ENOPROTOOPT;
+		default:
+			return udp_prot.setsockopt(sk, level, optname, optval, optlen);
+		}
+	}
 
 	if (level != SOL_IPV6)
 		return -ENOPROTOOPT;
-- 
2.36.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] net: error on unsupported IP setsockopts in IPv6
  2022-06-09 15:26 [PATCH] net: error on unsupported IP setsockopts in IPv6 Richard Gobert
@ 2022-06-11  5:16 ` Jakub Kicinski
  2022-06-11 16:55   ` David Ahern
  0 siblings, 1 reply; 3+ messages in thread
From: Jakub Kicinski @ 2022-06-11  5:16 UTC (permalink / raw)
  To: Richard Gobert; +Cc: davem, yoshfuji, dsahern, pabeni, netdev

On Thu, 9 Jun 2022 17:26:10 +0200 Richard Gobert wrote:
> The IP_TTL and IP_TOS sockopts are unsupported for IPv6 sockets,
> this bug was reported previously to the kernel bugzilla [1].
> Make the IP_TTL and IP_TOS sockopts return an error for AF_INET6 sockets.
> 
> [1] https://bugzilla.kernel.org/show_bug.cgi?id=212585

This is a little risky because applications may set both v4 and v6
options and expect the correct one to "stick". Obviously it's not 
the way we would have written this code today, but is there any harm?
Also why just those two options?

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] net: error on unsupported IP setsockopts in IPv6
  2022-06-11  5:16 ` Jakub Kicinski
@ 2022-06-11 16:55   ` David Ahern
  0 siblings, 0 replies; 3+ messages in thread
From: David Ahern @ 2022-06-11 16:55 UTC (permalink / raw)
  To: Jakub Kicinski, Richard Gobert; +Cc: davem, yoshfuji, pabeni, netdev

On 6/10/22 11:16 PM, Jakub Kicinski wrote:
> On Thu, 9 Jun 2022 17:26:10 +0200 Richard Gobert wrote:
>> The IP_TTL and IP_TOS sockopts are unsupported for IPv6 sockets,
>> this bug was reported previously to the kernel bugzilla [1].
>> Make the IP_TTL and IP_TOS sockopts return an error for AF_INET6 sockets.
>>
>> [1] https://bugzilla.kernel.org/show_bug.cgi?id=212585
> 
> This is a little risky because applications may set both v4 and v6
> options and expect the correct one to "stick". Obviously it's not 
> the way we would have written this code today, but is there any harm?
> Also why just those two options?

agreed, I do not believe this can be changed. The values will not be
used for ipv6 packets, so the exposure should just be a matter of
allowing the setting on a socket.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-06-11 16:55 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-09 15:26 [PATCH] net: error on unsupported IP setsockopts in IPv6 Richard Gobert
2022-06-11  5:16 ` Jakub Kicinski
2022-06-11 16:55   ` David Ahern

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).