netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net] net: validate SO_TXTIME clockid coming from  userspace
@ 2024-05-28 22:49 Abhishek Chauhan
  2024-05-29  1:15 ` Martin KaFai Lau
  2024-05-29 13:58 ` Willem de Bruijn
  0 siblings, 2 replies; 7+ messages in thread
From: Abhishek Chauhan @ 2024-05-28 22:49 UTC (permalink / raw)
  To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	netdev, linux-kernel, Andrew Halaney, Willem de Bruijn,
	Martin KaFai Lau, Martin KaFai Lau, Daniel Borkmann, bpf
  Cc: kernel, syzbot+d7b227731ec589e7f4f0, syzbot+30a35a2e9c5067cc43fa

Currently there are no strict checks while setting SO_TXTIME
from userspace. With the recent development in skb->tstamp_type
clockid with unsupported clocks results in warn_on_once, which causes
unnecessary aborts in some systems which enables panic on warns.

Add validation in setsockopt to support only CLOCK_REALTIME,
CLOCK_MONOTONIC and CLOCK_TAI to be set from userspace.

Link: https://lore.kernel.org/netdev/bc037db4-58bb-4861-ac31-a361a93841d3@linux.dev/
Link: https://lore.kernel.org/lkml/20240509211834.3235191-1-quic_abchauha@quicinc.com/
Fixes: 1693c5db6ab8 ("net: Add additional bit to support clockid_t timestamp type")
Reported-by: syzbot+d7b227731ec589e7f4f0@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=d7b227731ec589e7f4f0
Reported-by: syzbot+30a35a2e9c5067cc43fa@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=30a35a2e9c5067cc43fa
Signed-off-by: Abhishek Chauhan <quic_abchauha@quicinc.com>
---
 net/core/sock.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/net/core/sock.c b/net/core/sock.c
index 8629f9aecf91..f8374be9d8c9 100644
--- a/net/core/sock.c
+++ b/net/core/sock.c
@@ -1083,6 +1083,17 @@ bool sockopt_capable(int cap)
 }
 EXPORT_SYMBOL(sockopt_capable);
 
