Netdev List
 help / color / mirror / Atom feed
* [PATCH net] sctp: potential read out of bounds in sctp_ulpevent_type_enabled()
@ 2017-09-13  9:20 Dan Carpenter
  2017-09-13 14:28 ` Neil Horman
  2017-09-13 16:25 ` David Miller
  0 siblings, 2 replies; 5+ messages in thread
From: Dan Carpenter @ 2017-09-13  9:20 UTC (permalink / raw)
  To: Vlad Yasevich
  Cc: Neil Horman, David S. Miller, linux-sctp, netdev, kernel-janitors

This code causes a static checker warning because Smatch doesn't trust
anything that comes from skb->data.  I've reviewed this code and I do
think skb->data can be controlled by the user here.

The sctp_event_subscribe struct has 13 __u8 fields and we want to see
if ours is non-zero.  sn_type can be any value in the 0-USHRT_MAX range.
We're subtracting SCTP_SN_TYPE_BASE which is 1 << 15 so we could read
either before the start of the struct or after the end.

This is a very old bug and it's surprising that it would go undetected
for so long but my theory is that it just doesn't have a big impact so
it would be hard to notice.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
I'm not terribly familiar with sctp and this is a static checker fix.
Please review it carefully.

diff --git a/include/net/sctp/ulpevent.h b/include/net/sctp/ulpevent.h
index 1060494ac230..e6873176bea7 100644
--- a/include/net/sctp/ulpevent.h
+++ b/include/net/sctp/ulpevent.h
@@ -154,7 +154,11 @@ static inline int sctp_ulpevent_type_enabled(__u16 sn_type,
 					     struct sctp_event_subscribe *mask)
 {
 	char *amask = (char *) mask;
-	return amask[sn_type - SCTP_SN_TYPE_BASE];
+	int offset = sn_type - SCTP_SN_TYPE_BASE;
+
+	if (offset >= sizeof(struct sctp_event_subscribe))
+		return 0;
+	return amask[offset];
 }
 
 /* Given an event subscription, is this event enabled? */

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

* Re: [PATCH net] sctp: potential read out of bounds in sctp_ulpevent_type_enabled()
  2017-09-13  9:20 [PATCH net] sctp: potential read out of bounds in sctp_ulpevent_type_enabled() Dan Carpenter
@ 2017-09-13 14:28 ` Neil Horman
  2017-09-13 16:25 ` David Miller
  1 sibling, 0 replies; 5+ messages in thread
From: Neil Horman @ 2017-09-13 14:28 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Vlad Yasevich, David S. Miller, linux-sctp, netdev,
	kernel-janitors

On Wed, Sep 13, 2017 at 12:20:28PM +0300, Dan Carpenter wrote:
> This code causes a static checker warning because Smatch doesn't trust
> anything that comes from skb->data.  I've reviewed this code and I do
> think skb->data can be controlled by the user here.
> 
> The sctp_event_subscribe struct has 13 __u8 fields and we want to see
> if ours is non-zero.  sn_type can be any value in the 0-USHRT_MAX range.
> We're subtracting SCTP_SN_TYPE_BASE which is 1 << 15 so we could read
> either before the start of the struct or after the end.
> 
> This is a very old bug and it's surprising that it would go undetected
> for so long but my theory is that it just doesn't have a big impact so
> it would be hard to notice.
> 
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> ---
> I'm not terribly familiar with sctp and this is a static checker fix.
> Please review it carefully.
> 
> diff --git a/include/net/sctp/ulpevent.h b/include/net/sctp/ulpevent.h
> index 1060494ac230..e6873176bea7 100644
> --- a/include/net/sctp/ulpevent.h
> +++ b/include/net/sctp/ulpevent.h
> @@ -154,7 +154,11 @@ static inline int sctp_ulpevent_type_enabled(__u16 sn_type,
>  					     struct sctp_event_subscribe *mask)
>  {
>  	char *amask = (char *) mask;
> -	return amask[sn_type - SCTP_SN_TYPE_BASE];
> +	int offset = sn_type - SCTP_SN_TYPE_BASE;
> +
> +	if (offset >= sizeof(struct sctp_event_subscribe))
> +		return 0;
> +	return amask[offset];
>  }
Acked-by: Neil Horman <nhorman@tuxdriver.com>

>  
>  /* Given an event subscription, is this event enabled? */
> --
> To unsubscribe from this list: send the line "unsubscribe linux-sctp" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 

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

* Re: [PATCH net] sctp: potential read out of bounds in sctp_ulpevent_type_enabled()
  2017-09-13  9:20 [PATCH net] sctp: potential read out of bounds in sctp_ulpevent_type_enabled() Dan Carpenter
  2017-09-13 14:28 ` Neil Horman
@ 2017-09-13 16:25 ` David Miller
  2017-09-13 23:00   ` [PATCH v2 " Dan Carpenter
  1 sibling, 1 reply; 5+ messages in thread
From: David Miller @ 2017-09-13 16:25 UTC (permalink / raw)
  To: dan.carpenter; +Cc: vyasevich, nhorman, linux-sctp, netdev, kernel-janitors

From: Dan Carpenter <dan.carpenter@oracle.com>
Date: Wed, 13 Sep 2017 12:20:28 +0300

> @@ -154,7 +154,11 @@ static inline int sctp_ulpevent_type_enabled(__u16 sn_type,
>  					     struct sctp_event_subscribe *mask)
>  {
>  	char *amask = (char *) mask;
> -	return amask[sn_type - SCTP_SN_TYPE_BASE];
> +	int offset = sn_type - SCTP_SN_TYPE_BASE;

Please use reverse-christmas-tree local variable ordering.

Thank you.

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

* [PATCH v2 net] sctp: potential read out of bounds in sctp_ulpevent_type_enabled()
  2017-09-13 16:25 ` David Miller
@ 2017-09-13 23:00   ` Dan Carpenter
  2017-09-14  0:00     ` David Miller
  0 siblings, 1 reply; 5+ messages in thread
From: Dan Carpenter @ 2017-09-13 23:00 UTC (permalink / raw)
  To: Vlad Yasevich
  Cc: Neil Horman, David S. Miller, linux-sctp, netdev, kernel-janitors

This code causes a static checker warning because Smatch doesn't trust
anything that comes from skb->data.  I've reviewed this code and I do
think skb->data can be controlled by the user here.

The sctp_event_subscribe struct has 13 __u8 fields and we want to see
if ours is non-zero.  sn_type can be any value in the 0-USHRT_MAX range.
We're subtracting SCTP_SN_TYPE_BASE which is 1 << 15 so we could read
either before the start of the struct or after the end.

This is a very old bug and it's surprising that it would go undetected
for so long but my theory is that it just doesn't have a big impact so
it would be hard to notice.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
v2:  Use reverse-christmas-tree local variable ordering.

diff --git a/include/net/sctp/ulpevent.h b/include/net/sctp/ulpevent.h
index 1060494ac230..b8c86ec1a8f5 100644
--- a/include/net/sctp/ulpevent.h
+++ b/include/net/sctp/ulpevent.h
@@ -153,8 +153,12 @@ __u16 sctp_ulpevent_get_notification_type(const struct sctp_ulpevent *event);
 static inline int sctp_ulpevent_type_enabled(__u16 sn_type,
 					     struct sctp_event_subscribe *mask)
 {
+	int offset = sn_type - SCTP_SN_TYPE_BASE;
 	char *amask = (char *) mask;
-	return amask[sn_type - SCTP_SN_TYPE_BASE];
+
+	if (offset >= sizeof(struct sctp_event_subscribe))
+		return 0;
+	return amask[offset];
 }
 
 /* Given an event subscription, is this event enabled? */

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

* Re: [PATCH v2 net] sctp: potential read out of bounds in sctp_ulpevent_type_enabled()
  2017-09-13 23:00   ` [PATCH v2 " Dan Carpenter
@ 2017-09-14  0:00     ` David Miller
  0 siblings, 0 replies; 5+ messages in thread
From: David Miller @ 2017-09-14  0:00 UTC (permalink / raw)
  To: dan.carpenter; +Cc: vyasevich, nhorman, linux-sctp, netdev, kernel-janitors

From: Dan Carpenter <dan.carpenter@oracle.com>
Date: Thu, 14 Sep 2017 02:00:54 +0300

> This code causes a static checker warning because Smatch doesn't trust
> anything that comes from skb->data.  I've reviewed this code and I do
> think skb->data can be controlled by the user here.
> 
> The sctp_event_subscribe struct has 13 __u8 fields and we want to see
> if ours is non-zero.  sn_type can be any value in the 0-USHRT_MAX range.
> We're subtracting SCTP_SN_TYPE_BASE which is 1 << 15 so we could read
> either before the start of the struct or after the end.
> 
> This is a very old bug and it's surprising that it would go undetected
> for so long but my theory is that it just doesn't have a big impact so
> it would be hard to notice.
> 
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> ---
> v2:  Use reverse-christmas-tree local variable ordering.

Applied and queued up for -stable, thanks.

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

end of thread, other threads:[~2017-09-14  0:00 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-09-13  9:20 [PATCH net] sctp: potential read out of bounds in sctp_ulpevent_type_enabled() Dan Carpenter
2017-09-13 14:28 ` Neil Horman
2017-09-13 16:25 ` David Miller
2017-09-13 23:00   ` [PATCH v2 " Dan Carpenter
2017-09-14  0:00     ` David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox