The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: David Howells <dhowells@redhat.com>
To: linux-afs@lists.infradead.org
Cc: dhowells@redhat.com, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: [PATCH 09/13] rxrpc: Use ACCESS_ONCE() when accessing circular buffer pointers
Date: Fri, 04 Mar 2016 16:38:08 +0000	[thread overview]
Message-ID: <20160304163808.31057.35519.stgit@warthog.procyon.org.uk> (raw)
In-Reply-To: <20160304163705.31057.60831.stgit@warthog.procyon.org.uk>

Use ACCESS_ONCE() when accessing the other-end pointer into a circular
buffer as it's possible the other-end pointer might change whilst we're
doing this, and if we access it twice, we might get some weird things
happening.

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

 net/rxrpc/ar-output.c |   11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/net/rxrpc/ar-output.c b/net/rxrpc/ar-output.c
index 353f5c9141ea..14c8df6b7f41 100644
--- a/net/rxrpc/ar-output.c
+++ b/net/rxrpc/ar-output.c
@@ -401,7 +401,8 @@ static int rxrpc_wait_for_tx_window(struct rxrpc_sock *rx,
 	int ret;
 
 	_enter(",{%d},%ld",
-	       CIRC_SPACE(call->acks_head, call->acks_tail, call->acks_winsz),
+	       CIRC_SPACE(call->acks_head, ACCESS_ONCE(call->acks_tail),
+			  call->acks_winsz),
 	       *timeo);
 
 	add_wait_queue(&call->tx_waitq, &myself);
@@ -409,7 +410,7 @@ static int rxrpc_wait_for_tx_window(struct rxrpc_sock *rx,
 	for (;;) {
 		set_current_state(TASK_INTERRUPTIBLE);
 		ret = 0;
-		if (CIRC_SPACE(call->acks_head, call->acks_tail,
+		if (CIRC_SPACE(call->acks_head, ACCESS_ONCE(call->acks_tail),
 			       call->acks_winsz) > 0)
 			break;
 		if (signal_pending(current)) {
@@ -570,7 +571,8 @@ static int rxrpc_send_data(struct rxrpc_sock *rx,
 
 			_debug("alloc");
 
-			if (CIRC_SPACE(call->acks_head, call->acks_tail,
+			if (CIRC_SPACE(call->acks_head,
+				       ACCESS_ONCE(call->acks_tail),
 				       call->acks_winsz) <= 0) {
 				ret = -EAGAIN;
 				if (msg->msg_flags & MSG_DONTWAIT)
@@ -686,7 +688,8 @@ static int rxrpc_send_data(struct rxrpc_sock *rx,
 			sp->hdr.flags = conn->out_clientflag;
 			if (msg_data_left(msg) == 0 && !more)
 				sp->hdr.flags |= RXRPC_LAST_PACKET;
-			else if (CIRC_SPACE(call->acks_head, call->acks_tail,
+			else if (CIRC_SPACE(call->acks_head,
+					    ACCESS_ONCE(call->acks_tail),
 					    call->acks_winsz) > 1)
 				sp->hdr.flags |= RXRPC_MORE_PACKETS;
 			if (more && seq & 1)

  parent reply	other threads:[~2016-03-04 16:38 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-04 16:37 [PATCH 00/13] RxRPC: Rewrite part 1 David Howells
2016-03-04 16:37 ` [PATCH 01/13] rxrpc: Fix a case where a call event bit is being used as a flag bit David Howells
2016-03-04 16:37 ` [PATCH 02/13] rxrpc: Convert call flag and event numbers into enums David Howells
2016-03-04 16:37 ` [PATCH 03/13] rxrpc: Rename call events to begin RXRPC_CALL_EV_ David Howells
2016-03-04 16:37 ` [PATCH 04/13] rxrpc: Keep the skb private record of the Rx header in host byte order David Howells
2016-03-04 16:37 ` [PATCH 05/13] rxrpc: The protocol family should be set to PF_RXRPC not PF_UNIX David Howells
2016-03-04 16:37 ` [PATCH 06/13] rxrpc: Fix defined range for /proc/sys/net/rxrpc/rx_mtu David Howells
2016-03-04 16:37 ` [PATCH 07/13] rxrpc: Be more selective about the types of received packets we accept David Howells
2016-03-04 16:38 ` [PATCH 08/13] rxrpc: Adjust some whitespace and comments David Howells
2016-03-04 16:38 ` David Howells [this message]
2016-03-04 16:38 ` [PATCH 10/13] rxrpc: rxkad: The version number in the response should be net byte order David Howells
2016-03-04 16:38 ` [PATCH 11/13] rxrpc: rxkad: Casts are needed when comparing be32 values David Howells
2016-03-04 16:38 ` [PATCH 12/13] rxrpc: Clear the unused part of a sockaddr_rxrpc for memcmp() use David Howells
2016-03-04 16:38 ` [PATCH 13/13] rxrpc: Don't try to map ICMP to error as the lower layer already did that David Howells
2016-03-04 22:20 ` [PATCH 00/13] RxRPC: Rewrite part 1 David Miller
2016-03-04 22:33   ` David Howells
2016-03-04 23:27     ` David Miller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160304163808.31057.35519.stgit@warthog.procyon.org.uk \
    --to=dhowells@redhat.com \
    --cc=linux-afs@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox