From owner-svn-src-all@freebsd.org Tue May 24 07:19:01 2016 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 5C862B478E2; Tue, 24 May 2016 07:19:01 +0000 (UTC) (envelope-from mav@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 37FA61001; Tue, 24 May 2016 07:19:01 +0000 (UTC) (envelope-from mav@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u4O7J0P2076888; Tue, 24 May 2016 07:19:00 GMT (envelope-from mav@FreeBSD.org) Received: (from mav@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u4O7J0kT076887; Tue, 24 May 2016 07:19:00 GMT (envelope-from mav@FreeBSD.org) Message-Id: <201605240719.u4O7J0kT076887@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: mav set sender to mav@FreeBSD.org using -f From: Alexander Motin Date: Tue, 24 May 2016 07:19:00 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r300587 - stable/10/sys/cam/ctl X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 24 May 2016 07:19:01 -0000 Author: mav Date: Tue May 24 07:19:00 2016 New Revision: 300587 URL: https://svnweb.freebsd.org/changeset/base/300587 Log: MFC r299346: More XCOPY parameters validation. Modified: stable/10/sys/cam/ctl/ctl_tpc.c Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/cam/ctl/ctl_tpc.c ============================================================================== --- stable/10/sys/cam/ctl/ctl_tpc.c Tue May 24 07:18:22 2016 (r300586) +++ stable/10/sys/cam/ctl/ctl_tpc.c Tue May 24 07:19:00 2016 (r300587) @@ -1104,6 +1104,26 @@ tpc_ranges_length(struct scsi_range_desc } static int +tpc_check_ranges(struct scsi_range_desc *range, int nrange) +{ + uint64_t b1, b2; + uint32_t l1, l2; + int i, j; + + for (i = 0; i < nrange - 1; i++) { + b1 = scsi_8btou64(range[i].lba); + l1 = scsi_4btoul(range[i].length); + for (j = i + 1; j < nrange; j++) { + b2 = scsi_8btou64(range[j].lba); + l2 = scsi_4btoul(range[j].length); + if (b1 + l1 > b2 && b2 + l2 > b1) + return (-1); + } + } + return (0); +} + +static int tpc_skip_ranges(struct scsi_range_desc *range, int nrange, off_t skip, int *srange, off_t *soffset) { @@ -1992,6 +2012,16 @@ ctl_populate_token(struct ctl_scsiio *ct goto done; } + /* Validate list of ranges */ + if (tpc_check_ranges(&data->desc[0], + scsi_2btoul(data->range_descriptor_length) / + sizeof(struct scsi_range_desc))) { + ctl_set_invalid_field(ctsio, /*sks_valid*/ 0, + /*command*/ 0, /*field*/ 0, /*bit_valid*/ 0, + /*bit*/ 0); + goto done; + } + list = malloc(sizeof(struct tpc_list), M_CTL, M_WAITOK | M_ZERO); list->service_action = cdb->service_action; list->init_port = ctsio->io_hdr.nexus.targ_port; @@ -2065,7 +2095,7 @@ ctl_write_using_token(struct ctl_scsiio struct ctl_lun *lun; struct tpc_list *list, *tlist; struct tpc_token *token; - int len, lendesc; + int len, lendata, lendesc; CTL_DEBUG_PRINT(("ctl_write_using_token\n")); @@ -2074,8 +2104,8 @@ ctl_write_using_token(struct ctl_scsiio cdb = (struct scsi_write_using_token *)ctsio->cdb; len = scsi_4btoul(cdb->length); - if (len < sizeof(struct scsi_populate_token_data) || - len > sizeof(struct scsi_populate_token_data) + + if (len < sizeof(struct scsi_write_using_token_data) || + len > sizeof(struct scsi_write_using_token_data) + TPC_MAX_SEGS * sizeof(struct scsi_range_desc)) { ctl_set_invalid_field(ctsio, /*sks_valid*/ 1, /*command*/ 1, /*field*/ 9, /*bit_valid*/ 0, /*bit*/ 0); @@ -2101,10 +2131,19 @@ ctl_write_using_token(struct ctl_scsiio } data = (struct scsi_write_using_token_data *)ctsio->kern_data_ptr; + lendata = scsi_2btoul(data->length); + if (lendata < sizeof(struct scsi_write_using_token_data) - 2 + + sizeof(struct scsi_range_desc)) { + ctl_set_invalid_field(ctsio, /*sks_valid*/ 1, /*command*/ 0, + /*field*/ 0, /*bit_valid*/ 0, /*bit*/ 0); + goto done; + } lendesc = scsi_2btoul(data->range_descriptor_length); - if (len < sizeof(struct scsi_populate_token_data) + lendesc) { + if (lendesc < sizeof(struct scsi_range_desc) || + len < sizeof(struct scsi_write_using_token_data) + lendesc || + lendata < sizeof(struct scsi_write_using_token_data) - 2 + lendesc) { ctl_set_invalid_field(ctsio, /*sks_valid*/ 1, /*command*/ 0, - /*field*/ 2, /*bit_valid*/ 0, /*bit*/ 0); + /*field*/ 534, /*bit_valid*/ 0, /*bit*/ 0); goto done; } /* @@ -2113,6 +2152,17 @@ ctl_write_using_token(struct ctl_scsiio data->flags, scsi_8btou64(data->offset_into_rod), scsi_2btoul(data->range_descriptor_length)); */ + + /* Validate list of ranges */ + if (tpc_check_ranges(&data->desc[0], + scsi_2btoul(data->range_descriptor_length) / + sizeof(struct scsi_range_desc))) { + ctl_set_invalid_field(ctsio, /*sks_valid*/ 0, + /*command*/ 0, /*field*/ 0, /*bit_valid*/ 0, + /*bit*/ 0); + goto done; + } + list = malloc(sizeof(struct tpc_list), M_CTL, M_WAITOK | M_ZERO); list->service_action = cdb->service_action; list->init_port = ctsio->io_hdr.nexus.targ_port;