Bug 206283 - seq_file .next functions should increase position index
Summary: seq_file .next functions should increase position index
Status: NEW
Alias: None
Product: File System
Classification: Unclassified
Component: Other (show other bugs)
Hardware: All Linux
: P1 normal
Assignee: fs_other
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-01-22 16:20 UTC by Vasily Averin
Modified: 2020-06-11 01:00 UTC (History)
3 users (show)

See Also:
Kernel Version: 5.5-rc6
Subsystem:
Regression: No
Bisected commit-id:


Attachments

Description Vasily Averin 2020-01-22 16:20:31 UTC
In Aug 2018 NeilBrown submitted to mainline commit 1f4aace60b0e ("fs/seq_file.c: simplify seq_file iteration code and interface") with following comment

>"Some ->next functions do not increment *pos when they return NULL...
>Note that such ->next functions are buggy and should be fixed. 
>A simple demonstration is
>dd if=/proc/swaps bs=1000 skip=1
>Choose any block size larger than the size of /proc/swaps.  This will
>always show the whole last line of /proc/swaps"

Described problem is still actual. If you make lseek into middle of last output line following read will output end of last line and whole last line once again.

>$ dd if=/proc/swaps bs=1  # usual output
>Filename                               Type            Size    Used   
>Priority
>/dev/dm-0                               partition      4194812 97536   -2
>104+0 records in
>104+0 records out
>104 bytes copied
>
>$ dd if=/proc/swaps bs=40 skip=1    # last line was generated twice
>dd: /proc/swaps: cannot skip to specified offset
>v/dm-0                               partition 4194812 97536   -2
>/dev/dm-0                               partition      4194812 97536   -2 
>3+1 records in
>3+1 records out
>131 bytes copied

There are lot of other affected files, I've found 30+ including
/proc/net/ip_tables_matches and /proc/sysvipc/* 
I prepared patches and submitted this bug to simplify their processing.
Comment 1 Vasily Averin 2020-01-23 07:12:43 UTC
submitted to netdev@vger.kernel.org
 seq_tab_next() should increase position index
 l2t_seq_next should increase position index
 vcc_seq_next should increase position index
 neigh_stat_seq_next() should increase position index
 rt_cpu_seq_next should increase position index
 ipv6_route_seq_next should increase position index
Comment 2 Vasily Averin 2020-01-23 07:26:22 UTC
sent to netfilter-devel@vger.kernel.org
 ct_cpu_seq_next should increase position index
 synproxy_cpu_seq_next should increase position index
 recent_seq_next should increase position index
 xt_mttg_seq_next should increase position index
Comment 3 Vasily Averin 2020-01-23 07:40:45 UTC
sent to ocfs2-devel@oss.oracle.com
 lockres_seq_next should increase position index
 ocfs2_dlm_seq_next should increase position index
 nst_seq_next should increase position index
 sc_seq_next should increase position index
Comment 4 Vasily Averin 2020-01-23 07:49:21 UTC
sent to linux-integrity@vger.kernel.org
 tpm1_bios_measurements_next should increase position index
 tpm2_bios_measurements_next() should increase position index
Comment 5 Vasily Averin 2020-01-23 09:05:51 UTC
sent to linux-ext4@vger.kernel.org
 jbd2_seq_info_next should increase position index
Comment 6 Vasily Averin 2020-01-23 15:28:33 UTC
sent to qat-linux@intel.com 
 adf_ring_next should increase position index
Comment 7 Vasily Averin 2020-01-24 05:49:23 UTC
linux-s390@vger.kernel.org
 cio_ignore_proc_seq_next should increase position index
Comment 8 Vasily Averin 2020-01-24 05:56:50 UTC
sent to linux-scsi@vger.kernel.org
 snic_trc_seq_next should increase position index
Comment 9 Vasily Averin 2020-01-24 06:04:00 UTC
sent to cluster-devel@redhat.com
 table_seq_next should increase position index
Comment 10 Vasily Averin 2020-01-24 06:11:20 UTC
sent to devel@lists.orangefs.org
 help_next should increase position index
Comment 11 Vasily Averin 2020-01-24 06:18:20 UTC
sent to bpf@vger.kernel.org
 map_seq_next should increase position index
Comment 12 Vasily Averin 2020-01-24 06:26:15 UTC
sent to linux-security-module@vger.kernel.org
 proc_keys_next should increase position index
Comment 13 Vasily Averin 2020-01-24 06:33:01 UTC
sent to selinux@vger.kernel.org
 sel_avc_get_stat_idx should increase position index
Comment 14 Vasily Averin 2020-01-24 06:41:51 UTC
sent to linux-mm@kvack.org
 swap_next should increase position index
Comment 15 Vasily Averin 2020-01-24 07:03:50 UTC
sent directly to lkml@
 pstore_ftrace_seq_next should increase position index
 gcov_seq_next should increase position index
 t_next should increase position index
 fpid_next should increase position index
 eval_map_next should increase position index
 trigger_next should increase position index
 sysvipc_find_ipc should increase position index
Comment 16 Vasily Averin 2020-01-24 07:49:10 UTC
sent to lkml@ -- it helps to detect buggy .next function in missed cases and in out-of-tree modules
[PATCH] seq_read: info message about buggy .next functions
Comment 17 Vasily Averin 2020-01-24 08:12:55 UTC
last known affected function: cgroup_procs_next
Comment 18 Vasily Averin 2020-01-26 10:48:16 UTC
sent to cgroups@
  cgroup_pidlist_next should update position index
  cgroup_procs_next should increase position index
Comment 19 Matt Turner 2020-06-09 23:59:32 UTC
I see

> buggy seq_file .next function c_next did not updated position index

on an Alpha running v5.7.0. How can I determine what function is at fault?
Comment 20 Vasily Averin 2020-06-10 04:05:17 UTC
(In reply to Matt Turner from comment #19)
> I see
> 
> > buggy seq_file .next function c_next did not updated position index
> 
> on an Alpha running v5.7.0. How can I determine what function is at fault?

It's about 
arch/alpha/kernel/setup.c::c_next()
Comment 21 Matt Turner 2020-06-11 01:00:31 UTC
Thanks. I've sent

[PATCH] alpha: c_next should increase position index

to linux-alpha@

Note You need to log in before you can comment on or make changes to this bug.