Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965847AbdDTGii (ORCPT ); Thu, 20 Apr 2017 02:38:38 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:46140 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S941883AbdDTGi2 (ORCPT ); Thu, 20 Apr 2017 02:38:28 -0400 From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Peter Chang , Douglas Gilbert , "Martin K. Petersen" Subject: [PATCH 3.18 045/124] scsi: sg: check length passed to SG_NEXT_CMD_LEN Date: Thu, 20 Apr 2017 08:35:20 +0200 Message-Id: <20170420063558.791403420@linuxfoundation.org> X-Mailer: git-send-email 2.12.2 In-Reply-To: <20170420063557.021306233@linuxfoundation.org> References: <20170420063557.021306233@linuxfoundation.org> User-Agent: quilt/0.65 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 942 Lines: 33 3.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: peter chang commit bf33f87dd04c371ea33feb821b60d63d754e3124 upstream. The user can control the size of the next command passed along, but the value passed to the ioctl isn't checked against the usable max command size. Signed-off-by: Peter Chang Acked-by: Douglas Gilbert Signed-off-by: Martin K. Petersen Signed-off-by: Greg Kroah-Hartman --- drivers/scsi/sg.c | 2 ++ 1 file changed, 2 insertions(+) --- a/drivers/scsi/sg.c +++ b/drivers/scsi/sg.c @@ -1017,6 +1017,8 @@ sg_ioctl(struct file *filp, unsigned int result = get_user(val, ip); if (result) return result; + if (val > SG_MAX_CDB_SIZE) + return -ENOMEM; sfp->next_cmd_len = (val > 0) ? val : 0; return 0; case SG_GET_VERSION_NUM: