public inbox for linux-scsi@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] sg: fix overflow in timeout calculation
@ 2015-02-09 18:45 Mikulas Patocka
  2015-02-23 20:05 ` Douglas Gilbert
  0 siblings, 1 reply; 2+ messages in thread
From: Mikulas Patocka @ 2015-02-09 18:45 UTC (permalink / raw)
  To: Doug Gilbert; +Cc: linux-scsi

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

---
 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);
 

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] sg: fix overflow in timeout calculation
  2015-02-09 18:45 [PATCH] sg: fix overflow in timeout calculation Mikulas Patocka
@ 2015-02-23 20:05 ` Douglas Gilbert
  0 siblings, 0 replies; 2+ messages in thread
From: Douglas Gilbert @ 2015-02-23 20:05 UTC (permalink / raw)
  To: Mikulas Patocka; +Cc: linux-scsi

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);
>
> --


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-02-23 20:05 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-02-09 18:45 [PATCH] sg: fix overflow in timeout calculation Mikulas Patocka
2015-02-23 20:05 ` Douglas Gilbert

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox