Skip to content

Commit 5ef4130

Browse files
Dan Rosenbergdavem330
authored andcommitted
x25: Prevent crashing when parsing bad X.25 facilities
Now with improved comma support. On parsing malformed X.25 facilities, decrementing the remaining length may cause it to underflow. Since the length is an unsigned integer, this will result in the loop continuing until the kernel crashes. This patch adds checks to ensure decrementing the remaining length does not cause it to wrap around. Signed-off-by: Dan Rosenberg <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent e68e613 commit 5ef4130

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

net/x25/x25_facilities.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ int x25_parse_facilities(struct sk_buff *skb, struct x25_facilities *facilities,
6161
while (len > 0) {
6262
switch (*p & X25_FAC_CLASS_MASK) {
6363
case X25_FAC_CLASS_A:
64+
if (len < 2)
65+
return 0;
6466
switch (*p) {
6567
case X25_FAC_REVERSE:
6668
if((p[1] & 0x81) == 0x81) {
@@ -104,6 +106,8 @@ int x25_parse_facilities(struct sk_buff *skb, struct x25_facilities *facilities,
104106
len -= 2;
105107
break;
106108
case X25_FAC_CLASS_B:
109+
if (len < 3)
110+
return 0;
107111
switch (*p) {
108112
case X25_FAC_PACKET_SIZE:
109113
facilities->pacsize_in = p[1];
@@ -125,13 +129,17 @@ int x25_parse_facilities(struct sk_buff *skb, struct x25_facilities *facilities,
125129
len -= 3;
126130
break;
127131
case X25_FAC_CLASS_C:
132+
if (len < 4)
133+
return 0;
128134
printk(KERN_DEBUG "X.25: unknown facility %02X, "
129135
"values %02X, %02X, %02X\n",
130136
p[0], p[1], p[2], p[3]);
131137
p += 4;
132138
len -= 4;
133139
break;
134140
case X25_FAC_CLASS_D:
141+
if (len < p[1] + 2)
142+
return 0;
135143
switch (*p) {
136144
case X25_FAC_CALLING_AE:
137145
if (p[1] > X25_MAX_DTE_FACIL_LEN || p[1] <= 1)
@@ -149,9 +157,7 @@ int x25_parse_facilities(struct sk_buff *skb, struct x25_facilities *facilities,
149157
break;
150158
default:
151159
printk(KERN_DEBUG "X.25: unknown facility %02X,"
152-
"length %d, values %02X, %02X, "
153-
"%02X, %02X\n",
154-
p[0], p[1], p[2], p[3], p[4], p[5]);
160+
"length %d\n", p[0], p[1]);
155161
break;
156162
}
157163
len -= p[1] + 2;

0 commit comments

Comments
 (0)