public inbox for linux-scsi@vger.kernel.org
 help / color / mirror / Atom feed
From: Douglas Gilbert <dgilbert@interlog.com>
To: Mikulas Patocka <mpatocka@redhat.com>
Cc: linux-scsi@vger.kernel.org
Subject: Re: [PATCH] sg: fix overflow in timeout calculation
Date: Mon, 23 Feb 2015 15:05:00 -0500	[thread overview]
Message-ID: <54EB87EC.3030604@interlog.com> (raw)
In-Reply-To: <alpine.LRH.2.02.1502091343310.23787@file01.intranet.prod.int.rdu2.redhat.com>

On 15-02-09 01:45 PM, Mikulas Patocka wrote:
> USER_HZ may be greater than HZ and in that case arithmetics tries to
> calculate the maximum accepted timeout overflows. We need to use INT_MAX
> in this case.
>
> Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
> Cc: stable@vger.kernel.org

Acked-by: Douglas Gilbert <dgilbert@interlog.com>

> ---
>   drivers/scsi/sg.c |   10 ++++++++--
>   1 file changed, 8 insertions(+), 2 deletions(-)
>
> Index: linux-3.17-rc6/drivers/scsi/sg.c
> ===================================================================
> --- linux-3.17-rc6.orig/drivers/scsi/sg.c	2014-09-26 20:10:22.000000000 +0200
> +++ linux-3.17-rc6/drivers/scsi/sg.c	2014-09-26 20:10:50.000000000 +0200
> @@ -90,6 +90,12 @@ static void sg_proc_cleanup(void);
>    */
>   #define MULDIV(X,MUL,DIV) ((((X % DIV) * MUL) / DIV) + ((X / DIV) * MUL))
>
> +#if USER_HZ < HZ
> +#define MAX_USER_TIMEOUT MULDIV (INT_MAX, USER_HZ, HZ)
> +#else
> +#define MAX_USER_TIMEOUT INT_MAX
> +#endif
> +
>   #define SG_DEFAULT_TIMEOUT MULDIV(SG_DEFAULT_TIMEOUT_USER, HZ, USER_HZ)
>
>   int sg_big_buff = SG_DEF_RESERVED_SIZE;
> @@ -892,8 +898,8 @@ sg_ioctl(struct file *filp, unsigned int
>   			return result;
>   		if (val < 0)
>   			return -EIO;
> -		if (val >= MULDIV (INT_MAX, USER_HZ, HZ))
> -		    val = MULDIV (INT_MAX, USER_HZ, HZ);
> +		if (val >= MAX_USER_TIMEOUT)
> +		    val = MAX_USER_TIMEOUT;
>   		sfp->timeout_user = val;
>   		sfp->timeout = MULDIV (val, HZ, USER_HZ);
>
> --


      reply	other threads:[~2015-02-23 20:05 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-09 18:45 [PATCH] sg: fix overflow in timeout calculation Mikulas Patocka
2015-02-23 20:05 ` Douglas Gilbert [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=54EB87EC.3030604@interlog.com \
    --to=dgilbert@interlog.com \
    --cc=linux-scsi@vger.kernel.org \
    --cc=mpatocka@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox