Skip to content

Commit 4ab42d7

Browse files
bwhacksdavem330
authored andcommitted
ppp, slip: Validate VJ compression slot parameters completely
Currently slhc_init() treats out-of-range values of rslots and tslots as equivalent to 0, except that if tslots is too large it will dereference a null pointer (CVE-2015-7799). Add a range-check at the top of the function and make it return an ERR_PTR() on error instead of NULL. Change the callers accordingly. Compile-tested only. Reported-by: 郭永刚 <[email protected]> References: http://article.gmane.org/gmane.comp.security.oss.general/17908 Signed-off-by: Ben Hutchings <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 0baa57d commit 4ab42d7

File tree

4 files changed

+15
-15
lines changed

4 files changed

+15
-15
lines changed

drivers/isdn/i4l/isdn_ppp.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -322,9 +322,9 @@ isdn_ppp_open(int min, struct file *file)
322322
* VJ header compression init
323323
*/
324324
is->slcomp = slhc_init(16, 16); /* not necessary for 2. link in bundle */
325-
if (!is->slcomp) {
325+
if (IS_ERR(is->slcomp)) {
326326
isdn_ppp_ccp_reset_free(is);
327-
return -ENOMEM;
327+
return PTR_ERR(is->slcomp);
328328
}
329329
#endif
330330
#ifdef CONFIG_IPPP_FILTER
@@ -573,10 +573,8 @@ isdn_ppp_ioctl(int min, struct file *file, unsigned int cmd, unsigned long arg)
573573
is->maxcid = val;
574574
#ifdef CONFIG_ISDN_PPP_VJ
575575
sltmp = slhc_init(16, val);
576-
if (!sltmp) {
577-
printk(KERN_ERR "ippp, can't realloc slhc struct\n");
578-
return -ENOMEM;
579-
}
576+
if (IS_ERR(sltmp))
577+
return PTR_ERR(sltmp);
580578
if (is->slcomp)
581579
slhc_free(is->slcomp);
582580
is->slcomp = sltmp;

drivers/net/ppp/ppp_generic.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -721,10 +721,8 @@ static long ppp_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
721721
val &= 0xffff;
722722
}
723723
vj = slhc_init(val2+1, val+1);
724-
if (!vj) {
725-
netdev_err(ppp->dev,
726-
"PPP: no memory (VJ compressor)\n");
727-
err = -ENOMEM;
724+
if (IS_ERR(vj)) {
725+
err = PTR_ERR(vj);
728726
break;
729727
}
730728
ppp_lock(ppp);

drivers/net/slip/slhc.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,9 @@ static long decode(unsigned char **cpp);
8484
static unsigned char * put16(unsigned char *cp, unsigned short x);
8585
static unsigned short pull16(unsigned char **cpp);
8686

87-
/* Initialize compression data structure
87+
/* Allocate compression data structure
8888
* slots must be in range 0 to 255 (zero meaning no compression)
89+
* Returns pointer to structure or ERR_PTR() on error.
8990
*/
9091
struct slcompress *
9192
slhc_init(int rslots, int tslots)
@@ -94,19 +95,22 @@ slhc_init(int rslots, int tslots)
9495
register struct cstate *ts;
9596
struct slcompress *comp;
9697

98+
if (rslots < 0 || rslots > 255 || tslots < 0 || tslots > 255)
99+
return ERR_PTR(-EINVAL);
100+
97101
comp = kzalloc(sizeof(struct slcompress), GFP_KERNEL);
98102
if (! comp)
99103
goto out_fail;
100104

101-
if ( rslots > 0 && rslots < 256 ) {
105+
if (rslots > 0) {
102106
size_t rsize = rslots * sizeof(struct cstate);
103107
comp->rstate = kzalloc(rsize, GFP_KERNEL);
104108
if (! comp->rstate)
105109
goto out_free;
106110
comp->rslot_limit = rslots - 1;
107111
}
108112

109-
if ( tslots > 0 && tslots < 256 ) {
113+
if (tslots > 0) {
110114
size_t tsize = tslots * sizeof(struct cstate);
111115
comp->tstate = kzalloc(tsize, GFP_KERNEL);
112116
if (! comp->tstate)
@@ -141,7 +145,7 @@ slhc_init(int rslots, int tslots)
141145
out_free:
142146
kfree(comp);
143147
out_fail:
144-
return NULL;
148+
return ERR_PTR(-ENOMEM);
145149
}
146150

147151

drivers/net/slip/slip.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ static int sl_alloc_bufs(struct slip *sl, int mtu)
164164
if (cbuff == NULL)
165165
goto err_exit;
166166
slcomp = slhc_init(16, 16);
167-
if (slcomp == NULL)
167+
if (IS_ERR(slcomp))
168168
goto err_exit;
169169
#endif
170170
spin_lock_bh(&sl->lock);

0 commit comments

Comments
 (0)