Bug 13718 - Does smbd send error like STATUS_FILE_CORRUPT_ERROR on directory scanning error?
Does smbd send error like STATUS_FILE_CORRUPT_ERROR on directory scanning error?
Status: NEW
Product: Samba 4.1 and newer
Classification: Unclassified
Component: File services
All All
: P5 normal
: ---
Assigned To: Samba QA Contact
Samba QA Contact
Depends on:
  Show dependency treegraph
Reported: 2018-12-18 05:42 UTC by kenjiuno
Modified: 2019-01-07 18:32 UTC (History)
1 user (show)

See Also:

2 logs: log-bad=smbdShouldEncountIoError, log-good=shouldnt (69.44 KB, application/x-zip-compressed)
2018-12-21 04:10 UTC, kenjiuno
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description kenjiuno 2018-12-18 05:42:50 UTC
I had a NAS (based on samba) didn't send disk i/o error code to client on directory scanning operation.

If it is true, is there chance to send error code such as STATUS_FILE_CORRUPT_ERROR to client?

// It is used in real file system driver like fastfat.
// https://github.com/Microsoft/Windows-driver-samples/blob/6c1981b8504329521343ad00f32daa847fa6083a/filesys/fastfat/dirsup.c

I could reproduce this problem using dmsetup error mapping simulation.

Here is ls command output saying about an error at /mnt/test/broken/

ku@samba-server:~$ ls /mnt/test/broken/
ls: reading directory '/mnt/test/broken/': Input/output error

However smbd through smbclient won't say error at //

ku@samba-server:~$ /usr/local/samba/bin/smbclient //
Unable to initialize messaging context
Enter WORKGROUP\ku's password:
Try "help" to get a list of possible commands.
smb: \> ls
  .                                   D        0  Mon Dec 17 13:58:35 2018
  ..                                  D        0  Mon Dec 17 12:34:35 2018
  ok                                  D        0  Mon Dec 17 13:58:44 2018
  broken                              D        0  Mon Dec 17 13:54:24 2018
  lost+found                          D        0  Mon Dec 17 12:48:40 2018

                53 blocks of size 1024. 34 blocks available
smb: \> cd broken
smb: \broken\> ls
  .                                   D        0  Mon Dec 17 13:54:24 2018
  ..                                  D        0  Mon Dec 17 13:58:35 2018

                53 blocks of size 1024. 34 blocks available
smb: \broken\>

Windows share folder can say a status code like NT_STATUS_DEVICE_NOT_READY on device error:

smb: \folder1\folder2\folder3\> cd folder4\
smb: \folder1\folder2\folder3\folder4\> ls
NT_STATUS_DEVICE_NOT_READY listing \folder1\folder2\folder3\folder4\*

// NT_STATUS_DEVICE_NOT_READY is reported because iSCSI target returns "0010 = Sense Key: Not Ready (0x2)" on disk error.
// I have build iSCSI target on CentOS7 using dmsetup error mapping.

I'm not sure about smbd source code. So I'm afraid could you look into this problem?

I think samba is great software. I'll support for fixing this problem!

Comment 1 kenjiuno 2018-12-20 08:10:40 UTC
Here are some commands I have used to create an ext2 image file and block device reporting i/o error.

# dd if=/dev/zero of=~/ext2 bs=60KiB count=1
# mkfs.ext2 ~/ext2
# losetup -f ~/ext2
# losetup -l
# mount /dev/loop0 /mnt/test/
# mkdir /mnt/test/folder1
# mkdir /mnt/test/folder1/folder2
# mkdir /mnt/test/folder1/folder2/folder3
# umount /mnt/test
# vi errormap

0 116 linear /dev/loop0 0
116 1 error
117 3 linear /dev/loop0 117

# dmsetup create baddisk < errormap
# mount /dev/mapper/baddisk /mnt/test/

[root@localhost ~]# ls /mnt/test/folder1/folder2/
ls: reading directory /mnt/test/folder1/folder2/: Input/output error

Sharing /mnt/test with smbd will be useful to verify.
Comment 2 Jeremy Allison 2018-12-21 01:03:16 UTC
Can you get a debug level 10 log trace from smbd, that will allow us to see what error code we're getting back from a system call that fails when accessing the corrupt disk ?
Comment 3 kenjiuno 2018-12-21 04:10:01 UTC
Created attachment 14755 [details]
2 logs: log-bad=smbdShouldEncountIoError, log-good=shouldnt
Comment 4 kenjiuno 2018-12-21 04:16:42 UTC
I have attached 2 logs.

log-bad = smbclient requested smbd to access i/o error directory.
log-good = smbclient requested smbd to access normal directory.

just my quick look for significant difference starts at:

8034: smbd_dirptr_get_entry: dirptr 0x5655334faff0 now at offset 9223372036854775807

8034: smbd_dirptr_get_entry: dirptr 0x5604de79ac60 now at offset -1

my commands:

# smbd -i -S --debuglevel=10 -s ~/smb.conf > log

# smbclient -c "cd /folder1/folder2/ ; ls" //
Comment 5 kenjiuno 2018-12-25 04:29:08 UTC
In my quick research, readdir failure (errno variable) in vfswrap_readdir seems not to be processed.


at vfswrap_readdir
> result = readdir(dirp);



Referenced at vfs_readdirname
> ptr = SMB_VFS_READDIR(conn, (DIR *)p, sbuf);



Referenced at ReadDirName
> while ((n = vfs_readdirname(conn, dirp->dir, sbuf, &talloced))) {



Referenced at at dptr_normal_ReadDirName
> while ((name = ReadDirName(dptr->dir_hnd, poffset, pst, &talloced))



Referenced at at dptr_ReadDirName
> name_temp = dptr_normal_ReadDirName(dptr, poffset, pst,



Referenced at at smbd_dirptr_get_entry
> dname = dptr_ReadDirName(ctx, dirptr, &cur_offset, &sbuf);



Referenced at get_dir_entry
> ok = smbd_dirptr_get_entry(ctx,



Referenced at reply_search
> finished = !get_dir_entry(ctx,

Comment 6 kenjiuno 2018-12-25 04:53:57 UTC
For later reference: readdir fails in errno EIO.

[root@localhost ~]# ./a.out /mnt/test/folder1/folder2/
opendir 0xc3e010 0
readdir (nil) 5

#define EIO              5      /* I/O error */

> Input/output error (POSIX.1)

Comment 7 Jeremy Allison 2019-01-07 18:32:53 UTC
Yes, vfswrap_readdir() won't process the errno, that should be done at the calling layer if readdir() returns NULL.

Ah, I see the problem. readdir() is a horrid interface in that end-of-directory and error are both returned as NULL, and the caller must distinguish. That means errno must be set to 0 *before* calling readdir and then checked on return.

I'll see what I can do.