Received: by 10.213.65.68 with SMTP id h4csp36045imn; Mon, 19 Mar 2018 18:43:00 -0700 (PDT) X-Google-Smtp-Source: AG47ELvggJLT6r1Jues1l8oOWmqT9josKh1+OkzfjBtmWeUmRXMQtJcP9bqGKE+Wmn8QGamFJhDJ X-Received: by 10.101.83.75 with SMTP id w11mr10466152pgr.197.1521510180099; Mon, 19 Mar 2018 18:43:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521510180; cv=none; d=google.com; s=arc-20160816; b=z5WVIIo4X8PKkFfdpOlD3A9LZO9SOyLF0rga7eJwlVlcahctpT9zfh+G9TOdyBuFQU JxhJIeyvNrUDL0/vn14ik6qmkmnEyaIEnYET5gquftPolcqbKReKLpHxozugjBq4mIZB BOo9whv3NcZ3LyYViplXR20K36L6I+OOfUnqyd9SDGYjRkMrhtwRY/FX76nOKIRW2xBu eX857tCYLXnrYj9leVb4sC2r2OVk9H3/zI4RfrzqAVrAGDGL+sHkuVV/+KVeWgIobjKJ SLE+h3znmGHppmcd3be1eITkL0kcxw6bTRJh72lbLNLpJw9dcVwthlcoO8M6J+SJLrb3 Zxlw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=ew1qcVvYOLA6/BYmMS8xbf9iA9E1Hr4zU//crB87vmQ=; b=gccvKy0YwZnzntEQcxBInetzygVwq0E0i3/LHGabyYiJXJDkKGXkT3tKS7TmqymqFH NYXUTF9T30Wa4ACG+P3Z3O3o6Dzxm4N7jMXytLAyrzSA3E3VRxY2evhy6D4tBFveF0fe poFaIO7IRRMl22GCLOE78KF0OBIw76CK+oK8enKlRcM72nJz1UUvhXH9NnKBn1heiqrW eGAozzocB9yCwZkqfDDNGoDvEDweMw5lhi8iiSTvE1h681juUbD3ZsfEGbRE0HzFNASF xOemiNz6QmpXfNoZvGJd79CL9+b2lPwKG+OVQdzfLr7Eed0PyPxhOoTrGbDoJvMpOSlv 7BaQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d37-v6si520512plb.231.2018.03.19.18.42.46; Mon, 19 Mar 2018 18:43:00 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S969185AbeCSSRk (ORCPT + 99 others); Mon, 19 Mar 2018 14:17:40 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:45578 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965845AbeCSSR3 (ORCPT ); Mon, 19 Mar 2018 14:17:29 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 389E2FA8; Mon, 19 Mar 2018 18:17:29 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Johannes Thumshirn , Jason L Tibbitts III , Doug Gilbert , Hannes Reinecke , "Martin K. Petersen" Subject: [PATCH 4.4 128/134] scsi: sg: only check for dxfer_len greater than 256M Date: Mon, 19 Mar 2018 19:06:51 +0100 Message-Id: <20180319171907.770748258@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180319171849.024066323@linuxfoundation.org> References: <20180319171849.024066323@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Johannes Thumshirn commit f930c7043663188429cd9b254e9d761edfc101ce upstream. Don't make any assumptions on the sg_io_hdr_t::dxfer_direction or the sg_io_hdr_t::dxferp in order to determine if it is a valid request. The only way we can check for bad requests is by checking if the length exceeds 256M. Signed-off-by: Johannes Thumshirn Fixes: 28676d869bbb (scsi: sg: check for valid direction before starting the request) Reported-by: Jason L Tibbitts III Tested-by: Jason L Tibbitts III Suggested-by: Doug Gilbert Cc: Doug Gilbert Cc: Reviewed-by: Hannes Reinecke Signed-off-by: Martin K. Petersen Signed-off-by: Greg Kroah-Hartman --- drivers/scsi/sg.c | 31 +------------------------------ 1 file changed, 1 insertion(+), 30 deletions(-) --- a/drivers/scsi/sg.c +++ b/drivers/scsi/sg.c @@ -762,35 +762,6 @@ sg_new_write(Sg_fd *sfp, struct file *fi 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_FROM_DEV: - /* - * for SG_DXFER_FROM_DEV we always set dxfer_len to > 0. dxferp - * can either be NULL or != NULL so there's no point in checking - * it either. So just return true. - */ - return true; - case SG_DXFER_TO_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) @@ -811,7 +782,7 @@ sg_common_write(Sg_fd * sfp, Sg_request "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);