From patchwork Wed May 10 13:24:36 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hannes Reinecke X-Patchwork-Id: 9719837 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 582C16035D for ; Wed, 10 May 2017 13:24:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4C736285EE for ; Wed, 10 May 2017 13:24:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 41074285F1; Wed, 10 May 2017 13:24:47 +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=ham 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 B9618285EE for ; Wed, 10 May 2017 13:24:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752469AbdEJNYq (ORCPT ); Wed, 10 May 2017 09:24:46 -0400 Received: from mx2.suse.de ([195.135.220.15]:38678 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750733AbdEJNYp (ORCPT ); Wed, 10 May 2017 09:24:45 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 1FDB3AAB1; Wed, 10 May 2017 13:24:44 +0000 (UTC) From: Hannes Reinecke To: "Martin K. Petersen" Cc: Jens Axboe , Christoph Hellwig , James Bottomley , linux-scsi@vger.kernel.org, linux-block@vger.kernel.org, Hannes Reinecke , Hannes Reinecke Subject: [PATCH] scsi: sanity check for timeout in sg_io() Date: Wed, 10 May 2017 15:24:36 +0200 Message-Id: <1494422676-72745-1-git-send-email-hare@suse.de> X-Mailer: git-send-email 1.8.5.6 Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP sg_io() is using msecs_to_jiffies() to convert a passed in timeout value (in milliseconds) to a jiffies value. However, if the value is too large msecs_to_jiffies() will return MAX_JIFFY_OFFSET, which will be truncated to -2 and cause the timeout to be set to 1.3 _years_. Which is probably too long for most applications. Signed-off-by: Hannes Reinecke --- block/scsi_ioctl.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c index 4a294a5..53b95ea 100644 --- a/block/scsi_ioctl.c +++ b/block/scsi_ioctl.c @@ -231,6 +231,7 @@ static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq, struct sg_io_hdr *hdr, fmode_t mode) { struct scsi_request *req = scsi_req(rq); + unsigned long timeout; if (copy_from_user(req->cmd, hdr->cmdp, hdr->cmd_len)) return -EFAULT; @@ -242,7 +243,11 @@ static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq, */ req->cmd_len = hdr->cmd_len; - rq->timeout = msecs_to_jiffies(hdr->timeout); + timeout = msecs_to_jiffies(hdr->timeout); + if (timeout == MAX_JIFFY_OFFSET) + rq->timeout = 0; + else + rq->timeout = timeout; if (!rq->timeout) rq->timeout = q->sg_timeout; if (!rq->timeout)