diff mbox series

[net] rxrpc: Call state should be read with READ_ONCE() under some circumstances

Message ID 161046715522.2450566.488819910256264150.stgit@warthog.procyon.org.uk
State New
Headers show
Series [net] rxrpc: Call state should be read with READ_ONCE() under some circumstances | expand

Commit Message

David Howells Jan. 12, 2021, 3:59 p.m. UTC
From: Baptiste Lepers <baptiste.lepers@gmail.com>

The call state may be changed at any time by the data-ready routine in
response to received packets, so if the call state is to be read and acted
upon several times in a function, READ_ONCE() must be used unless the call
state lock is held.

As it happens, we used READ_ONCE() to read the state a few lines above the
unmarked read in rxrpc_input_data(), so use that value rather than
re-reading it.

Signed-off-by: Baptiste Lepers <baptiste.lepers@gmail.com>
Signed-off-by: David Howells <dhowells@redhat.com>
---

 net/rxrpc/input.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Jakub Kicinski Jan. 13, 2021, 2:25 a.m. UTC | #1
On Tue, 12 Jan 2021 15:59:15 +0000 David Howells wrote:
> From: Baptiste Lepers <baptiste.lepers@gmail.com>

> 

> The call state may be changed at any time by the data-ready routine in

> response to received packets, so if the call state is to be read and acted

> upon several times in a function, READ_ONCE() must be used unless the call

> state lock is held.

> 

> As it happens, we used READ_ONCE() to read the state a few lines above the

> unmarked read in rxrpc_input_data(), so use that value rather than

> re-reading it.

> 

> Signed-off-by: Baptiste Lepers <baptiste.lepers@gmail.com>

> Signed-off-by: David Howells <dhowells@redhat.com>


Fixes: a158bdd3247b ("rxrpc: Fix call timeouts")

maybe?

> diff --git a/net/rxrpc/input.c b/net/rxrpc/input.c

> index 667c44aa5a63..dc201363f2c4 100644

> --- a/net/rxrpc/input.c

> +++ b/net/rxrpc/input.c

> @@ -430,7 +430,7 @@ static void rxrpc_input_data(struct rxrpc_call *call, struct sk_buff *skb)

>  		return;

>  	}

>  

> -	if (call->state == RXRPC_CALL_SERVER_RECV_REQUEST) {

> +	if (state == RXRPC_CALL_SERVER_RECV_REQUEST) {

>  		unsigned long timo = READ_ONCE(call->next_req_timo);

>  		unsigned long now, expect_req_by;

>  

> 

>
David Howells Jan. 13, 2021, 8:23 a.m. UTC | #2
Jakub Kicinski <kuba@kernel.org> wrote:

> On Tue, 12 Jan 2021 15:59:15 +0000 David Howells wrote:

> > From: Baptiste Lepers <baptiste.lepers@gmail.com>

> > 

> > The call state may be changed at any time by the data-ready routine in

> > response to received packets, so if the call state is to be read and acted

> > upon several times in a function, READ_ONCE() must be used unless the call

> > state lock is held.

> > 

> > As it happens, we used READ_ONCE() to read the state a few lines above the

> > unmarked read in rxrpc_input_data(), so use that value rather than

> > re-reading it.

> > 

> > Signed-off-by: Baptiste Lepers <baptiste.lepers@gmail.com>

> > Signed-off-by: David Howells <dhowells@redhat.com>

> 

> Fixes: a158bdd3247b ("rxrpc: Fix call timeouts")

> 

> maybe?


Ah, yes.  I missed there wasn't a Fixes line.  Can you add that one in, or do
I need to resubmit the patch?

David
Jakub Kicinski Jan. 13, 2021, 6:41 p.m. UTC | #3
On Wed, 13 Jan 2021 08:23:54 +0000 David Howells wrote:
> Jakub Kicinski <kuba@kernel.org> wrote:

> 

> > On Tue, 12 Jan 2021 15:59:15 +0000 David Howells wrote:  

> > > From: Baptiste Lepers <baptiste.lepers@gmail.com>

> > > 

> > > The call state may be changed at any time by the data-ready routine in

> > > response to received packets, so if the call state is to be read and acted

> > > upon several times in a function, READ_ONCE() must be used unless the call

> > > state lock is held.

> > > 

> > > As it happens, we used READ_ONCE() to read the state a few lines above the

> > > unmarked read in rxrpc_input_data(), so use that value rather than

> > > re-reading it.

> > > 

> > > Signed-off-by: Baptiste Lepers <baptiste.lepers@gmail.com>

> > > Signed-off-by: David Howells <dhowells@redhat.com>  

> > 

> > Fixes: a158bdd3247b ("rxrpc: Fix call timeouts")

> > 

> > maybe?  

> 

> Ah, yes.  I missed there wasn't a Fixes line.  Can you add that one in, or do

> I need to resubmit the patch?


Sure, added, just checking if you didn't leave it out on purpose.

Applied, thanks!
diff mbox series

Patch

diff --git a/net/rxrpc/input.c b/net/rxrpc/input.c
index 667c44aa5a63..dc201363f2c4 100644
--- a/net/rxrpc/input.c
+++ b/net/rxrpc/input.c
@@ -430,7 +430,7 @@  static void rxrpc_input_data(struct rxrpc_call *call, struct sk_buff *skb)
 		return;
 	}
 
-	if (call->state == RXRPC_CALL_SERVER_RECV_REQUEST) {
+	if (state == RXRPC_CALL_SERVER_RECV_REQUEST) {
 		unsigned long timo = READ_ONCE(call->next_req_timo);
 		unsigned long now, expect_req_by;