Patch "ptr_ring: add barriers" has been added to the 4.14-stable tree
This is a note to let you know that I've just added the patch titled
ptr_ring: add barriers
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:
ptr_ring-add-barriers.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 Sun Dec 31 11:12:48 CET 2017
From: "Michael S. Tsirkin" <[email protected]>
Date: Tue, 5 Dec 2017 21:29:37 +0200
Subject: ptr_ring: add barriers
From: "Michael S. Tsirkin" <[email protected]>
[ Upstream commit a8ceb5dbfde1092b466936bca0ff3be127ecf38e ]
Users of ptr_ring expect that it's safe to give the data structure a pointer and have it be available to consumers, but that actually requires an smb_wmb or a stronger barrier.
In absence of such barriers and on architectures that reorder writes, consumer might read an un=initialized value from an skb pointer stored in the skb array. This was observed causing crashes.
To fix, add memory barriers. The barrier we use is a wmb, the assumption being that producers do not need to read the value so we do not need to order these reads.
--- include/linux/ptr_ring.h | 9 +++++++++ 1 file changed, 9 insertions(+)
include/linux/ptr_ring.h +9 -0
@@ -101,12 +101,18 @@ static inline bool ptr_ring_full_bh(stru/* Note: callers invoking this in a loop must use a compiler barrier, * for example cpu_relax(). Callers must hold producer_lock. +* Callers are responsible for making sure pointer that is being queued +* points to a valid data. */ static inline int __ptr_ring_produce (struct ptr_ring *r,void *ptr) {if (unlikely (!r->size) || r->queue[r->producer])return -ENOSPC ; +/* Make sure the pointer we are storing points to a valid data. */ +/* Pairs with smp_read_barrier_depends in __ptr_ring_consume. */ +smp_wmb (); + r->queue[r->producer++] = ptr;if (unlikely (r->producer >= r->size)) r->producer =0 ;
@@ -275,6 +281,9 @@ static inline void *__ptr_ring_consume(sif (ptr)__ptr_ring_discard_one (r); +/* Make sure anyone accessing data through the pointer is up to date. */ +/* Pairs with smp_wmb in __ptr_ring_produce. */ +smp_read_barrier_depends ();return ptr; }
Patches currently in stable-queue which might be from [email protected] are
queue-4.14/ptr_ring-add-barriers.patch