All of lore.kernel.org
 help / color / mirror / Atom feed
* [patch 2/2] misc: mic/scif: fix wrap around tests
@ 2015-10-09  6:40 ` Dan Carpenter
  0 siblings, 0 replies; 10+ messages in thread
From: Dan Carpenter @ 2015-10-09  6:40 UTC (permalink / raw)
  To: Sudeep Dutt; +Cc: Nikhil Rao, Greg Kroah-Hartman, linux-kernel, kernel-janitors

Signed integer overflow is undefined.  Also I added a check for
"(offset < 0)" in scif_unregister() because that makes it match the
other conditions and because I didn't want to subtract a negative.

Fixes: ba612aa8b487 ('misc: mic: SCIF memory registration and unregistration')
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---

Imagine you are on 64 bit and len is larger than INT_MAX << 12, it means
that we truncate it because scif_get_window_offset() takes an integer
argument.  I don't know if this is an issue.  Maybe I should use
INT_MAX instead of LONG_MAX?  I am working on a static checker warning
for these types of issues:
drivers/misc/mic/scif/scif_rma.c:1631 scif_register() warn: truncating user data 'len >> 12' '0-4503599627370495'
drivers/misc/mic/scif/scif_rma.c:1643 scif_register() warn: truncating user data 'len >> 12' '0-4503599627370495'

The other static warnings here are:

drivers/misc/mic/scif/scif_rma.c:745 scif_unregister_window() warn: inconsistent returns 'mutex:&ep->rma_info.rma_lock'.
  Locked on:   line 745
  Unlocked on: line 687
drivers/misc/mic/scif/scif_rma.c:1463 scif_unpin_pages() warn: passing __func__ while the format string already contains the name of the function 'scif_unpin_pages'

diff --git a/drivers/misc/mic/scif/scif_rma.c b/drivers/misc/mic/scif/scif_rma.c
index bc2dccb..fea7d2c 100644
--- a/drivers/misc/mic/scif/scif_rma.c
+++ b/drivers/misc/mic/scif/scif_rma.c
@@ -1510,7 +1510,7 @@ off_t scif_register_pinned_pages(scif_epd_t epd,
 	if ((map_flags & SCIF_MAP_FIXED) &&
 	    ((ALIGN(offset, PAGE_SIZE) != offset) ||
 	    (offset < 0) ||
-	    (offset + (off_t)len < offset)))
+	    (len > LONG_MAX - offset)))
 		return -EINVAL;
 
 	might_sleep();
@@ -1613,7 +1613,7 @@ off_t scif_register(scif_epd_t epd, void *addr, size_t len, off_t offset,
 	if ((map_flags & SCIF_MAP_FIXED) &&
 	    ((ALIGN(offset, PAGE_SIZE) != offset) ||
 	    (offset < 0) ||
-	    (offset + (off_t)len < offset)))
+	    (len < LONG_MAX - offset)))
 		return -EINVAL;
 
 	/* Unsupported protection requested */
@@ -1731,7 +1731,8 @@ scif_unregister(scif_epd_t epd, off_t offset, size_t len)
 
 	/* Offset is not page aligned or offset+len wraps around */
 	if ((ALIGN(offset, PAGE_SIZE) != offset) ||
-	    (offset + (off_t)len < offset))
+	    (offset < 0) ||
+	    (len > LONG_MAX - offset))
 		return -EINVAL;
 
 	err = scif_verify_epd(ep);

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

* [patch 2/2] misc: mic/scif: fix wrap around tests
@ 2015-10-09  6:40 ` Dan Carpenter
  0 siblings, 0 replies; 10+ messages in thread
From: Dan Carpenter @ 2015-10-09  6:40 UTC (permalink / raw)
  To: Sudeep Dutt; +Cc: Nikhil Rao, Greg Kroah-Hartman, linux-kernel, kernel-janitors

Signed integer overflow is undefined.  Also I added a check for
"(offset < 0)" in scif_unregister() because that makes it match the
other conditions and because I didn't want to subtract a negative.

Fixes: ba612aa8b487 ('misc: mic: SCIF memory registration and unregistration')
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---

