Patch to fix kernel bug 15678 - x25 code accesses fields beyond the end of packet.
Subsystems (3)
The current X.25 code attempts to decode fields in X.25 packets that are not present. Here is a little patch that checks the received packet length before attempting to decode the missing fields. It also improves error checking for malformed packets.
From: John Hughes <[email protected]>
Subject: Patch to fix bug 15678 - x25 accesses fields beyond end of packet.
Here is a patch to stop X.25 examining fields beyond the end of the packet.
For example, when a simple CALL ACCEPTED was received:
10 10 0f
x25_parse_facilities was attempting to decode the FACILITIES field, but this packet contains no facilities field.
include/net/x25.h +4 -0
@@ -182,6 +182,10 @@ extern int sysctl_x25_clear_request_timeout;extern int sysctl_x25_ack_holdback_timeout;extern int sysctl_x25_forward; +extern int x25_parse_address_block (struct sk_buff *skb, +struct x25_address *called_addr, +struct x25_address *calling_addr); +extern int x25_addr_ntoa (unsigned char *,struct x25_address *,struct x25_address *); extern int x25_addr_aton(unsigned char *, struct x25_address *,
net/x25/af_x25.c +46 -1
68 lines not on this page · raw message
net/x25/x25_facilities.c +11 -1
@@ -35,7 +35,7 @@ int x25_parse_facilities(struct sk_buff *skb, struct x25_facilities *facilities, struct x25_dte_facilities *dte_facs, unsigned long *vc_fac_mask) { unsigned char *p = skb->data; -unsigned int len = *p++; +unsigned int len; *vc_fac_mask =0 ;
@@ -50,6 +50,14 @@ int x25_parse_facilities(struct sk_buff *skb, struct x25_facilities *facilities,memset (dte_facs->called_ae,'\0' ,sizeof (dte_facs->called_ae));memset (dte_facs->calling_ae,'\0' ,sizeof (dte_facs->calling_ae)); +if (skb->len <1 ) +return 0 ; + + len = *p++; + +if (len >= skb->len) +return -1 ; +while (len >0 ) {switch (*p &X25_FAC_CLASS_MASK ) {case X25_FAC_CLASS_A :
@@ -247,6 +255,8 @@ int x25_negotiate_facilities(struct sk_buff *skb, struct sock *sk,memcpy (new, ours,sizeof (*new)); len =x25_parse_facilities (skb, &theirs, dte, &x25->vc_facil_mask); +if (len <0 ) +return len;/* * They want reverse charging, we won't accept it.
net/x25/x25_in.c +11 -4
@@ -89,6 +89,7 @@ static int x25_queue_rx_frame(struct sock *sk, struct sk_buff *skb, int more)static int x25_state1_machine (struct sock *sk,struct sk_buff *skb,int frametype) {struct x25_address source_addr, dest_addr; +int len;switch (frametype) {case X25_CALL_ACCEPTED : {
@@ -106,11 +107,17 @@ static int x25_state1_machine(struct sock *sk, struct sk_buff *skb, int frametyp* Parse the data in the frame. */ skb_pull (skb,X25_STD_MIN_LEN ); -skb_pull (skb,x25_addr_ntoa (skb->data, &source_addr, &dest_addr)); -skb_pull (skb, -x25_parse_facilities (skb, &x25->facilities, + + len =x25_parse_address_block (skb, &source_addr, + &dest_addr); +if (len >0 ) +skb_pull (skb, len); + + len =x25_parse_facilities (skb, &x25->facilities, &x25->dte_facilities, - &x25->vc_facil_mask)); + &x25->vc_facil_mask); +if (len >0 ) +skb_pull (skb, len);/* * Copy any Call User Data. */
From: John Hughes <[email protected]>
Date: Sun, 04 Apr 2010 18:40:17 +0200
Quoted 5 lines
From: John Hughes <[email protected]>
Subject: Patch to fix bug 15678 - x25 accesses fields beyond end of packet.Here is a patch to stop X.25 examining fields beyond the end of the packet.
Quoted 8 lines
For example, when a simple CALL ACCEPTED was received:
10 10 0f
x25_parse_facilitieswas attempting to decode the FACILITIES field, but this packet contains no facilities field.Signed-off-by John Hughes <[email protected]>
Applied, thanks John.