Skip to contentSkip to conversation

Patch "bpf: sockmap missing NULL psock check" has been added to the 4.14-stable tree

PATCH [email protected] 1 participant 1 message Feb 28, 2018

Subsystems (2)
lore
Share & tools
lore

[email protected]

author maintainer Applied
#0 lore raw

This is a note to let you know that I've just added the patch titled

bpf: sockmap missing NULL psock check

to the 4.14-stable tree which can be found at:
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
bpf-sockmap-missing-null-psock-check.patch
and it can be found in the queue-4.14 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree, please let <[email protected]> know about it.

Quoted 1 line

From foo@baz Wed Feb 28 16:23:28 CET 2018

From: John Fastabend <[email protected]>
Date: Thu, 4 Jan 2018 20:02:09 -0800
Subject: bpf: sockmap missing NULL psock check

From: John Fastabend <[email protected]>

[ Upstream commit 5731a879d03bdaa00265f8ebc32dfd0e65d25276 ]

Add psock NULL check to handle a racing sock event that can get the sk_callback_lock before this case but after xchg happens causing the refcnt to hit zero and sock user data (psock) to be null and queued for garbage collection.

Also add a comment in the code because this is a bit subtle and not obvious in my opinion.

---
 kernel/bpf/sockmap.c |   11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
kernel/bpf/sockmap.c +9 -2
@@ -588,8 +588,15 @@ static void sock_map_free(struct bpf_map
 
 		write_lock_bh(&sock->sk_callback_lock);
 		psock = smap_psock_sk(sock);
-		smap_list_remove(psock, &stab->sock_map[i]);
-		smap_release_sock(psock, sock);
+		/* This check handles a racing sock event that can get the
+		 * sk_callback_lock before this case but after xchg happens
+		 * causing the refcnt to hit zero and sock user data (psock)
+		 * to be null and queued for garbage collection.
+		 */
+		if (likely(psock)) {
+			smap_list_remove(psock, &stab->sock_map[i]);
+			smap_release_sock(psock, sock);
+		}
 		write_unlock_bh(&sock->sk_callback_lock);
 	}
 	rcu_read_unlock();

Patches currently in stable-queue which might be from [email protected] are

queue-4.14/bpf-sockmap-missing-null-psock-check.patch