On Sun, Jan 2, 2022 at 11:04 PM Jann Horn <jannh@xxxxxxxxxx> wrote: > > And for this validation caching to work properly, AFAIU you need to > hold the file->f_pos_lock (or have exclusive access to the "struct > file"), which happens in the normal getdents() path via fdget_pos(). > This guarantees that the readdir handler has exclusive access to the > file's ->f_version, which has to stay in sync with the position. Yes. So the whole 'preaddir()' model was wrong, and thanks to Al for noticing. It turns out that you cannot pass in a different 'pos' than f_pos, because we have that very tight coupling between the 'struct file' and readdir(). It's not just about f_pos and f_version, either - Al pointed out the virtual filesystems, which use a special dentry cursor to traverse the child dentries for readdir, and that one uses 'file->private_data'. So the directory position isn't really about some simple passed-in pos, it has locking rules, it has validation, and it has actual secondary data in the file pointer. Linus