1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
From: John Ogness <john.ogness@linutronix.de>
Date: Fri, 22 Feb 2019 23:02:44 +0100
Subject: [PATCH] printk: devkmsg: llseek: reset clear if it is lost
Origin: https://www.kernel.org/pub/linux/kernel/projects/rt/5.0/older/patches-5.0.10-rt7.tar.xz
SEEK_DATA will seek to the last clear record. If this clear record
is no longer in the ring buffer, devkmsg_llseek() will go into an
infinite loop. Fix that by resetting the clear sequence if the old
clear record is no longer in the ring buffer.
Signed-off-by: John Ogness <john.ogness@linutronix.de>
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
---
kernel/printk/printk.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -725,6 +725,7 @@ static loff_t devkmsg_llseek(struct file
{
struct devkmsg_user *user = file->private_data;
loff_t ret;
+ u64 seq;
if (!user)
return -EBADF;
@@ -747,7 +748,7 @@ static loff_t devkmsg_llseek(struct file
* changes no global state, and does not clear anything.
*/
for (;;) {
- prb_iter_init(&user->iter, &printk_rb, NULL);
+ prb_iter_init(&user->iter, &printk_rb, &seq);
ret = prb_iter_seek(&user->iter, clear_seq);
if (ret > 0) {
/* seeked to clear seq */
@@ -764,6 +765,10 @@ static loff_t devkmsg_llseek(struct file
break;
}
/* iterator invalid, start over */
+
+ /* reset clear_seq if it is no longer available */
+ if (seq > clear_seq)
+ clear_seq = 0;
}
ret = 0;
break;
|