Skip to contentSkip to conversation

JFS readdir() issues in stable 3.2

DISCUSSION Richard Weinberger 2 participants 3 messages Mar 20, 2015 – Mar 21, 2015

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

Hi!

Mainline commit 44512449c0ab368889dd13ae0031fba74ee7e1d2
(jfs: fix readdir cookie incompatibility with NFSv4) does not work as expected on 3.2. Maybe on other stable kernels too.

UML stumbled over it:
https://bugzilla.kernel.org/show_bug.cgi?id=94741

If you run the attached readdir.c on a JFS on stable 3.2.51+ readdir() will not increment the directory offset nor return NULL, hence the caller will loop forever. It looks like if the current directory offset is > 0 and you run seekdir(telldir()) the next readdir() call will not increment it.

Dave, has your fix some unnamed dependencies which need backporting too?

Thanks,
//richard

#include <stdio.h>
#include <dirent.h>
#include <assert.h>

int main(int argc, char *argv[])

{
	DIR *dirp;
	struct dirent *dent;
	off_t dpos;

	if (argc < 2) {
		fprintf(stderr, "Usage: %s DIR\n", argv[0]);
		return 1;
	}

	dirp = opendir(argv[1]);
	assert(dirp);
	dpos = 0;

	for (;;) {
		seekdir(dirp, dpos);
		dent = readdir(dirp);
		if (!dent)
			break;
		assert(dpos != telldir(dirp));
		dpos = telldir(dirp);
	}

	return 0;
}
#1 lore raw
Quoted 6 lines · Richard Weinberger

Hi!

Mainline commit 44512449c0ab368889dd13ae0031fba74ee7e1d2
(jfs: fix readdir cookie incompatibility with NFSv4) does not work as expected on 3.2. Maybe on other stable kernels too.

Quoted 7 lines

UML stumbled over it:
https://bugzilla.kernel.org/show_bug.cgi?id=94741

If you run the attached readdir.c on a JFS on stable 3.2.51+ readdir() will not increment the directory offset nor return NULL, hence the caller will loop forever. It looks like if the current directory offset is > 0 and you run seekdir(telldir()) the next readdir() call will not increment it.

The backport failed to pass the proper position to filldir() for the . and .. entries. I've attached a proposed patch to the above bug.

Quoted 5 lines

Dave, has your fix some unnamed dependencies which need backporting too?

Thanks,
//richard

Thanks!
Shaggy

#2 lore raw

Am 21.03.2015 um 22:58 schrieb Dave Kleikamp:

Quoted 10 lines · Richard Weinberger
Quoted 9 lines

Hi!

Mainline commit 44512449c0ab368889dd13ae0031fba74ee7e1d2
(jfs: fix readdir cookie incompatibility with NFSv4) does not work as expected on 3.2. Maybe on other stable kernels too.

UML stumbled over it:
https://bugzilla.kernel.org/show_bug.cgi?id=94741

Quoted 7 lines
Quoted 4 lines

If you run the attached readdir.c on a JFS on stable 3.2.51+ readdir() will not increment the directory offset nor return NULL, hence the caller will loop forever. It looks like if the current directory offset is > 0 and you run seekdir(telldir()) the next readdir() call will not increment it.

The backport failed to pass the proper position to filldir() for the . and .. entries. I've attached a proposed patch to the above bug.

Thanks for sorting this out! :-)
//richard