Imagine you are on 64 bit and len is larger than INT_MAX << 12, it means
that we truncate it because scif_get_window_offset() takes an integer
argument.  I don't know if this is an issue.  Maybe I should use
INT_MAX instead of LONG_MAX?  I am working on a static checker warning
for these types of issues:
drivers/misc/mic/scif/scif_rma.c:1631 scif_register() warn: truncating user data 'len >> 12' '0-4503599627370495'
drivers/misc/mic/scif/scif_rma.c:1643 scif_register() warn: truncating user data 'len >> 12' '0-4503599627370495'

The other static warnings here are:

drivers/misc/mic/scif/scif_rma.c:745 scif_unregister_window() warn: inconsistent returns 'mutex:&ep->rma_info.rma_lock'.
  Locked on:   line 745
  Unlocked on: line 687
drivers/misc/mic/scif/scif_rma.c:1463 scif_unpin_pages() warn: passing __func__ while the format string already contains the name of the function 'scif_unpin_pages'

diff --git a/drivers/misc/mic/scif/scif_rma.c b/drivers/misc/mic/scif/scif_rma.c
index bc2dccb..fea7d2c 100644
--- a/drivers/misc/mic/scif/scif_rma.c
+++ b/drivers/misc/mic/scif/scif_rma.c
@@ -1510,7 +1510,7 @@ off_t scif_register_pinned_pages(scif_epd_t epd,
 	if ((map_flags & SCIF_MAP_FIXED) &&
 	    ((ALIGN(offset, PAGE_SIZE) != offset) ||
 	    (offset < 0) ||
-	    (offset + (off_t)len < offset)))
+	    (len > LONG_MAX - offset)))
 		return -EINVAL;
 
 	might_sleep();
@@ -1613,7 +1613,7 @@ off_t scif_register(scif_epd_t epd, void *addr, size_t len, off_t offset,
 	if ((map_flags & SCIF_MAP_FIXED) &&
 	    ((ALIGN(offset, PAGE_SIZE) != offset) ||
 	    (offset < 0) ||
-	    (offset + (off_t)len < offset)))
+	    (len < LONG_MAX - offset)))
 		return -EINVAL;
 
 	/* Unsupported protection requested */
@@ -1731,7 +1731,8 @@ scif_unregister(scif_epd_t epd, off_t offset, size_t len)
 
 	/* Offset is not page aligned or offset+len wraps around */
 	if ((ALIGN(offset, PAGE_SIZE) != offset) ||
-	    (offset + (off_t)len < offset))
+	    (offset < 0) ||
+	    (len > LONG_MAX - offset))
 		return -EINVAL;
 
 	err = scif_verify_epd(ep);

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

* Re: [patch 2/2] misc: mic/scif: fix wrap around tests
  2015-10-09  6:40 ` Dan Carpenter
@ 2015-10-11  9:14   ` Sudeep Dutt
  -1 siblings, 0 replies; 10+ messages in thread
From: Sudeep Dutt @ 2015-10-11  9:14 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Sudeep Dutt, Nikhil Rao, Greg Kroah-Hartman, linux-kernel,
	kernel-janitors

On Fri, 2015-10-09 at 09:40 +0300, Dan Carpenter wrote:
> Signed integer overflow is undefined.  Also I added a check for
> "(offset < 0)" in scif_unregister() because that makes it match the
> other conditions and because I didn't want to subtract a negative.
> 
> Fixes: ba612aa8b487 ('misc: mic: SCIF memory registration and unregistration')
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> ---
> 
> Imagine you are on 64 bit and len is larger than INT_MAX << 12, it means
> that we truncate it because scif_get_window_offset() takes an integer
> argument.  I don't know if this is an issue. 

scif_get_window_offset(..) takes an integer argument for the number of
pages. We believe that an int for number of 4K pages is sufficient for
current systems. I don't think there is an issue here.

>  Maybe I should use
> INT_MAX instead of LONG_MAX?  I am working on a static checker warning
> for these types of issues:
> drivers/misc/mic/scif/scif_rma.c:1631 scif_register() warn: truncating user data 'len >> 12' '0-4503599627370495'
> drivers/misc/mic/scif/scif_rma.c:1643 scif_register() warn: truncating user data 'len >> 12' '0-4503599627370495'
> 
> The other static warnings here are:
> 
> drivers/misc/mic/scif/scif_rma.c:745 scif_unregister_window() warn: inconsistent returns 'mutex:&ep->rma_info.rma_lock'.
>   Locked on:   line 745
>   Unlocked on: line 687

The function expects the lock to be held by the caller so there is no
issue here.

> drivers/misc/mic/scif/scif_rma.c:1463 scif_unpin_pages() warn: passing __func__ while the format string already contains the name of the function 'scif_unpin_pages'
> 

It might be useful to enhance checkpatch to catch such issues.

> diff --git a/drivers/misc/mic/scif/scif_rma.c b/drivers/misc/mic/scif/scif_rma.c
> index bc2dccb..fea7d2c 100644
> --- a/drivers/misc/mic/scif/scif_rma.c
> +++ b/drivers/misc/mic/scif/scif_rma.c
> @@ -1510,7 +1510,7 @@ off_t scif_register_pinned_pages(scif_epd_t epd,
>  	if ((map_flags & SCIF_MAP_FIXED) &&
>  	    ((ALIGN(offset, PAGE_SIZE) != offset) ||
>  	    (offset < 0) ||
> -	    (offset + (off_t)len < offset)))
> +	    (len > LONG_MAX - offset)))
>  		return -EINVAL;
>  
>  	might_sleep();
> @@ -1613,7 +1613,7 @@ off_t scif_register(scif_epd_t epd, void *addr, size_t len, off_t offset,
>  	if ((map_flags & SCIF_MAP_FIXED) &&
>  	    ((ALIGN(offset, PAGE_SIZE) != offset) ||
>  	    (offset < 0) ||
> -	    (offset + (off_t)len < offset)))
> +	    (len < LONG_MAX - offset)))

Why is this change required? The earlier code was being used to detect
wraparound and I think it works fine.

Thanks,
Sudeep Dutt


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

* Re: [patch 2/2] misc: mic/scif: fix wrap around tests
@ 2015-10-11  9:14   ` Sudeep Dutt
  0 siblings, 0 replies; 10+ messages in thread
From: Sudeep Dutt @ 2015-10-11  9:14 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Sudeep Dutt, Nikhil Rao, Greg Kroah-Hartman, linux-kernel,
	kernel-janitors

On Fri, 2015-10-09 at 09:40 +0300, Dan Carpenter wrote:
> Signed integer overflow is undefined.  Also I added a check for
> "(offset < 0)" in scif_unregister() because that makes it match the
> other conditions and because I didn't want to subtract a negative.
> 
> Fixes: ba612aa8b487 ('misc: mic: SCIF memory registration and unregistration')
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> ---
> 
> Imagine you are on 64 bit and len is larger than INT_MAX << 12, it means
> that we truncate it because scif_get_window_offset() takes an integer
> argument.  I don't know if this is an issue. 

scif_get_window_offset(..) takes an integer argument for the number of
pages. We believe that an int for number of 4K pages is sufficient for
current systems. I don't think there is an issue here.

>  Maybe I should use
> INT_MAX instead of LONG_MAX?  I am working on a static checker warning
> for these types of issues:
> drivers/misc/mic/scif/scif_rma.c:1631 scif_register() warn: truncating user data 'len >> 12' '0-4503599627370495'
> drivers/misc/mic/scif/scif_rma.c:1643 scif_register() warn: truncating user data 'len >> 12' '0-4503599627370495'
> 
> The other static warnings here are:
> 
> drivers/misc/mic/scif/scif_rma.c:745 scif_unregister_window() warn: inconsistent returns 'mutex:&ep->rma_info.rma_lock'.
>   Locked on:   line 745
>   Unlocked on: line 687

The function expects the lock to be held by the caller so there is no
issue here.

> drivers/misc/mic/scif/scif_rma.c:1463 scif_unpin_pages() warn: passing __func__ while the format string already contains the name of the function 'scif_unpin_pages'
> 

It might be useful to enhance checkpatch to catch such issues.

> diff --git a/drivers/misc/mic/scif/scif_rma.c b/drivers/misc/mic/scif/scif_rma.c
> index bc2dccb..fea7d2c 100644
> --- a/drivers/misc/mic/scif/scif_rma.c
> +++ b/drivers/misc/mic/scif/scif_rma.c
> @@ -1510,7 +1510,7 @@ off_t scif_register_pinned_pages(scif_epd_t epd,
>  	if ((map_flags & SCIF_MAP_FIXED) &&
>  	    ((ALIGN(offset, PAGE_SIZE) != offset) ||
>  	    (offset < 0) ||
> -	    (offset + (off_t)len < offset)))
> +	    (len > LONG_MAX - offset)))
>  		return -EINVAL;
>  
>  	might_sleep();
> @@ -1613,7 +1613,7 @@ off_t scif_register(scif_epd_t epd, void *addr, size_t len, off_t offset,
>  	if ((map_flags & SCIF_MAP_FIXED) &&
>  	    ((ALIGN(offset, PAGE_SIZE) != offset) ||
>  	    (offset < 0) ||
> -	    (offset + (off_t)len < offset)))
> +	    (len < LONG_MAX - offset)))

Why is this change required? The earlier code was being used to detect
wraparound and I think it works fine.

Thanks,
Sudeep Dutt


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

* Re: [patch 2/2] misc: mic/scif: fix wrap around tests
  2015-10-11  9:14   ` Sudeep Dutt
@ 2015-10-13 12:51     ` Dan Carpenter
  -1 siblings, 0 replies; 10+ messages in thread
From: Dan Carpenter @ 2015-10-13 12:51 UTC (permalink / raw)
  To: Sudeep Dutt; +Cc: Nikhil Rao, Greg Kroah-Hartman, linux-kernel, kernel-janitors

On Sun, Oct 11, 2015 at 02:14:44AM -0700, Sudeep Dutt wrote:
> On Fri, 2015-10-09 at 09:40 +0300, Dan Carpenter wrote:
> > Signed integer overflow is undefined.  Also I added a check for
> > "(offset < 0)" in scif_unregister() because that makes it match the
> > other conditions and because I didn't want to subtract a negative.
> > 
> > Fixes: ba612aa8b487 ('misc: mic: SCIF memory registration and unregistration')
> > Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> > ---
> > 
> > Imagine you are on 64 bit and len is larger than INT_MAX << 12, it means
> > that we truncate it because scif_get_window_offset() takes an integer
> > argument.  I don't know if this is an issue. 
> 
> scif_get_window_offset(..) takes an integer argument for the number of
> pages. We believe that an int for number of 4K pages is sufficient for
> current systems. I don't think there is an issue here.

The issue isn't that we need more pages, it's that we can overflow
INT_MAX so scif_get_window_offset() succeeds when it should fail.

> 
> >  Maybe I should use
> > INT_MAX instead of LONG_MAX?  I am working on a static checker warning
> > for these types of issues:
> > drivers/misc/mic/scif/scif_rma.c:1631 scif_register() warn: truncating user data 'len >> 12' '0-4503599627370495'
> > drivers/misc/mic/scif/scif_rma.c:1643 scif_register() warn: truncating user data 'len >> 12' '0-4503599627370495'
> > 
> > The other static warnings here are:
> > 
> > drivers/misc/mic/scif/scif_rma.c:745 scif_unregister_window() warn: inconsistent returns 'mutex:&ep->rma_info.rma_lock'.
> >   Locked on:   line 745
> >   Unlocked on: line 687
> 
> The function expects the lock to be held by the caller so there is no
> issue here.
> 

You're missing the point.  Never mind, I will send a patch for this.

> > @@ -1613,7 +1613,7 @@ off_t scif_register(scif_epd_t epd, void *addr, size_t len, off_t offset,
> >  	if ((map_flags & SCIF_MAP_FIXED) &&
> >  	    ((ALIGN(offset, PAGE_SIZE) != offset) ||
> >  	    (offset < 0) ||
> > -	    (offset + (off_t)len < offset)))
> > +	    (len < LONG_MAX - offset)))
> 
> Why is this change required? The earlier code was being used to detect
> wraparound and I think it works fine.

It doesn't work.  off_t is a signed type so it's undefined.  The
compiler will often just remove the condition.

regards,
dan carpenter


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

* Re: [patch 2/2] misc: mic/scif: fix wrap around tests
@ 2015-10-13 12:51     ` Dan Carpenter
  0 siblings, 0 replies; 10+ messages in thread
From: Dan Carpenter @ 2015-10-13 12:51 UTC (permalink / raw)
  To: Sudeep Dutt; +Cc: Nikhil Rao, Greg Kroah-Hartman, linux-kernel, kernel-janitors