+static int sockopt_validate_clockid(int value)
+{
+	switch (value) {
+	case CLOCK_REALTIME:
+	case CLOCK_MONOTONIC:
+	case CLOCK_TAI:
+		return 0;
+	}
+	return -EINVAL;
+}
+
 /*
  *	This is meant for all protocols to use and covers goings on
  *	at the socket level. Everything here is generic.
@@ -1497,6 +1508,11 @@ int sk_setsockopt(struct sock *sk, int level, int optname,
 			ret = -EPERM;
 			break;
 		}
+
+		ret = sockopt_validate_clockid(sk_txtime.clockid);
+		if (ret)
+			break;
+
 		sock_valbool_flag(sk, SOCK_TXTIME, true);
 		sk->sk_clockid = sk_txtime.clockid;
 		sk->sk_txtime_deadline_mode =
-- 
2.25.1


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

* Re: [PATCH net] net: validate SO_TXTIME clockid coming from userspace
  2024-05-28 22:49 [PATCH net] net: validate SO_TXTIME clockid coming from userspace Abhishek Chauhan
@ 2024-05-29  1:15 ` Martin KaFai Lau
  2024-05-29  3:32   ` Abhishek Chauhan (ABC)
  2024-05-29 13:58 ` Willem de Bruijn
  1 sibling, 1 reply; 7+ messages in thread
From: Martin KaFai Lau @ 2024-05-29  1:15 UTC (permalink / raw)
  To: Abhishek Chauhan
  Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	netdev, linux-kernel, Andrew Halaney, Willem de Bruijn,
	Martin KaFai Lau, Daniel Borkmann, bpf, kernel,
	syzbot+d7b227731ec589e7f4f0, syzbot+30a35a2e9c5067cc43fa

On 5/28/24 3:49 PM, Abhishek Chauhan wrote:
> Currently there are no strict checks while setting SO_TXTIME
> from userspace. With the recent development in skb->tstamp_type
> clockid with unsupported clocks results in warn_on_once, which causes
> unnecessary aborts in some systems which enables panic on warns.
> 
> Add validation in setsockopt to support only CLOCK_REALTIME,
> CLOCK_MONOTONIC and CLOCK_TAI to be set from userspace.
> 
> Link: https://lore.kernel.org/netdev/bc037db4-58bb-4861-ac31-a361a93841d3@linux.dev/
> Link: https://lore.kernel.org/lkml/20240509211834.3235191-1-quic_abchauha@quicinc.com/
> Fixes: 1693c5db6ab8 ("net: Add additional bit to support clockid_t timestamp type")

Patch lgtm. This should target for net-next instead of net. The Fixes patch is 
in net-next only.

Acked-by: Martin KaFai Lau <martin.lau@kernel.org>


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

* Re: [PATCH net] net: validate SO_TXTIME clockid coming from userspace
  2024-05-29  1:15 ` Martin KaFai Lau
@ 2024-05-29  3:32   ` Abhishek Chauhan (ABC)
  0 siblings, 0 replies; 7+ messages in thread
From: Abhishek Chauhan (ABC) @ 2024-05-29  3:32 UTC (permalink / raw)
  To: Martin KaFai Lau
  Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	netdev, linux-kernel, Andrew Halaney, Willem de Bruijn,
	Martin KaFai Lau, Daniel Borkmann, bpf, kernel,
	syzbot+d7b227731ec589e7f4f0, syzbot+30a35a2e9c5067cc43fa



On 5/28/2024 6:15 PM, Martin KaFai Lau wrote:
> On 5/28/24 3:49 PM, Abhishek Chauhan wrote:
>> Currently there are no strict checks while setting SO_TXTIME
>> from userspace. With the recent development in skb->tstamp_type
>> clockid with unsupported clocks results in warn_on_once, which causes
>> unnecessary aborts in some systems which enables panic on warns.
>>
>> Add validation in setsockopt to support only CLOCK_REALTIME,
>> CLOCK_MONOTONIC and CLOCK_TAI to be set from userspace.
>>
>> Link: https://lore.kernel.org/netdev/bc037db4-58bb-4861-ac31-a361a93841d3@linux.dev/
>> Link: https://lore.kernel.org/lkml/20240509211834.3235191-1-quic_abchauha@quicinc.com/
>> Fixes: 1693c5db6ab8 ("net: Add additional bit to support clockid_t timestamp type")
> 
> Patch lgtm. This should target for net-next instead of net. The Fixes patch is in net-next only.
> 
Thanks Martin. Let me raise a patch on net-next and add your acked-by to it as well. 

> Acked-by: Martin KaFai Lau <martin.lau@kernel.org>
> 

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

* Re: [PATCH net] net: validate SO_TXTIME clockid coming from  userspace
  2024-05-28 22:49 [PATCH net] net: validate SO_TXTIME clockid coming from userspace Abhishek Chauhan
  2024-05-29  1:15 ` Martin KaFai Lau
@ 2024-05-29 13:58 ` Willem de Bruijn
  2024-05-29 15:49   ` Abhishek Chauhan (ABC)
  1 sibling, 1 reply; 7+ messages in thread
From: Willem de Bruijn @ 2024-05-29 13:58 UTC (permalink / raw)
  To: Abhishek Chauhan, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, netdev, linux-kernel, Andrew Halaney,
	Willem de Bruijn, Martin KaFai Lau, Martin KaFai Lau,
	Daniel Borkmann, bpf
  Cc: kernel, syzbot+d7b227731ec589e7f4f0, syzbot+30a35a2e9c5067cc43fa

minor: double space before userspace

Abhishek Chauhan wrote:
> Currently there are no strict checks while setting SO_TXTIME
> from userspace. With the recent development in skb->tstamp_type
> clockid with unsupported clocks results in warn_on_once, which causes
> unnecessary aborts in some systems which enables panic on warns.
> 
> Add validation in setsockopt to support only CLOCK_REALTIME,
> CLOCK_MONOTONIC and CLOCK_TAI to be set from userspace.
> 
> Link: https://lore.kernel.org/netdev/bc037db4-58bb-4861-ac31-a361a93841d3@linux.dev/
> Link: https://lore.kernel.org/lkml/20240509211834.3235191-1-quic_abchauha@quicinc.com/

These discussions can be found directly from the referenced commit?
If any, I'd like to the conversation we had that arrived at this
approach.

> Fixes: 1693c5db6ab8 ("net: Add additional bit to support clockid_t timestamp type")
> Reported-by: syzbot+d7b227731ec589e7f4f0@syzkaller.appspotmail.com
> Closes: https://syzkaller.appspot.com/bug?extid=d7b227731ec589e7f4f0
> Reported-by: syzbot+30a35a2e9c5067cc43fa@syzkaller.appspotmail.com
> Closes: https://syzkaller.appspot.com/bug?extid=30a35a2e9c5067cc43fa
> Signed-off-by: Abhishek Chauhan <quic_abchauha@quicinc.com>
> ---
>  net/core/sock.c | 16 ++++++++++++++++
>  1 file changed, 16 insertions(+)
> 
> diff --git a/net/core/sock.c b/net/core/sock.c
> index 8629f9aecf91..f8374be9d8c9 100644
> --- a/net/core/sock.c
> +++ b/net/core/sock.c
> @@ -1083,6 +1083,17 @@ bool sockopt_capable(int cap)
>  }
>  EXPORT_SYMBOL(sockopt_capable);
>  
> +static int sockopt_validate_clockid(int value)

sock_txtime.clockid has type __kernel_clockid_t.

> +{
> +	switch (value) {
> +	case CLOCK_REALTIME:
> +	case CLOCK_MONOTONIC:
> +	case CLOCK_TAI:
> +		return 0;
> +	}
> +	return -EINVAL;
> +}
> +
>  /*
>   *	This is meant for all protocols to use and covers goings on
>   *	at the socket level. Everything here is generic.
> @@ -1497,6 +1508,11 @@ int sk_setsockopt(struct sock *sk, int level, int optname,
>  			ret = -EPERM;
>  			break;
>  		}
> +
> +		ret = sockopt_validate_clockid(sk_txtime.clockid);
> +		if (ret)
> +			break;
> +
>  		sock_valbool_flag(sk, SOCK_TXTIME, true);
>  		sk->sk_clockid = sk_txtime.clockid;
>  		sk->sk_txtime_deadline_mode =
> -- 
> 2.25.1
> 



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

* Re: [PATCH net] net: validate SO_TXTIME clockid coming from userspace
  2024-05-29 13:58 ` Willem de Bruijn
@ 2024-05-29 15:49   ` Abhishek Chauhan (ABC)
  2024-05-29 16:00     ` Willem de Bruijn
  0 siblings, 1 reply; 7+ messages in thread
From: Abhishek Chauhan (ABC) @ 2024-05-29 15:49 UTC (permalink / raw)
  To: Willem de Bruijn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, netdev, linux-kernel, Andrew Halaney,
	Martin KaFai Lau, Martin KaFai Lau, Daniel Borkmann, bpf
  Cc: kernel, syzbot+d7b227731ec589e7f4f0, syzbot+30a35a2e9c5067cc43fa



On 5/29/2024 6:58 AM, Willem de Bruijn wrote:
> minor: double space before userspace
> 
> Abhishek Chauhan wrote:
>> Currently there are no strict checks while setting SO_TXTIME
>> from userspace. With the recent development in skb->tstamp_type
>> clockid with unsupported clocks results in warn_on_once, which causes
>> unnecessary aborts in some systems which enables panic on warns.
>>
>> Add validation in setsockopt to support only CLOCK_REALTIME,
>> CLOCK_MONOTONIC and CLOCK_TAI to be set from userspace.
>>
>> Link: https://lore.kernel.org/netdev/bc037db4-58bb-4861-ac31-a361a93841d3@linux.dev/
>> Link: https://lore.kernel.org/lkml/20240509211834.3235191-1-quic_abchauha@quicinc.com/
> 
> These discussions can be found directly from the referenced commit?
> If any, I'd like to the conversation we had that arrived at this
> approach.
> 
Not Directly but from the patch series. 
1. First link is for why we introduced skb->tstamp_type 
2. Second link points to the series were we discussed on two approach to solve the problem 
one being limit the skclockid to just TAI,MONO and REALTIME. 



>> Fixes: 1693c5db6ab8 ("net: Add additional bit to support clockid_t timestamp type")
>> Reported-by: syzbot+d7b227731ec589e7f4f0@syzkaller.appspotmail.com
>> Closes: https://syzkaller.appspot.com/bug?extid=d7b227731ec589e7f4f0
>> Reported-by: syzbot+30a35a2e9c5067cc43fa@syzkaller.appspotmail.com
>> Closes: https://syzkaller.appspot.com/bug?extid=30a35a2e9c5067cc43fa
>> Signed-off-by: Abhishek Chauhan <quic_abchauha@quicinc.com>
>> ---
>>  net/core/sock.c | 16 ++++++++++++++++
>>  1 file changed, 16 insertions(+)
>>
>> diff --git a/net/core/sock.c b/net/core/sock.c
>> index 8629f9aecf91..f8374be9d8c9 100644
>> --- a/net/core/sock.c
>> +++ b/net/core/sock.c
>> @@ -1083,6 +1083,17 @@ bool sockopt_capable(int cap)
>>  }
>>  EXPORT_SYMBOL(sockopt_capable);
>>  
>> +static int sockopt_validate_clockid(int value)
> 
> sock_txtime.clockid has type __kernel_clockid_t.
> 

 __kernel_clockid_t is typedef of int.  

>> +{
>> +	switch (value) {
>> +	case CLOCK_REALTIME:
>> +	case CLOCK_MONOTONIC:
>> +	case CLOCK_TAI:
>> +		return 0;
>> +	}
>> +	return -EINVAL;
>> +}
>> +
>>  /*
>>   *	This is meant for all protocols to use and covers goings on
>>   *	at the socket level. Everything here is generic.
>> @@ -1497,6 +1508,11 @@ int sk_setsockopt(struct sock *sk, int level, int optname,
>>  			ret = -EPERM;
>>  			break;
>>  		}
>> +
>> +		ret = sockopt_validate_clockid(sk_txtime.clockid);
>> +		if (ret)
>> +			break;
>> +
>>  		sock_valbool_flag(sk, SOCK_TXTIME, true);
>>  		sk->sk_clockid = sk_txtime.clockid;
>>  		sk->sk_txtime_deadline_mode =
>> -- 
>> 2.25.1
>>
> 
> 

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

* Re: [PATCH net] net: validate SO_TXTIME clockid coming from userspace
  2024-05-29 15:49   ` Abhishek Chauhan (ABC)
@ 2024-05-29 16:00     ` Willem de Bruijn
  2024-05-29 16:04       ` Abhishek Chauhan (ABC)
  0 siblings, 1 reply; 7+ messages in thread
From: Willem de Bruijn @ 2024-05-29 16:00 UTC (permalink / raw)
  To: Abhishek Chauhan (ABC), Willem de Bruijn, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, netdev, linux-kernel,
	Andrew Halaney, Martin KaFai Lau, Martin KaFai Lau,
	Daniel Borkmann, bpf
  Cc: kernel, syzbot+d7b227731ec589e7f4f0, syzbot+30a35a2e9c5067cc43fa

Abhishek Chauhan (ABC) wrote:
> 
> 
> On 5/29/2024 6:58 AM, Willem de Bruijn wrote:
> > minor: double space before userspace
> > 
> > Abhishek Chauhan wrote:
> >> Currently there are no strict checks while setting SO_TXTIME
> >> from userspace. With the recent development in skb->tstamp_type
> >> clockid with unsupported clocks results in warn_on_once, which causes
> >> unnecessary aborts in some systems which enables panic on warns.
> >>
> >> Add validation in setsockopt to support only CLOCK_REALTIME,
> >> CLOCK_MONOTONIC and CLOCK_TAI to be set from userspace.
> >>
> >> Link: https://lore.kernel.org/netdev/bc037db4-58bb-4861-ac31-a361a93841d3@linux.dev/
> >> Link: https://lore.kernel.org/lkml/20240509211834.3235191-1-quic_abchauha@quicinc.com/
> > 
> > These discussions can be found directly from the referenced commit?
> > If any, I'd like to the conversation we had that arrived at this
> > approach.
> > 
> Not Directly but from the patch series. 
> 1. First link is for why we introduced skb->tstamp_type 
> 2. Second link points to the series were we discussed on two approach to solve the problem 
> one being limit the skclockid to just TAI,MONO and REALTIME. 

Ah, I missed that.
Perhaps point directly to the start of that follow-up conversation?

https://lore.kernel.org/lkml/6bdba7b6-fd22-4ea5-a356-12268674def1@quicinc.com/

> 
> 
> >> Fixes: 1693c5db6ab8 ("net: Add additional bit to support clockid_t timestamp type")
> >> Reported-by: syzbot+d7b227731ec589e7f4f0@syzkaller.appspotmail.com
> >> Closes: https://syzkaller.appspot.com/bug?extid=d7b227731ec589e7f4f0
> >> Reported-by: syzbot+30a35a2e9c5067cc43fa@syzkaller.appspotmail.com
> >> Closes: https://syzkaller.appspot.com/bug?extid=30a35a2e9c5067cc43fa
> >> Signed-off-by: Abhishek Chauhan <quic_abchauha@quicinc.com>
> >> ---
> >>  net/core/sock.c | 16 ++++++++++++++++
> >>  1 file changed, 16 insertions(+)
> >>
> >> diff --git a/net/core/sock.c b/net/core/sock.c
> >> index 8629f9aecf91..f8374be9d8c9 100644
> >> --- a/net/core/sock.c
> >> +++ b/net/core/sock.c
> >> @@ -1083,6 +1083,17 @@ bool sockopt_capable(int cap)
> >>  }
> >>  EXPORT_SYMBOL(sockopt_capable);
> >>  
> >> +static int sockopt_validate_clockid(int value)
> > 
> > sock_txtime.clockid has type __kernel_clockid_t.
> > 
> 
>  __kernel_clockid_t is typedef of int.  

It is now, but the stricter type definition exists for a reason.
Try to keep the strict types where possible. Besides aiding
syntactic checks, it also helps self document code.

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

* Re: [PATCH net] net: validate SO_TXTIME clockid coming from userspace
  2024-05-29 16:00     ` Willem de Bruijn
@ 2024-05-29 16:04       ` Abhishek Chauhan (ABC)
  0 siblings, 0 replies; 7+ messages in thread
From: Abhishek Chauhan (ABC) @ 2024-05-29 16:04 UTC (permalink / raw)
  To: Willem de Bruijn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, netdev, linux-kernel, Andrew Halaney,
	Martin KaFai Lau, Martin KaFai Lau, Daniel Borkmann, bpf
  Cc: kernel, syzbot+d7b227731ec589e7f4f0, syzbot+30a35a2e9c5067cc43fa



On 5/29/2024 9:00 AM, Willem de Bruijn wrote:
> Abhishek Chauhan (ABC) wrote:
>>
>>
>> On 5/29/2024 6:58 AM, Willem de Bruijn wrote:
>>> minor: double space before userspace
>>>
>>> Abhishek Chauhan wrote:
>>>> Currently there are no strict checks while setting SO_TXTIME
>>>> from userspace. With the recent development in skb->tstamp_type
>>>> clockid with unsupported clocks results in warn_on_once, which causes
>>>> unnecessary aborts in some systems which enables panic on warns.
>>>>
>>>> Add validation in setsockopt to support only CLOCK_REALTIME,
>>>> CLOCK_MONOTONIC and CLOCK_TAI to be set from userspace.
>>>>
>>>> Link: https://lore.kernel.org/netdev/bc037db4-58bb-4861-ac31-a361a93841d3@linux.dev/
>>>> Link: https://lore.kernel.org/lkml/20240509211834.3235191-1-quic_abchauha@quicinc.com/
>>>
>>> These discussions can be found directly from the referenced commit?
>>> If any, I'd like to the conversation we had that arrived at this
>>> approach.
>>>
>> Not Directly but from the patch series. 
>> 1. First link is for why we introduced skb->tstamp_type 
>> 2. Second link points to the series were we discussed on two approach to solve the problem 
>> one being limit the skclockid to just TAI,MONO and REALTIME. 
> 
> Ah, I missed that.
> Perhaps point directly to the start of that follow-up conversation?
> Thanks Willem, Let me do that when i raise the net-next patch. 
> https://lore.kernel.org/lkml/6bdba7b6-fd22-4ea5-a356-12268674def1@quicinc.com/
> 
>>
>>
>>>> Fixes: 1693c5db6ab8 ("net: Add additional bit to support clockid_t timestamp type")
>>>> Reported-by: syzbot+d7b227731ec589e7f4f0@syzkaller.appspotmail.com
>>>> Closes: https://syzkaller.appspot.com/bug?extid=d7b227731ec589e7f4f0
>>>> Reported-by: syzbot+30a35a2e9c5067cc43fa@syzkaller.appspotmail.com
>>>> Closes: https://syzkaller.appspot.com/bug?extid=30a35a2e9c5067cc43fa
>>>> Signed-off-by: Abhishek Chauhan <quic_abchauha@quicinc.com>
>>>> ---
>>>>  net/core/sock.c | 16 ++++++++++++++++
>>>>  1 file changed, 16 insertions(+)
>>>>
>>>> diff --git a/net/core/sock.c b/net/core/sock.c
>>>> index 8629f9aecf91..f8374be9d8c9 100644
>>>> --- a/net/core/sock.c
>>>> +++ b/net/core/sock.c
>>>> @@ -1083,6 +1083,17 @@ bool sockopt_capable(int cap)
>>>>  }
>>>>  EXPORT_SYMBOL(sockopt_capable);
>>>>  
>>>> +static int sockopt_validate_clockid(int value)
>>>
>>> sock_txtime.clockid has type __kernel_clockid_t.
>>>
>>
>>  __kernel_clockid_t is typedef of int.  
>> It is now, but the stricter type definition exists for a reason.
> Try to keep the strict types where possible. Besides aiding
> syntactic checks, it also helps self document code.
Okay i see what you are saying. Makes sense. I will change it to __kernel_clockid_t

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

end of thread, other threads:[~2024-05-29 16:05 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-05-28 22:49 [PATCH net] net: validate SO_TXTIME clockid coming from userspace Abhishek Chauhan
2024-05-29  1:15 ` Martin KaFai Lau
2024-05-29  3:32   ` Abhishek Chauhan (ABC)
2024-05-29 13:58 ` Willem de Bruijn
2024-05-29 15:49   ` Abhishek Chauhan (ABC)
2024-05-29 16:00     ` Willem de Bruijn
2024-05-29 16:04       ` Abhishek Chauhan (ABC)

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