Skip to contentSkip to conversation

printk: Fix skipped entries after index iterator restart

PATCH In review Avi Weiss 2 participants 2 messages Nov 16

Subsystems (2)
lore
Share & tools
lore

Avi Weiss

author
#0 lore raw

PATCH 1/1 printk: Fix skipped entries after index iterator restart

seq_read_iter() can advance the iterator before the next record fits in the read buffer. When iteration resumes, pi_start() calls pi_next() at the saved position and advances past the pending printk index entry. As a result, index reads can silently omit formats.

Return the entry corresponding to the saved position without advancing the iterator.

Fixes 337015573718 ("printk: Userspace format indexing support")
---
 kernel/printk/index.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/printk/index.c +1 -1
index a6b27526baaf6..642640a36abe1 100644
@@ -59,7 +59,7 @@ static void *pi_start(struct seq_file *s, loff_t *pos)
 	if (*pos == 0)
 		return SEQ_START_TOKEN;
 
-	return pi_next(s, NULL, pos);
+	return pi_get_entry(s->file->f_inode->i_private, *pos - 1);
 }
 
 /*

base-commit: 97d73c8251226cf27cc6656b4c542869bb8c69fa

Signature · 1 line
2.43.0
#1 lore raw
Quoted 7 lines · Avi Weiss

seq_read_iter() can advance the iterator before the next record fits in the read buffer. When iteration resumes, pi_start() calls pi_next() at the saved position and advances past the pending printk index entry. As a result, index reads can silently omit formats.

Return the entry corresponding to the saved position without advancing the iterator.

...

kernel/printk/index.c static void *pi_start(struct seq_file *s, loff_t *pos) · line 62

Quoted 2 lines
kernel/printk/index.c +1 -1
-	return pi_next(s, NULL, pos);
+	return pi_get_entry(s->file->f_inode->i_private, *pos - 1);

Side note (because it seems used more in the same form), we have file_inode() helper and this should idiomatically look as

	return pi_get_entry(file_inode(s->file)->i_private, *pos - 1);

But I haven't checked if the file_inode() is recommended or deprecated API.

Signature · 2 lines
With Best Regards,
Andy Shevchenko