On Sun, Oct 11, 2015 at 02:14:44AM -0700, Sudeep Dutt wrote:
> On Fri, 2015-10-09 at 09:40 +0300, Dan Carpenter wrote:
> > Signed integer overflow is undefined.  Also I added a check for
> > "(offset < 0)" in scif_unregister() because that makes it match the
> > other conditions and because I didn't want to subtract a negative.
> > 
> > Fixes: ba612aa8b487 ('misc: mic: SCIF memory registration and unregistration')
> > Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> > ---
> > 
> > Imagine you are on 64 bit and len is larger than INT_MAX << 12, it means
> > that we truncate it because scif_get_window_offset() takes an integer
> > argument.  I don't know if this is an issue. 
> 
> scif_get_window_offset(..) takes an integer argument for the number of
> pages. We believe that an int for number of 4K pages is sufficient for
> current systems. I don't think there is an issue here.

The issue isn't that we need more pages, it's that we can overflow
INT_MAX so scif_get_window_offset() succeeds when it should fail.

> 
> >  Maybe I should use
> > INT_MAX instead of LONG_MAX?  I am working on a static checker warning
> > for these types of issues:
> > drivers/misc/mic/scif/scif_rma.c:1631 scif_register() warn: truncating user data 'len >> 12' '0-4503599627370495'
> > drivers/misc/mic/scif/scif_rma.c:1643 scif_register() warn: truncating user data 'len >> 12' '0-4503599627370495'
> > 
> > The other static warnings here are:
> > 
> > drivers/misc/mic/scif/scif_rma.c:745 scif_unregister_window() warn: inconsistent returns 'mutex:&ep->rma_info.rma_lock'.
> >   Locked on:   line 745
> >   Unlocked on: line 687
> 
> The function expects the lock to be held by the caller so there is no
> issue here.
> 

You're missing the point.  Never mind, I will send a patch for this.

> > @@ -1613,7 +1613,7 @@ off_t scif_register(scif_epd_t epd, void *addr, size_t len, off_t offset,
> >  	if ((map_flags & SCIF_MAP_FIXED) &&
> >  	    ((ALIGN(offset, PAGE_SIZE) != offset) ||
> >  	    (offset < 0) ||
> > -	    (offset + (off_t)len < offset)))
> > +	    (len < LONG_MAX - offset)))
> 
> Why is this change required? The earlier code was being used to detect
> wraparound and I think it works fine.

It doesn't work.  off_t is a signed type so it's undefined.  The
compiler will often just remove the condition.

regards,
dan carpenter


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

* Re: [patch 2/2] misc: mic/scif: fix wrap around tests
  2015-10-09  6:40 ` Dan Carpenter
@ 2015-10-14  3:21   ` Sudeep Dutt
  -1 siblings, 0 replies; 10+ messages in thread
From: Sudeep Dutt @ 2015-10-14  3:21 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Sudeep Dutt, Nikhil Rao, Greg Kroah-Hartman, linux-kernel,
	kernel-janitors

On Fri, 2015-10-09 at 09:40 +0300, Dan Carpenter wrote:
> Signed integer overflow is undefined.  Also I added a check for
> "(offset < 0)" in scif_unregister() because that makes it match the
> other conditions and because I didn't want to subtract a negative.
> 
> Fixes: ba612aa8b487 ('misc: mic: SCIF memory registration and unregistration')
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> ---
> 
> Imagine you are on 64 bit and len is larger than INT_MAX << 12, it means
> that we truncate it because scif_get_window_offset() takes an integer
> argument.  I don't know if this is an issue.  Maybe I should use
> INT_MAX instead of LONG_MAX?  I am working on a static checker warning
> for these types of issues:
> drivers/misc/mic/scif/scif_rma.c:1631 scif_register() warn: truncating user data 'len >> 12' '0-4503599627370495'
> drivers/misc/mic/scif/scif_rma.c:1643 scif_register() warn: truncating user data 'len >> 12' '0-4503599627370495'
> 
> The other static warnings here are:
> 
> drivers/misc/mic/scif/scif_rma.c:745 scif_unregister_window() warn: inconsistent returns 'mutex:&ep->rma_info.rma_lock'.
>   Locked on:   line 745
>   Unlocked on: line 687
> drivers/misc/mic/scif/scif_rma.c:1463 scif_unpin_pages() warn: passing __func__ while the format string already contains the name of the function 'scif_unpin_pages'
> 
> diff --git a/drivers/misc/mic/scif/scif_rma.c b/drivers/misc/mic/scif/scif_rma.c
> index bc2dccb..fea7d2c 100644
> --- a/drivers/misc/mic/scif/scif_rma.c
> +++ b/drivers/misc/mic/scif/scif_rma.c
> @@ -1510,7 +1510,7 @@ off_t scif_register_pinned_pages(scif_epd_t epd,
>  	if ((map_flags & SCIF_MAP_FIXED) &&
>  	    ((ALIGN(offset, PAGE_SIZE) != offset) ||
>  	    (offset < 0) ||
> -	    (offset + (off_t)len < offset)))
> +	    (len > LONG_MAX - offset)))
>  		return -EINVAL;
>  
>  	might_sleep();
> @@ -1613,7 +1613,7 @@ off_t scif_register(scif_epd_t epd, void *addr, size_t len, off_t offset,
>  	if ((map_flags & SCIF_MAP_FIXED) &&
>  	    ((ALIGN(offset, PAGE_SIZE) != offset) ||
>  	    (offset < 0) ||
> -	    (offset + (off_t)len < offset)))
> +	    (len < LONG_MAX - offset)))

Hi Dan,
Should this be > instead of < like the others?
Thanks,
Sudeep Dutt

>  		return -EINVAL;
>  
>  	/* Unsupported protection requested */
> @@ -1731,7 +1731,8 @@ scif_unregister(scif_epd_t epd, off_t offset, size_t len)
>  
>  	/* Offset is not page aligned or offset+len wraps around */
>  	if ((ALIGN(offset, PAGE_SIZE) != offset) ||
> -	    (offset + (off_t)len < offset))
> +	    (offset < 0) ||
> +	    (len > LONG_MAX - offset))
>  		return -EINVAL;
>  
>  	err = scif_verify_epd(ep);



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

* Re: [patch 2/2] misc: mic/scif: fix wrap around tests
@ 2015-10-14  3:21   ` Sudeep Dutt
  0 siblings, 0 replies; 10+ messages in thread
From: Sudeep Dutt @ 2015-10-14  3:21 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Sudeep Dutt, Nikhil Rao, Greg Kroah-Hartman, linux-kernel,
	kernel-janitors

On Fri, 2015-10-09 at 09:40 +0300, Dan Carpenter wrote:
> Signed integer overflow is undefined.  Also I added a check for
> "(offset < 0)" in scif_unregister() because that makes it match the
> other conditions and because I didn't want to subtract a negative.
> 
> Fixes: ba612aa8b487 ('misc: mic: SCIF memory registration and unregistration')
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> ---
> 
> Imagine you are on 64 bit and len is larger than INT_MAX << 12, it means
> that we truncate it because scif_get_window_offset() takes an integer
> argument.  I don't know if this is an issue.  Maybe I should use
> INT_MAX instead of LONG_MAX?  I am working on a static checker warning
> for these types of issues:
> drivers/misc/mic/scif/scif_rma.c:1631 scif_register() warn: truncating user data 'len >> 12' '0-4503599627370495'
> drivers/misc/mic/scif/scif_rma.c:1643 scif_register() warn: truncating user data 'len >> 12' '0-4503599627370495'
> 
> The other static warnings here are:
> 
> drivers/misc/mic/scif/scif_rma.c:745 scif_unregister_window() warn: inconsistent returns 'mutex:&ep->rma_info.rma_lock'.
>   Locked on:   line 745
>   Unlocked on: line 687
> drivers/misc/mic/scif/scif_rma.c:1463 scif_unpin_pages() warn: passing __func__ while the format string already contains the name of the function 'scif_unpin_pages'
> 
> diff --git a/drivers/misc/mic/scif/scif_rma.c b/drivers/misc/mic/scif/scif_rma.c
> index bc2dccb..fea7d2c 100644
> --- a/drivers/misc/mic/scif/scif_rma.c
> +++ b/drivers/misc/mic/scif/scif_rma.c
> @@ -1510,7 +1510,7 @@ off_t scif_register_pinned_pages(scif_epd_t epd,
>  	if ((map_flags & SCIF_MAP_FIXED) &&
>  	    ((ALIGN(offset, PAGE_SIZE) != offset) ||
>  	    (offset < 0) ||
> -	    (offset + (off_t)len < offset)))
> +	    (len > LONG_MAX - offset)))
>  		return -EINVAL;
>  
>  	might_sleep();
> @@ -1613,7 +1613,7 @@ off_t scif_register(scif_epd_t epd, void *addr, size_t len, off_t offset,
>  	if ((map_flags & SCIF_MAP_FIXED) &&
>  	    ((ALIGN(offset, PAGE_SIZE) != offset) ||
>  	    (offset < 0) ||
> -	    (offset + (off_t)len < offset)))
> +	    (len < LONG_MAX - offset)))

Hi Dan,
Should this be > instead of < like the others?
Thanks,
Sudeep Dutt

>  		return -EINVAL;
>  
>  	/* Unsupported protection requested */
> @@ -1731,7 +1731,8 @@ scif_unregister(scif_epd_t epd, off_t offset, size_t len)
>  
>  	/* Offset is not page aligned or offset+len wraps around */
>  	if ((ALIGN(offset, PAGE_SIZE) != offset) ||
> -	    (offset + (off_t)len < offset))
> +	    (offset < 0) ||
> +	    (len > LONG_MAX - offset))
>  		return -EINVAL;
>  
>  	err = scif_verify_epd(ep);



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

* Re: [patch 2/2] misc: mic/scif: fix wrap around tests
  2015-10-14  3:21   ` Sudeep Dutt
