mirror of
				https://github.com/torvalds/linux.git
				synced 2025-11-04 02:30:34 +02:00 
			
		
		
		
	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: 郭永刚 <guoyonggang@360.cn> References: http://article.gmane.org/gmane.comp.security.oss.general/17908 Signed-off-by: Ben Hutchings <ben@decadent.org.uk> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
		
							parent
							
								
									0baa57d8dc
								
							
						
					
					
						commit
						4ab42d78e3
					
				
					 4 changed files with 15 additions and 15 deletions
				
			
		| 
						 | 
					@ -322,9 +322,9 @@ isdn_ppp_open(int min, struct file *file)
 | 
				
			||||||
	 * VJ header compression init
 | 
						 * VJ header compression init
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	is->slcomp = slhc_init(16, 16);	/* not necessary for 2. link in bundle */
 | 
						is->slcomp = slhc_init(16, 16);	/* not necessary for 2. link in bundle */
 | 
				
			||||||
	if (!is->slcomp) {
 | 
						if (IS_ERR(is->slcomp)) {
 | 
				
			||||||
		isdn_ppp_ccp_reset_free(is);
 | 
							isdn_ppp_ccp_reset_free(is);
 | 
				
			||||||
		return -ENOMEM;
 | 
							return PTR_ERR(is->slcomp);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
#ifdef CONFIG_IPPP_FILTER
 | 
					#ifdef CONFIG_IPPP_FILTER
 | 
				
			||||||
| 
						 | 
					@ -573,10 +573,8 @@ isdn_ppp_ioctl(int min, struct file *file, unsigned int cmd, unsigned long arg)
 | 
				
			||||||
			is->maxcid = val;
 | 
								is->maxcid = val;
 | 
				
			||||||
#ifdef CONFIG_ISDN_PPP_VJ
 | 
					#ifdef CONFIG_ISDN_PPP_VJ
 | 
				
			||||||
			sltmp = slhc_init(16, val);
 | 
								sltmp = slhc_init(16, val);
 | 
				
			||||||
			if (!sltmp) {
 | 
								if (IS_ERR(sltmp))
 | 
				
			||||||
				printk(KERN_ERR "ippp, can't realloc slhc struct\n");
 | 
									return PTR_ERR(sltmp);
 | 
				
			||||||
				return -ENOMEM;
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
			if (is->slcomp)
 | 
								if (is->slcomp)
 | 
				
			||||||
				slhc_free(is->slcomp);
 | 
									slhc_free(is->slcomp);
 | 
				
			||||||
			is->slcomp = sltmp;
 | 
								is->slcomp = sltmp;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -721,10 +721,8 @@ static long ppp_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
 | 
				
			||||||
			val &= 0xffff;
 | 
								val &= 0xffff;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		vj = slhc_init(val2+1, val+1);
 | 
							vj = slhc_init(val2+1, val+1);
 | 
				
			||||||
		if (!vj) {
 | 
							if (IS_ERR(vj)) {
 | 
				
			||||||
			netdev_err(ppp->dev,
 | 
								err = PTR_ERR(vj);
 | 
				
			||||||
				   "PPP: no memory (VJ compressor)\n");
 | 
					 | 
				
			||||||
			err = -ENOMEM;
 | 
					 | 
				
			||||||
			break;
 | 
								break;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		ppp_lock(ppp);
 | 
							ppp_lock(ppp);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -84,8 +84,9 @@ static long decode(unsigned char **cpp);
 | 
				
			||||||
static unsigned char * put16(unsigned char *cp, unsigned short x);
 | 
					static unsigned char * put16(unsigned char *cp, unsigned short x);
 | 
				
			||||||
static unsigned short pull16(unsigned char **cpp);
 | 
					static unsigned short pull16(unsigned char **cpp);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* Initialize compression data structure
 | 
					/* Allocate compression data structure
 | 
				
			||||||
 *	slots must be in range 0 to 255 (zero meaning no compression)
 | 
					 *	slots must be in range 0 to 255 (zero meaning no compression)
 | 
				
			||||||
 | 
					 * Returns pointer to structure or ERR_PTR() on error.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
struct slcompress *
 | 
					struct slcompress *
 | 
				
			||||||
slhc_init(int rslots, int tslots)
 | 
					slhc_init(int rslots, int tslots)
 | 
				
			||||||
| 
						 | 
					@ -94,11 +95,14 @@ slhc_init(int rslots, int tslots)
 | 
				
			||||||
	register struct cstate *ts;
 | 
						register struct cstate *ts;
 | 
				
			||||||
	struct slcompress *comp;
 | 
						struct slcompress *comp;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (rslots < 0 || rslots > 255 || tslots < 0 || tslots > 255)
 | 
				
			||||||
 | 
							return ERR_PTR(-EINVAL);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	comp = kzalloc(sizeof(struct slcompress), GFP_KERNEL);
 | 
						comp = kzalloc(sizeof(struct slcompress), GFP_KERNEL);
 | 
				
			||||||
	if (! comp)
 | 
						if (! comp)
 | 
				
			||||||
		goto out_fail;
 | 
							goto out_fail;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if ( rslots > 0  &&  rslots < 256 ) {
 | 
						if (rslots > 0) {
 | 
				
			||||||
		size_t rsize = rslots * sizeof(struct cstate);
 | 
							size_t rsize = rslots * sizeof(struct cstate);
 | 
				
			||||||
		comp->rstate = kzalloc(rsize, GFP_KERNEL);
 | 
							comp->rstate = kzalloc(rsize, GFP_KERNEL);
 | 
				
			||||||
		if (! comp->rstate)
 | 
							if (! comp->rstate)
 | 
				
			||||||
| 
						 | 
					@ -106,7 +110,7 @@ slhc_init(int rslots, int tslots)
 | 
				
			||||||
		comp->rslot_limit = rslots - 1;
 | 
							comp->rslot_limit = rslots - 1;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if ( tslots > 0  &&  tslots < 256 ) {
 | 
						if (tslots > 0) {
 | 
				
			||||||
		size_t tsize = tslots * sizeof(struct cstate);
 | 
							size_t tsize = tslots * sizeof(struct cstate);
 | 
				
			||||||
		comp->tstate = kzalloc(tsize, GFP_KERNEL);
 | 
							comp->tstate = kzalloc(tsize, GFP_KERNEL);
 | 
				
			||||||
		if (! comp->tstate)
 | 
							if (! comp->tstate)
 | 
				
			||||||
| 
						 | 
					@ -141,7 +145,7 @@ slhc_init(int rslots, int tslots)
 | 
				
			||||||
out_free:
 | 
					out_free:
 | 
				
			||||||
	kfree(comp);
 | 
						kfree(comp);
 | 
				
			||||||
out_fail:
 | 
					out_fail:
 | 
				
			||||||
	return NULL;
 | 
						return ERR_PTR(-ENOMEM);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -164,7 +164,7 @@ static int sl_alloc_bufs(struct slip *sl, int mtu)
 | 
				
			||||||
	if (cbuff == NULL)
 | 
						if (cbuff == NULL)
 | 
				
			||||||
		goto err_exit;
 | 
							goto err_exit;
 | 
				
			||||||
	slcomp = slhc_init(16, 16);
 | 
						slcomp = slhc_init(16, 16);
 | 
				
			||||||
	if (slcomp == NULL)
 | 
						if (IS_ERR(slcomp))
 | 
				
			||||||
		goto err_exit;
 | 
							goto err_exit;
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
	spin_lock_bh(&sl->lock);
 | 
						spin_lock_bh(&sl->lock);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue