From patchwork Wed Jul 26 20:19:31 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason L Tibbitts III X-Patchwork-Id: 9865781 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 55619601A1 for ; Wed, 26 Jul 2017 20:19:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 45EC7286C4 for ; Wed, 26 Jul 2017 20:19:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3A059287B0; Wed, 26 Jul 2017 20:19:56 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CBD67286C4 for ; Wed, 26 Jul 2017 20:19:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751089AbdGZUTn (ORCPT ); Wed, 26 Jul 2017 16:19:43 -0400 Received: from mx2.math.uh.edu ([129.7.128.33]:47688 "EHLO mx2.math.uh.edu" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750970AbdGZUTl (ORCPT ); Wed, 26 Jul 2017 16:19:41 -0400 Received: from epithumia.math.uh.edu ([129.7.128.2]) by mx2.math.uh.edu with esmtp (Exim 4.87) (envelope-from ) id 1daSmJ-00058O-AZ; Wed, 26 Jul 2017 15:19:32 -0500 Received: by epithumia.math.uh.edu (Postfix, from userid 7225) id 4467E834422; Wed, 26 Jul 2017 15:19:31 -0500 (CDT) From: Jason L Tibbitts III To: Johannes Thumshirn Cc: Doug Gilbert , linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, dvyukov@google.com, hare@suse.com, hch@lst.de, martin.petersen@oracle.com Subject: Re: [REGRESSION] 28676d869bbb (scsi: sg: check for valid direction before starting the request) breaks mtx tape library control References: <20170718073747.GD4875@linux-x5ow.site> <20170719070335.GC4151@linux-x5ow.site> <20170719083654.GE4151@linux-x5ow.site> <20170721164343.GA4086@linux-x5ow.site> <20170725071852.GA3750@linux-x5ow.site> <20170726073934.GC4039@linux-x5ow.site> Date: Wed, 26 Jul 2017 15:19:31 -0500 In-Reply-To: <20170726073934.GC4039@linux-x5ow.site> (Johannes Thumshirn's message of "Wed, 26 Jul 2017 09:39:34 +0200") Message-ID: User-Agent: Gnus/5.130014 (Ma Gnus v0.14) Emacs/25.2 (gnu/linux) MIME-Version: 1.0 Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP >>>>> "JT" == Johannes Thumshirn writes: JT> It's probably best to just check for dxfer_len <= 2^28 to be valid JT> as Doug suggested: I can verify that patch on top of git head (as of a few hours ago) does function properly. It didn't apply directly on top of 4.12 but even I can handle fixing that up. The result (just deleting the function and changing the call to a check for hp->dxfer_len >= SZ_256M) works fine and is at the end. So thanks. If this goes in, please CC to stable. - J< diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c index 82c33a6..aa6f1de 100644 --- a/drivers/scsi/sg.c +++ b/drivers/scsi/sg.c @@ -751,29 +751,6 @@ sg_new_write(Sg_fd *sfp, struct file *file, const char __user *buf, return count; } -static bool sg_is_valid_dxfer(sg_io_hdr_t *hp) -{ - switch (hp->dxfer_direction) { - case SG_DXFER_NONE: - if (hp->dxferp || hp->dxfer_len > 0) - return false; - return true; - case SG_DXFER_TO_DEV: - case SG_DXFER_FROM_DEV: - case SG_DXFER_TO_FROM_DEV: - if (!hp->dxferp || hp->dxfer_len == 0) - return false; - return true; - case SG_DXFER_UNKNOWN: - if ((!hp->dxferp && hp->dxfer_len) || - (hp->dxferp && hp->dxfer_len == 0)) - return false; - return true; - default: - return false; - } -} - static int sg_common_write(Sg_fd * sfp, Sg_request * srp, unsigned char *cmnd, int timeout, int blocking) @@ -794,7 +771,7 @@ sg_common_write(Sg_fd * sfp, Sg_request * srp, "sg_common_write: scsi opcode=0x%02x, cmd_size=%d\n", (int) cmnd[0], (int) hp->cmd_len)); - if (!sg_is_valid_dxfer(hp)) + if (hp->dxfer_len >= SZ_256M) return -EINVAL; k = sg_start_req(srp, cmnd);