forked from mirrors/linux
		
	usb: typec: fix potential array underflow in ucsi_ccg_sync_control()
The "command" variable can be controlled by the user via debugfs.  The
worry is that if con_index is zero then "&uc->ucsi->connector[con_index
- 1]" would be an array underflow.
Fixes: 170a6726d0 ("usb: typec: ucsi: add support for separate DP altmode devices")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Link: https://lore.kernel.org/r/c69ef0b3-61b0-4dde-98dd-97b97f81d912@stanley.mountain
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
			
			
This commit is contained in:
		
							parent
							
								
									2481af7967
								
							
						
					
					
						commit
						e56aac6e5a
					
				
					 1 changed files with 5 additions and 0 deletions
				
			
		| 
						 | 
					@ -642,6 +642,10 @@ static int ucsi_ccg_sync_control(struct ucsi *ucsi, u64 command)
 | 
				
			||||||
	    uc->has_multiple_dp) {
 | 
						    uc->has_multiple_dp) {
 | 
				
			||||||
		con_index = (uc->last_cmd_sent >> 16) &
 | 
							con_index = (uc->last_cmd_sent >> 16) &
 | 
				
			||||||
			UCSI_CMD_CONNECTOR_MASK;
 | 
								UCSI_CMD_CONNECTOR_MASK;
 | 
				
			||||||
 | 
							if (con_index == 0) {
 | 
				
			||||||
 | 
								ret = -EINVAL;
 | 
				
			||||||
 | 
								goto unlock;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
		con = &uc->ucsi->connector[con_index - 1];
 | 
							con = &uc->ucsi->connector[con_index - 1];
 | 
				
			||||||
		ucsi_ccg_update_set_new_cam_cmd(uc, con, &command);
 | 
							ucsi_ccg_update_set_new_cam_cmd(uc, con, &command);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					@ -649,6 +653,7 @@ static int ucsi_ccg_sync_control(struct ucsi *ucsi, u64 command)
 | 
				
			||||||
	ret = ucsi_sync_control_common(ucsi, command);
 | 
						ret = ucsi_sync_control_common(ucsi, command);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	pm_runtime_put_sync(uc->dev);
 | 
						pm_runtime_put_sync(uc->dev);
 | 
				
			||||||
 | 
					unlock:
 | 
				
			||||||
	mutex_unlock(&uc->lock);
 | 
						mutex_unlock(&uc->lock);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return ret;
 | 
						return ret;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue