Skip to contentSkip to conversation

smb: client: fix readdir returning wrong type with POSIX extensions

PATCH In review Philipp Kerling 2 participants 2 messages Jun 29, 2025

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

PATCH 1/1 smb: client: fix readdir returning wrong type with POSIX extensions

When SMB 3.1.1 POSIX Extensions are negotiated, userspace applications using readdir() or getdents() calls without stat() on each individual file (such as a simple "ls" or "find") would misidentify file types and exhibit strange behavior such as not descending into directories. The reason for this behavior is an oversight in the cifs_posix_to_fattr conversion function. Instead of extracting the entry type for cf_dtype from the properly converted cf_mode field, it tries to extract the type from the PDU. While the wire representation of the entry mode is similar in structure to POSIX stat(), the assignments of the entry types are different. Applying the S_DT macro to cf_mode instead yields the correct result. This is also what the equivalent function smb311_posix_info_to_fattr in inode.c already does for stat() etc.; which is why "ls -l" would give the correct file type but "ls" would not (as identified by the colors).

---
 fs/smb/client/readdir.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/smb/client/readdir.c +1 -1
index ba0193cf9033..4e5460206397 100644
@@ -264,7 +264,7 @@ cifs_posix_to_fattr(struct cifs_fattr *fattr, struct smb2_posix_info *info,
 	/* The Mode field in the response can now include the file type as well */
 	fattr->cf_mode = wire_mode_to_posix(le32_to_cpu(info->Mode),
 					    fattr->cf_cifsattrs & ATTR_DIRECTORY);
-	fattr->cf_dtype = S_DT(le32_to_cpu(info->Mode));
+	fattr->cf_dtype = S_DT(fattr->cf_mode);
 
 	switch (fattr->cf_mode & S_IFMT) {
 	case S_IFLNK:
Signature · 1 line
2.50.0
#1 lore raw

good catch

Tentatively merged into cifs-2.6.git for-next and added cc:stable

Quoted 38 lines · Philipp Kerling

When SMB 3.1.1 POSIX Extensions are negotiated, userspace applications using readdir() or getdents() calls without stat() on each individual file (such as a simple "ls" or "find") would misidentify file types and exhibit strange behavior such as not descending into directories. The reason for this behavior is an oversight in the cifs_posix_to_fattr conversion function. Instead of extracting the entry type for cf_dtype from the properly converted cf_mode field, it tries to extract the type from the PDU. While the wire representation of the entry mode is similar in structure to POSIX stat(), the assignments of the entry types are different. Applying the S_DT macro to cf_mode instead yields the correct result. This is also what the equivalent function smb311_posix_info_to_fattr in inode.c already does for stat() etc.; which is why "ls -l" would give the correct file type but "ls" would not (as identified by the colors).

---
 fs/smb/client/readdir.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/smb/client/readdir.c +1 -2
index ba0193cf9033..4e5460206397 100644
@@ -264,7 +264,7 @@ cifs_posix_to_fattr(struct cifs_fattr *fattr, struct smb2_posix_info *info,
        /* The Mode field in the response can now include the file type as well */
        fattr->cf_mode = wire_mode_to_posix(le32_to_cpu(info->Mode),
                                            fattr->cf_cifsattrs & ATTR_DIRECTORY);
-       fattr->cf_dtype = S_DT(le32_to_cpu(info->Mode));
+       fattr->cf_dtype = S_DT(fattr->cf_mode);
 
        switch (fattr->cf_mode & S_IFMT) {
        case S_IFLNK:
--

2.50.0

Signature · 3 lines
Thanks,

Steve