@ 2015-10-14 18:05     ` Dan Carpenter
  -1 siblings, 0 replies; 10+ messages in thread
From: Dan Carpenter @ 2015-10-14 18:05 UTC (permalink / raw)
  To: Sudeep Dutt; +Cc: Nikhil Rao, Greg Kroah-Hartman, linux-kernel, kernel-janitors

On Tue, Oct 13, 2015 at 08:21:24PM -0700, Sudeep Dutt wrote:

> > @@ -1613,7 +1613,7 @@ off_t scif_register(scif_epd_t epd, void *addr, size_t len, off_t offset,
> >  	if ((map_flags & SCIF_MAP_FIXED) &&
> >  	    ((ALIGN(offset, PAGE_SIZE) != offset) ||
> >  	    (offset < 0) ||
> > -	    (offset + (off_t)len < offset)))
> > +	    (len < LONG_MAX - offset)))
> 
> Hi Dan,
> Should this be > instead of < like the others?

Gar.  You're right, obviously.  Thanks.  I will resend tomorrow.

regards,
dan carpenter


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

* Re: [patch 2/2] misc: mic/scif: fix wrap around tests
@ 2015-10-14 18:05     ` Dan Carpenter
  0 siblings, 0 replies; 10+ messages in thread
From: Dan Carpenter @ 2015-10-14 18:05 UTC (permalink / raw)
  To: Sudeep Dutt; +Cc: Nikhil Rao, Greg Kroah-Hartman, linux-kernel, kernel-janitors

On Tue, Oct 13, 2015 at 08:21:24PM -0700, Sudeep Dutt wrote:

> > @@ -1613,7 +1613,7 @@ off_t scif_register(scif_epd_t epd, void *addr, size_t len, off_t offset,
> >  	if ((map_flags & SCIF_MAP_FIXED) &&
> >  	    ((ALIGN(offset, PAGE_SIZE) != offset) ||
> >  	    (offset < 0) ||
> > -	    (offset + (off_t)len < offset)))
> > +	    (len < LONG_MAX - offset)))
> 
> Hi Dan,
> Should this be > instead of < like the others?

Gar.  You're right, obviously.  Thanks.  I will resend tomorrow.

regards,
dan carpenter


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

end of thread, other threads:[~2015-10-14 18:05 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-10-09  6:40 [patch 2/2] misc: mic/scif: fix wrap around tests Dan Carpenter
2015-10-09  6:40 ` Dan Carpenter
2015-10-11  9:14 ` Sudeep Dutt
2015-10-11  9:14   ` Sudeep Dutt
2015-10-13 12:51   ` Dan Carpenter
2015-10-13 12:51     ` Dan Carpenter
2015-10-14  3:21 ` Sudeep Dutt
2015-10-14  3:21   ` Sudeep Dutt
2015-10-14 18:05   ` Dan Carpenter
2015-10-14 18:05     ` Dan Carpenter

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.