All of lore.kernel.org
 help / color / mirror / Atom feed
* Re: [PATCH lttng-modules] Fix: atomic_add_unless() already returns zero on overflow
       [not found] <1488947760-25045-1-git-send-email-francis.deslauriers@efficios.com>
@ 2017-03-08 12:09 ` Mathieu Desnoyers
  2017-03-08 16:38 ` [PATCH lttng-modules] Fix: atomic_add_unless() returns true/false rather than prior value Francis Deslauriers
       [not found] ` <1488991131-9828-1-git-send-email-francis.deslauriers@efficios.com>
  2 siblings, 0 replies; 5+ messages in thread
From: Mathieu Desnoyers @ 2017-03-08 12:09 UTC (permalink / raw)
  To: Francis Deslauriers; +Cc: lttng-dev

About the title:

could you change it to "Fix: atomic_add_unless() returns true/false rather than prior value" ?

And describe the discrepancy between the existing implementation
vs kernel interface, and its effect ?

Basically, even though the existing implementation aimed at preventing
kref overflow (and thus eventual use-after-free), the check never
triggers due to this issue.

Since lttng_kref_get is used only for the metadata cache "open" and the
lib_ring_buffer_open_read operations, we overall number of references
end up being limited by the number of file descriptors that can be
concurrently open on the entire OS, which is limited by the value
in /proc/sys/fs/file-max . So we can say that those kref overflow
protections as used here in lttng-modules are redundant with the
bound given by the maximum number of file descriptors, so it's not
a security issue per se, but it appears to be safer to have an
overflow-handling kref_get nevertheless.

Thanks,

Mathieu

----- On Mar 7, 2017, at 11:36 PM, Francis Deslauriers francis.deslauriers@efficios.com wrote:

> Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
> ---
> wrapper/kref.h | 6 +-----
> 1 file changed, 1 insertion(+), 5 deletions(-)
> 
> diff --git a/wrapper/kref.h b/wrapper/kref.h
> index eedefbf..f30a9ae 100644
> --- a/wrapper/kref.h
> +++ b/wrapper/kref.h
> @@ -36,11 +36,7 @@
>  */
> static inline int lttng_kref_get(struct kref *kref)
> {
> -	if (atomic_add_unless(&kref->refcount, 1, INT_MAX) != INT_MAX) {
> -		return 1;
> -	} else {
> -		return 0;
> -	}
> +	return atomic_add_unless(&kref->refcount, 1, INT_MAX);
> }
> 
> #endif /* _LTTNG_WRAPPER_KREF_H */
> --
> 2.7.4

-- 
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com
_______________________________________________
lttng-dev mailing list
lttng-dev@lists.lttng.org
https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev

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

* [PATCH lttng-modules] Fix: atomic_add_unless() returns true/false rather than prior value
       [not found] <1488947760-25045-1-git-send-email-francis.deslauriers@efficios.com>
  2017-03-08 12:09 ` [PATCH lttng-modules] Fix: atomic_add_unless() already returns zero on overflow Mathieu Desnoyers
@ 2017-03-08 16:38 ` Francis Deslauriers
       [not found] ` <1488991131-9828-1-git-send-email-francis.deslauriers@efficios.com>
  2 siblings, 0 replies; 5+ messages in thread
From: Francis Deslauriers @ 2017-03-08 16:38 UTC (permalink / raw)
  To: lttng-dev

The previous implementation assumed that `atomic_add_unless` returned the
prior value of the atomic counter when in fact it returned if addition was
successful(true) or overflowed(false).
Since `atomic_add_unless` can not return INT_MAX, the `lttng_kref_get`
always returned that the call was successful.

This issue had a low likelihood of being triggered since the two refcounts
of the counters used with this call are both bounded by the maximum
number of file descriptors on the system.

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
---
 wrapper/kref.h | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/wrapper/kref.h b/wrapper/kref.h
index eedefbf..f30a9ae 100644
--- a/wrapper/kref.h
+++ b/wrapper/kref.h
@@ -36,11 +36,7 @@
  */
 static inline int lttng_kref_get(struct kref *kref)
 {
-	if (atomic_add_unless(&kref->refcount, 1, INT_MAX) != INT_MAX) {
-		return 1;
-	} else {
-		return 0;
-	}
+	return atomic_add_unless(&kref->refcount, 1, INT_MAX);
 }
 
 #endif /* _LTTNG_WRAPPER_KREF_H */
-- 
2.7.4

_______________________________________________
lttng-dev mailing list
lttng-dev@lists.lttng.org
https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev

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

* Re: [PATCH lttng-modules] Fix: atomic_add_unless() returns true/false rather than prior value
       [not found] ` <1488991131-9828-1-git-send-email-francis.deslauriers@efficios.com>
@ 2017-03-08 16:43   ` Mathieu Desnoyers
  2017-03-08 16:50   ` [PATCH lttng-modules v3] " Francis Deslauriers
       [not found]   ` <1488991838-13807-1-git-send-email-francis.deslauriers@efficios.com>
  2 siblings, 0 replies; 5+ messages in thread
From: Mathieu Desnoyers @ 2017-03-08 16:43 UTC (permalink / raw)
  To: Francis Deslauriers; +Cc: lttng-dev

----- On Mar 8, 2017, at 11:38 AM, Francis Deslauriers francis.deslauriers@efficios.com wrote:

> The previous implementation assumed that `atomic_add_unless` returned the
> prior value of the atomic counter when in fact it returned if addition was
> successful(true) or overflowed(false).

I think you mean "if addition was performed (true) or not performed (false)" ?

Thanks,

Mathieu

