All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Add a read memory barrier to wait_on_buffer
@ 2022-07-31 11:43 Mikulas Patocka
  2022-07-31 12:00 ` Ard Biesheuvel
  0 siblings, 1 reply; 47+ messages in thread
From: Mikulas Patocka @ 2022-07-31 11:43 UTC (permalink / raw)
  To: Linus Torvalds, Alexander Viro
  Cc: Alan Stern, Andrea Parri, Will Deacon, Peter Zijlstra,
	Boqun Feng, Nicholas Piggin, David Howells, Jade Alglave,
	Luc Maranget, Paul E. McKenney, Akira Yokosawa, Daniel Lustig,
	Joel Fernandes, linux-kernel, linux-arch, linux-fsdevel

Let's have a look at this piece of code in __bread_slow:
	get_bh(bh);
	bh->b_end_io = end_buffer_read_sync;
	submit_bh(REQ_OP_READ, 0, bh);
	wait_on_buffer(bh);
	if (buffer_uptodate(bh))
		return bh;
Neither wait_on_buffer nor buffer_uptodate contain a memory barrier.
Consequently, if someone calls sb_bread and then reads the buffer data,
the read of buffer data may be speculatively executed before
wait_on_buffer(bh) and it may return invalid data.

Also, there is this pattern present several times:
	wait_on_buffer(bh);
	if (!buffer_uptodate(bh))
		err = -EIO;
It may be possible that buffer_uptodate is executed before wait_on_buffer
and it may return spurious error.

Fix these bugs by adding a read memory barrier to wait_on_buffer().

Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Cc: stable@vger.kernel.org

Index: linux-2.6/include/linux/buffer_head.h
===================================================================
--- linux-2.6.orig/include/linux/buffer_head.h
+++ linux-2.6/include/linux/buffer_head.h
@@ -353,6 +353,11 @@ static inline void wait_on_buffer(struct
 	might_sleep();
 	if (buffer_locked(bh))
 		__wait_on_buffer(bh);
+	/*
+	 * Make sure that the following accesses to buffer state or buffer data
+	 * are not reordered with buffer_locked(bh).
+	 */
+	smp_rmb();
 }
 
 static inline int trylock_buffer(struct buffer_head *bh)


^ permalink raw reply	[flat|nested] 47+ messages in thread

end of thread, other threads:[~2022-08-09 22:14 UTC | newest]

Thread overview: 47+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-31 11:43 [PATCH] Add a read memory barrier to wait_on_buffer Mikulas Patocka
2022-07-31 12:00 ` Ard Biesheuvel
2022-07-31 13:41   ` Mikulas Patocka
2022-07-31 15:08     ` [PATCH v2] make buffer_locked provide an acquire semantics Mikulas Patocka
2022-07-31 16:51       ` Linus Torvalds
2022-07-31 17:30         ` Paul E. McKenney
2022-07-31 22:48           ` Matthew Wilcox
2022-08-01  3:20             ` Paul E. McKenney
2022-08-01 15:41           ` Will Deacon
2022-08-01 19:20             ` Paul E. McKenney
2022-08-02  8:54               ` Will Deacon
2022-08-02 13:49                 ` Paul E. McKenney
2022-08-02 15:29                   ` Paul E. McKenney
2022-07-31 20:39         ` Mikulas Patocka
2022-07-31 20:40           ` [PATCH v3 1/2] wait_bit: do read barrier after testing a bit Mikulas Patocka
2022-07-31 20:57             ` Linus Torvalds
2022-08-01 10:40               ` Mikulas Patocka
2022-08-01 10:43                 ` [PATCH v4 2/2] change buffer_locked, so that it has acquire semantics Mikulas Patocka
2022-08-01 14:37                   ` Matthew Wilcox
2022-08-01 15:01                     ` Mikulas Patocka
2022-08-05  3:22                       ` Matthew Wilcox
2022-08-07 11:37                         ` [PATCH v5] add barriers to buffer functions Mikulas Patocka
2022-08-07 14:50                           ` Matthew Wilcox
2022-08-08 14:26                             ` Mikulas Patocka
2022-08-08 14:40                               ` Matthew Wilcox
2022-08-08 14:57                                 ` Mikulas Patocka
2022-08-08 15:31                                   ` Paul E. McKenney
2022-08-08 15:39                                   ` Matthew Wilcox
2022-08-09 18:32                                     ` [PATCH v6] add barriers to buffer_uptodate and set_buffer_uptodate Mikulas Patocka
2022-08-09 19:44                                       ` Matthew Wilcox
2022-08-09 22:06                                       ` Linus Torvalds
2022-08-01 10:42               ` [PATCH v4 1/2] introduce test_bit_acquire and use it in wait_on_bit Mikulas Patocka
2022-08-01 15:54                 ` Will Deacon
2022-08-01 16:12                   ` Mikulas Patocka
2022-08-01 18:17                     ` Boqun Feng
2022-08-02  8:00                       ` David Laight
2022-08-02  8:40                     ` Will Deacon
2022-08-02 11:38                       ` Mikulas Patocka
2022-08-02 13:36                         ` Will Deacon
2022-08-02 15:57                           ` Mikulas Patocka
2022-08-01  0:27             ` [PATCH v3 1/2] wait_bit: do read barrier after testing a bit Alan Stern
2022-07-31 20:43           ` [PATCH v3 2/2] make buffer_locked provide an acquire semantics Mikulas Patocka
2022-07-31 20:51             ` Linus Torvalds
2022-07-31 22:14             ` Matthew Wilcox
2022-07-31 22:31               ` Ard Biesheuvel
2022-07-31 22:48                 ` Ard Biesheuvel
2022-07-31 20:46           ` [PATCH v2] " Linus Torvalds

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.