tipc: use a write lock for keepalive_intv instead of a read lock
Subsystems (3)
PATCH 1/1 tipc: use a write lock for keepalive_intv instead of a read lock
Currently, n->keepalive_intv is written to while n is locked by a read lock instead of a write lock. This seems to me to break the atomicity against other readers.
Change this to a write lock instead to solve the issue.
Note:
I am currently working on a static analyser to detect missing locks using type-based static analysis as my master's thesis
in order to obtain my master's degree.
If you would like to have more details, please let me know. This was a reported case. I manually verified the report by looking at the code, so that I do not send wrong information or patches. After concluding that this seems to be a true positive, I created this patch. I have both compile-tested this patch and runtime-tested this patch on x86_64. The effect on a running system could be a potential race condition in exceptional cases.
This issue was found on Linux v5.17.
--- net/tipc/node.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
net/tipc/node.c +2 -2
@@ -806,9 +806,9 @@ static void tipc_node_timeout(struct timer_list *t)/* Initial node interval to value larger (10 seconds), then it will be * recalculated with link lowest tolerance */ -tipc_node_read_lock (n); +tipc_node_write_lock (n); n->keepalive_intv =10000 ; -tipc_node_read_unlock (n); +tipc_node_write_unlock (n);for (bearer_id =0 ; remains && (bearer_id <MAX_BEARERS ); bearer_id++) {tipc_node_read_lock (n); le = &n->links[bearer_id];
Signature · 1 line
2.35.1
Hi Niels,
I did consider this function however I guess it is safe to use tipc_node_read_lock()/unlock() since this value is being apply in this callback function.
BTW, you must be using tipc_node_write_unlock_fast() instead of tipc_node_write_unlock(). Regards,
Hoang
Quoted 51 lines
-----Original Message-----
From: Niels Dossche <[email protected]>
Sent: Tuesday, March 29, 2022 11:12 PM
To: [email protected]
Cc: [email protected]; Jon Maloy <[email protected]>; Ying Xue <[email protected]>; David S. Miller <[email protected]>; Jakub Kicinski <[email protected]>; Paolo Abeni <[email protected]>; Hoang Huu Le <[email protected]>; Niels Dossche <[email protected]>
Subject: [PATCH net] tipc: use a write lock forkeepalive_intvinstead of a read lockCurrently,
n->keepalive_intvis written to while n is locked by a read lock instead of a write lock. This seems to me to break the atomicity against other readers.
Change this to a write lock instead to solve the issue.Note:
I am currently working on a static analyser to detect missing locks using type-based static analysis as my master's thesis
in order to obtain my master's degree.
If you would like to have more details, please let me know. This was a reported case. I manually verified the report by looking at the code, so that I do not send wrong information or patches. After concluding that this seems to be a true positive, I created this patch. I have both compile-tested this patch and runtime-tested this patch onx86_64. The effect on a running system could be a potential race condition in exceptional cases.
This issue was found on Linux v5.17.Fixes f5d6c3e5a359 ("tipc: fix node keep alive interval calculation")Signed-off-by Niels Dossche <[email protected]>--- net/tipc/node.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)net/tipc/node.c +2
-3@@ -806,9 +806,9 @@ static void tipc_node_timeout(struct timer_list *t)/* Initial node interval to value larger (10 seconds), then it will be * recalculated with link lowest tolerance */ -tipc_node_read_lock (n); +tipc_node_write_lock (n); n->keepalive_intv =10000 ; -tipc_node_read_unlock (n); +tipc_node_write_unlock (n);for (bearer_id =0 ; remains && (bearer_id <MAX_BEARERS ); bearer_id++) {tipc_node_read_lock (n); le = &n->links[bearer_id]; --2.35.1
Jakub Kicinski
maintainerQuoted 18 lines · On Tue, 29 Mar 2022 18:12:14 +0200 Niels Dossche wrote:
Currently,
n->keepalive_intvis written to while n is locked by a read lock instead of a write lock. This seems to me to break the atomicity against other readers.
Change this to a write lock instead to solve the issue.Note:
I am currently working on a static analyser to detect missing locks using type-based static analysis as my master's thesis
in order to obtain my master's degree.
If you would like to have more details, please let me know. This was a reported case. I manually verified the report by looking at the code, so that I do not send wrong information or patches. After concluding that this seems to be a true positive, I created this patch. I have both compile-tested this patch and runtime-tested this patch onx86_64. The effect on a running system could be a potential race condition in exceptional cases.
This issue was found on Linux v5.17.
Quoted 2 lines
Fixes f5d6c3e5a359 ("tipc: fix node keep alive interval calculation")Signed-off-by Niels Dossche <[email protected]>
Looks good, Jon?
Paolo Abeni
maintainerQuoted 29 lines · Niels Dossche
Currently,
n->keepalive_intvis written to while n is locked by a read lock instead of a write lock. This seems to me to break the atomicity against other readers.
Change this to a write lock instead to solve the issue.Note:
I am currently working on a static analyser to detect missing locks using type-based static analysis as my master's thesis
in order to obtain my master's degree.
If you would like to have more details, please let me know. This was a reported case. I manually verified the report by looking at the code, so that I do not send wrong information or patches. After concluding that this seems to be a true positive, I created this patch. I have both compile-tested this patch and runtime-tested this patch onx86_64. The effect on a running system could be a potential race condition in exceptional cases.
This issue was found on Linux v5.17.Fixes f5d6c3e5a359 ("tipc: fix node keep alive interval calculation")Signed-off-by Niels Dossche <[email protected]>--- net/tipc/node.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)net/tipc/node.c +0
-0
net/tipc/node.c static void tipc_node_timeout(struct timer_list *t) · line 809
Quoted 5 lines
net/tipc/node.c +1
-1@@ -806,9 +806,9 @@ static void tipc_node_timeout(struct timer_list *t)/* Initial node interval to value larger (10 seconds), then it will be * recalculated with link lowest tolerance */ -tipc_node_read_lock (n); +tipc_node_write_lock (n);
I agree with Hoang, this should be safe even without write lock, as tipc_node_timeout() is the only function modifying keepalive_intv, and such function is invoked only by a timer, so we are guaranteeded there are no possible concurrent updates...
net/tipc/node.c static void tipc_node_timeout(struct timer_list *t) · line 813
Quoted 5 lines
net/tipc/node.c +1
-1n->keepalive_intv =10000 ; -tipc_node_read_unlock (n); +tipc_node_write_unlock (n);for (bearer_id =0 ; remains && (bearer_id <MAX_BEARERS ); bearer_id++) {tipc_node_read_lock (n);
...otherwise we have a similar issue here: a few line below keepalive_intv is updated via tipc_node_calculate_timer(), still under the read lock
Thanks!
Paolo
Jon Maloy
maintainerQuoted 49 lines · Paolo Abeni
Quoted 29 lines · Niels Dossche
Currently,
n->keepalive_intvis written to while n is locked by a read lock instead of a write lock. This seems to me to break the atomicity against other readers.
Change this to a write lock instead to solve the issue.Note:
I am currently working on a static analyser to detect missing locks using type-based static analysis as my master's thesis
in order to obtain my master's degree.
If you would like to have more details, please let me know. This was a reported case. I manually verified the report by looking at the code, so that I do not send wrong information or patches. After concluding that this seems to be a true positive, I created this patch. I have both compile-tested this patch and runtime-tested this patch onx86_64. The effect on a running system could be a potential race condition in exceptional cases.
This issue was found on Linux v5.17.Fixes f5d6c3e5a359 ("tipc: fix node keep alive interval calculation")Signed-off-by Niels Dossche <[email protected]>--- net/tipc/node.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)net/tipc/node.c +0
-0net/tipc/node.c static void tipc_node_timeout(struct timer_list *t) · line 809
Quoted 5 lines
net/tipc/node.c +1
-1@@ -806,9 +806,9 @@ static void tipc_node_timeout(struct timer_list *t)/* Initial node interval to value larger (10 seconds), then it will be * recalculated with link lowest tolerance */ -tipc_node_read_lock (n); +tipc_node_write_lock (n);I agree with Hoang, this should be safe even without write lock, as
tipc_node_timeout()is the only function modifyingkeepalive_intv, and such function is invoked only by a timer, so we are guaranteeded there are no possible concurrent updates...net/tipc/node.c static void tipc_node_timeout(struct timer_list *t) · line 813
Quoted 5 lines
net/tipc/node.c +1
-1n->keepalive_intv =10000 ; -tipc_node_read_unlock (n); +tipc_node_write_unlock (n);for (bearer_id =0 ; remains && (bearer_id <MAX_BEARERS ); bearer_id++) {tipc_node_read_lock (n);...otherwise we have a similar issue here: a few line below
keepalive_intvis updated viatipc_node_calculate_timer(), still under the read lock
Quoted 4 lines
Thanks!
Paolo
Hoang's and Paolo's conclusion is correct.
The patch is not needed.
///jon
Quoted 4 lines · Jon Maloy
Hoang's and Paolo's conclusion is correct.
The patch is not needed.
///jon
Thank you everyone for commenting on this.
Kind regards
Niels