> Since `atomic_add_unless` can not return INT_MAX, the `lttng_kref_get`
> always returned that the call was successful.
> 
> This issue had a low likelihood of being triggered since the two refcounts
> of the counters used with this call are both bounded by the maximum
> number of file descriptors on the system.
> 
> Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
> ---
> wrapper/kref.h | 6 +-----
> 1 file changed, 1 insertion(+), 5 deletions(-)
> 
> diff --git a/wrapper/kref.h b/wrapper/kref.h
> index eedefbf..f30a9ae 100644
> --- a/wrapper/kref.h
> +++ b/wrapper/kref.h
> @@ -36,11 +36,7 @@
>  */
> static inline int lttng_kref_get(struct kref *kref)
> {
> -	if (atomic_add_unless(&kref->refcount, 1, INT_MAX) != INT_MAX) {
> -		return 1;
> -	} else {
> -		return 0;
> -	}
> +	return atomic_add_unless(&kref->refcount, 1, INT_MAX);
> }
> 
> #endif /* _LTTNG_WRAPPER_KREF_H */
> --
> 2.7.4

-- 
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com
_______________________________________________
lttng-dev mailing list
lttng-dev@lists.lttng.org
https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev

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

* [PATCH lttng-modules v3] Fix: atomic_add_unless() returns true/false rather than prior value
       [not found] ` <1488991131-9828-1-git-send-email-francis.deslauriers@efficios.com>
  2017-03-08 16:43   ` Mathieu Desnoyers
@ 2017-03-08 16:50   ` Francis Deslauriers
       [not found]   ` <1488991838-13807-1-git-send-email-francis.deslauriers@efficios.com>
  2 siblings, 0 replies; 5+ messages in thread
From: Francis Deslauriers @ 2017-03-08 16:50 UTC (permalink / raw)
  To: lttng-dev

The previous implementation assumed that `atomic_add_unless` returned
the prior value of the atomic counter when in fact it returned if the
addition was performed (true) or not performed (false).
Since `atomic_add_unless` can not return INT_MAX, the `lttng_kref_get`
always returned that the call was successful.

This issue had a low likelihood of being triggered since the two refcounts
of the counters used with this call are both bounded by the maximum
number of file descriptors on the system.

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
---
 wrapper/kref.h | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/wrapper/kref.h b/wrapper/kref.h
index eedefbf..f30a9ae 100644
--- a/wrapper/kref.h
+++ b/wrapper/kref.h
@@ -36,11 +36,7 @@
  */
 static inline int lttng_kref_get(struct kref *kref)
 {
-	if (atomic_add_unless(&kref->refcount, 1, INT_MAX) != INT_MAX) {
-		return 1;
-	} else {
-		return 0;
-	}
+	return atomic_add_unless(&kref->refcount, 1, INT_MAX);
 }
 
 #endif /* _LTTNG_WRAPPER_KREF_H */
-- 
2.7.4

_______________________________________________
lttng-dev mailing list
lttng-dev@lists.lttng.org
https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev

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

* Re: [PATCH lttng-modules v3] Fix: atomic_add_unless() returns true/false rather than prior value
       [not found]   ` <1488991838-13807-1-git-send-email-francis.deslauriers@efficios.com>
@ 2017-03-08 16:56     ` Mathieu Desnoyers
  0 siblings, 0 replies; 5+ messages in thread
From: Mathieu Desnoyers @ 2017-03-08 16:56 UTC (permalink / raw)
  To: Francis Deslauriers; +Cc: lttng-dev

merged into master, 2.9, 2.8, thanks!

Mathieu

----- On Mar 8, 2017, at 11:50 AM, Francis Deslauriers francis.deslauriers@efficios.com wrote:

> The previous implementation assumed that `atomic_add_unless` returned
> the prior value of the atomic counter when in fact it returned if the
> addition was performed (true) or not performed (false).
> Since `atomic_add_unless` can not return INT_MAX, the `lttng_kref_get`
> always returned that the call was successful.
> 
> This issue had a low likelihood of being triggered since the two refcounts
> of the counters used with this call are both bounded by the maximum
> number of file descriptors on the system.
> 
> Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
> ---
> wrapper/kref.h | 6 +-----
> 1 file changed, 1 insertion(+), 5 deletions(-)
> 
> diff --git a/wrapper/kref.h b/wrapper/kref.h
> index eedefbf..f30a9ae 100644
> --- a/wrapper/kref.h
> +++ b/wrapper/kref.h
> @@ -36,11 +36,7 @@
>  */
> static inline int lttng_kref_get(struct kref *kref)
> {
> -	if (atomic_add_unless(&kref->refcount, 1, INT_MAX) != INT_MAX) {
> -		return 1;
> -	} else {
> -		return 0;
> -	}
> +	return atomic_add_unless(&kref->refcount, 1, INT_MAX);
> }
> 
> #endif /* _LTTNG_WRAPPER_KREF_H */
> --
> 2.7.4

-- 
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com
_______________________________________________
lttng-dev mailing list
lttng-dev@lists.lttng.org
https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev

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

end of thread, other threads:[~2017-03-08 16:56 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <1488947760-25045-1-git-send-email-francis.deslauriers@efficios.com>
2017-03-08 12:09 ` [PATCH lttng-modules] Fix: atomic_add_unless() already returns zero on overflow Mathieu Desnoyers
2017-03-08 16:38 ` [PATCH lttng-modules] Fix: atomic_add_unless() returns true/false rather than prior value Francis Deslauriers
     [not found] ` <1488991131-9828-1-git-send-email-francis.deslauriers@efficios.com>
2017-03-08 16:43   ` Mathieu Desnoyers
2017-03-08 16:50   ` [PATCH lttng-modules v3] " Francis Deslauriers
     [not found]   ` <1488991838-13807-1-git-send-email-francis.deslauriers@efficios.com>
2017-03-08 16:56     ` Mathieu Desnoyers

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.