Skip to contentSkip to conversation

ksmbd: fix incorrect handling of iterate_dir

PATCH In review Hyunchul Lee 2 participants 12 messages Aug 19, 2022 – Aug 31, 2022

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

PATCH 1/1 ksmbd: fix incorrect handling of iterate_dir

if iterate_dir() returns non-negative value, caller has to treat it as normal and check there is any error while populating dentry information. ksmbd doesn't have to do anything because ksmbd already checks too small OutputBufferLength to store one file information.

And because ctx->pos is set to file->f_pos when iterative_dir is called, remove restart_ctx().

This patch fixes some failure of SMB2_QUERY_DIRECTORY, which happens when ntfs3 is local filesystem.

---
 fs/ksmbd/smb2pdu.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
fs/ksmbd/smb2pdu.c +2 -4
index 53c91ab02be2..6716c4e3c16d 100644
@@ -3970,11 +3970,9 @@ int smb2_query_dir(struct ksmbd_work *work)
 	 */
 	if (!d_info.out_buf_len && !d_info.num_entry)
 		goto no_buf_len;
-	if (rc == 0)
-		restart_ctx(&dir_fp->readdir_data.ctx);
-	if (rc == -ENOSPC)
+	if (rc > 0 || rc == -ENOSPC)
 		rc = 0;
-	if (rc)
+	else if (rc)
 		goto err_out;
 
 	d_info.wptr = d_info.rptr;
Signature · 1 line
2.17.1
maintainer
#1 lore raw

2022-08-19 13:35 GMT+09:00, Hyunchul Lee <[email protected]>:

Quoted 11 lines

if iterate_dir() returns non-negative value, caller has to treat it as normal and check there is any error while populating dentry information. ksmbd doesn't have to do anything because ksmbd already checks too small OutputBufferLength to store one file information.

And because ctx->pos is set to file->f_pos when iterative_dir is called, remove restart_ctx().

Shouldn't we get rid of the useless restart_ctx() ?

Quoted 15 lines

This patch fixes some failure of SMB2_QUERY_DIRECTORY, which happens when ntfs3 is local filesystem.

---
 fs/ksmbd/smb2pdu.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
fs/ksmbd/smb2pdu.c +0 -0
index 53c91ab02be2..6716c4e3c16d 100644

fs/ksmbd/smb2pdu.c int smb2_query_dir(struct ksmbd_work *work) · line 3973

Quoted 7 lines
fs/ksmbd/smb2pdu.c +1 -3
@@ -3970,11 +3970,9 @@ int smb2_query_dir(struct ksmbd_work *work)
 	 */
 	if (!d_info.out_buf_len && !d_info.num_entry)
 		goto no_buf_len;
-	if (rc == 0)
-		restart_ctx(&dir_fp->readdir_data.ctx);
-	if (rc == -ENOSPC)
+	if (rc > 0 || rc == -ENOSPC)

Do you know why -ENOSPC error is ignored ?

Thanks.

Quoted 10 lines
fs/ksmbd/smb2pdu.c +1 -2
 		rc = 0;
-	if (rc)
+	else if (rc)
 		goto err_out;
 
 	d_info.wptr = d_info.rptr;
--

2.17.1

#2 lore raw

2022년 8월 22일 (월) 오전 9:51, Namjae Jeon <[email protected]>님이 작성:

Quoted 10 lines

2022-08-19 13:35 GMT+09:00, Hyunchul Lee <[email protected]>:

Quoted 8 lines

if iterate_dir() returns non-negative value, caller has to treat it as normal and check there is any error while populating dentry information. ksmbd doesn't have to do anything because ksmbd already checks too small OutputBufferLength to store one file information.

Quoted 5 lines
Quoted 3 lines

And because ctx->pos is set to file->f_pos when iterative_dir is called, remove restart_ctx().

Shouldn't we get rid of the useless restart_ctx() ?

There is one place to call this function. We can replace that with ctx->pos = 0 and remove this function.

Quoted 10 lines
Quoted 10 lines

This patch fixes some failure of SMB2_QUERY_DIRECTORY, which happens when ntfs3 is local filesystem.

---
 fs/ksmbd/smb2pdu.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
Quoted 14 lines

fs/ksmbd/smb2pdu.c int smb2_query_dir(struct ksmbd_work *work) · line 3973

Quoted 12 lines
fs/ksmbd/smb2pdu.c +1 -3
index 53c91ab02be2..6716c4e3c16d 100644
@@ -3970,11 +3970,9 @@ int smb2_query_dir(struct ksmbd_work *work)
       */
      if (!d_info.out_buf_len && !d_info.num_entry)
              goto no_buf_len;
-     if (rc == 0)
-             restart_ctx(&dir_fp->readdir_data.ctx);
-     if (rc == -ENOSPC)
+     if (rc > 0 || rc == -ENOSPC)

Do you know why -ENOSPC error is ignored ?

I don't know why and can't find the commit history for this.

Quoted 11 lines

Thanks.

Quoted 10 lines
fs/ksmbd/smb2pdu.c +1 -2
              rc = 0;
-     if (rc)
+     else if (rc)
              goto err_out;
 
      d_info.wptr = d_info.rptr;
--

2.17.1

Signature · 2 lines
Thanks,
Hyunchul
maintainer
#3 lore raw

2022-08-22 11:14 GMT+09:00, Hyunchul Lee <[email protected]>:

Quoted 11 lines

2022년 8월 22일 (월) 오전 9:51, Namjae Jeon <[email protected]>님이 작성:

Quoted 10 lines

2022-08-19 13:35 GMT+09:00, Hyunchul Lee <[email protected]>:

Quoted 8 lines

if iterate_dir() returns non-negative value, caller has to treat it as normal and check there is any error while populating dentry information. ksmbd doesn't have to do anything because ksmbd already checks too small OutputBufferLength to store one file information.

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

And because ctx->pos is set to file->f_pos when iterative_dir is called, remove restart_ctx().

Shouldn't we get rid of the useless restart_ctx() ?

There is one place to call this function. We can replace that with ctx->pos = 0 and remove this function.

Why should we do ctx->pos = 0 there ?

Quoted 26 lines
Quoted 11 lines
Quoted 11 lines

This patch fixes some failure of SMB2_QUERY_DIRECTORY, which happens when ntfs3 is local filesystem.

---
 fs/ksmbd/smb2pdu.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
Quoted 14 lines

fs/ksmbd/smb2pdu.c int smb2_query_dir(struct ksmbd_work *work) · line 3973

Quoted 12 lines
fs/ksmbd/smb2pdu.c +1 -3
index 53c91ab02be2..6716c4e3c16d 100644
@@ -3970,11 +3970,9 @@ int smb2_query_dir(struct ksmbd_work *work)
       */
      if (!d_info.out_buf_len && !d_info.num_entry)
              goto no_buf_len;
-     if (rc == 0)
-             restart_ctx(&dir_fp->readdir_data.ctx);
-     if (rc == -ENOSPC)
+     if (rc > 0 || rc == -ENOSPC)

Do you know why -ENOSPC error is ignored ?

Quoted 2 lines

I don't know why and can't find the commit history for this.

After checking if -ENOSPC error is returned, there is no need to leave it if it is not needed.

Quoted 19 lines
Quoted 12 lines

Thanks.

Quoted 10 lines
fs/ksmbd/smb2pdu.c +1 -2
              rc = 0;
-     if (rc)
+     else if (rc)
              goto err_out;
 
      d_info.wptr = d_info.rptr;
--

2.17.1

--
Thanks,
Hyunchul

#4 lore raw

2022년 8월 22일 (월) 오전 11:47, Namjae Jeon <[email protected]>님이 작성:

Quoted 16 lines

2022-08-22 11:14 GMT+09:00, Hyunchul Lee <[email protected]>:

Quoted 14 lines

2022년 8월 22일 (월) 오전 9:51, Namjae Jeon <[email protected]>님이 작성:

Quoted 13 lines

2022-08-19 13:35 GMT+09:00, Hyunchul Lee <[email protected]>:

Quoted 11 lines

if iterate_dir() returns non-negative value, caller has to treat it as normal and check there is any error while populating dentry information. ksmbd doesn't have to do anything because ksmbd already checks too small OutputBufferLength to store one file information.

And because ctx->pos is set to file->f_pos when iterative_dir is called, remove restart_ctx().

Quoted 6 lines
Quoted 5 lines
Quoted 2 lines

Shouldn't we get rid of the useless restart_ctx() ?

There is one place to call this function. We can replace that with ctx->pos = 0 and remove this function.

Why should we do ctx->pos = 0 there ?

restart_ctx has to be deleted. I misunderstood it,

Quoted 26 lines
Quoted 26 lines
Quoted 25 lines
Quoted 16 lines

This patch fixes some failure of SMB2_QUERY_DIRECTORY, which happens when ntfs3 is local filesystem.

---
 fs/ksmbd/smb2pdu.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
fs/ksmbd/smb2pdu.c +0 -0
index 53c91ab02be2..6716c4e3c16d 100644

fs/ksmbd/smb2pdu.c int smb2_query_dir(struct ksmbd_work *work) · line 3973

Quoted 7 lines
fs/ksmbd/smb2pdu.c +1 -3
@@ -3970,11 +3970,9 @@ int smb2_query_dir(struct ksmbd_work *work)
       */
      if (!d_info.out_buf_len && !d_info.num_entry)
              goto no_buf_len;
-     if (rc == 0)
-             restart_ctx(&dir_fp->readdir_data.ctx);
-     if (rc == -ENOSPC)
+     if (rc > 0 || rc == -ENOSPC)

Do you know why -ENOSPC error is ignored ?

Quoted 4 lines
Quoted 2 lines

I don't know why and can't find the commit history for this.

After checking if -ENOSPC error is returned, there is no need to leave it if it is not needed.

In most cases, -ENOSPC is not returned. Because the value is set to the return value from filesystems' iterate or iterate_share, and most file systems don't allocate disk space for this operation.

But we cannot guarantee this. So how about changing handling iterate_dir like gendents system call. Even if an error code is returned by iterate_dir, it treats as normal if several child files are iterated and the buffer is filled with
information about those.

Quoted 19 lines
Quoted 19 lines
Quoted 12 lines

Thanks.

Quoted 10 lines
fs/ksmbd/smb2pdu.c +1 -2
              rc = 0;
-     if (rc)
+     else if (rc)
              goto err_out;
 
      d_info.wptr = d_info.rptr;
--

2.17.1

--
Thanks,
Hyunchul

Signature · 2 lines
Thanks,
Hyunchul
maintainer
#5 lore raw

2022-08-22 15:24 GMT+09:00, Hyunchul Lee <[email protected]>:

Quoted 61 lines

2022년 8월 22일 (월) 오전 11:47, Namjae Jeon <[email protected]>님이 작성:

Quoted 16 lines

2022-08-22 11:14 GMT+09:00, Hyunchul Lee <[email protected]>:

Quoted 14 lines

2022년 8월 22일 (월) 오전 9:51, Namjae Jeon <[email protected]>님이 작성:

Quoted 13 lines

2022-08-19 13:35 GMT+09:00, Hyunchul Lee <[email protected]>:

Quoted 11 lines

if iterate_dir() returns non-negative value, caller has to treat it as normal and check there is any error while populating dentry information. ksmbd doesn't have to do anything because ksmbd already checks too small OutputBufferLength to store one file information.

And because ctx->pos is set to file->f_pos when iterative_dir is called, remove restart_ctx().

Quoted 6 lines
Quoted 5 lines
Quoted 2 lines

Shouldn't we get rid of the useless restart_ctx() ?

There is one place to call this function. We can replace that with ctx->pos = 0 and remove this function.

Why should we do ctx->pos = 0 there ?

restart_ctx has to be deleted. I misunderstood it,

Quoted 26 lines
Quoted 26 lines
Quoted 25 lines
Quoted 16 lines

This patch fixes some failure of SMB2_QUERY_DIRECTORY, which happens when ntfs3 is local filesystem.

---
 fs/ksmbd/smb2pdu.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
fs/ksmbd/smb2pdu.c +0 -0
index 53c91ab02be2..6716c4e3c16d 100644

fs/ksmbd/smb2pdu.c int smb2_query_dir(struct ksmbd_work *work) · line 3973

Quoted 7 lines
fs/ksmbd/smb2pdu.c +1 -3
@@ -3970,11 +3970,9 @@ int smb2_query_dir(struct ksmbd_work *work)
       */
      if (!d_info.out_buf_len && !d_info.num_entry)
              goto no_buf_len;
-     if (rc == 0)
-             restart_ctx(&dir_fp->readdir_data.ctx);
-     if (rc == -ENOSPC)
+     if (rc > 0 || rc == -ENOSPC)

Do you know why -ENOSPC error is ignored ?

Quoted 4 lines
Quoted 2 lines

I don't know why and can't find the commit history for this.

After checking if -ENOSPC error is returned, there is no need to leave it if it is not needed.

In most cases, -ENOSPC is not returned. Because the value is set to the return value from filesystems' iterate or iterate_share, and most file systems don't allocate disk space for this operation.

Quoted 6 lines

But we cannot guarantee this. So how about changing handling iterate_dir like gendents system call. Even if an error code is returned by iterate_dir,
it treats as normal if several child files are iterated and the buffer is filled with
information about those.

Among the errors of the smb2 query directory in the specification, there is a file corruption error response type(STATUS_FILE_CORRUPT_ERROR).
Can you check when smb server return that error response for smb2 query directory?

Quoted 27 lines
Quoted 16 lines
Quoted 16 lines
Quoted 13 lines

Thanks.

Quoted 10 lines
fs/ksmbd/smb2pdu.c +1 -2
              rc = 0;
-     if (rc)
+     else if (rc)
              goto err_out;
 
      d_info.wptr = d_info.rptr;
--

2.17.1

Quoted 4 lines
Quoted 4 lines

--
Thanks,
Hyunchul

--
Thanks,
Hyunchul

#6 lore raw

2022년 8월 23일 (화) 오전 9:40, Namjae Jeon <[email protected]>님이 작성:

Quoted 69 lines

2022-08-22 15:24 GMT+09:00, Hyunchul Lee <[email protected]>:

Quoted 61 lines

2022년 8월 22일 (월) 오전 11:47, Namjae Jeon <[email protected]>님이 작성:

Quoted 16 lines

2022-08-22 11:14 GMT+09:00, Hyunchul Lee <[email protected]>:

Quoted 14 lines

2022년 8월 22일 (월) 오전 9:51, Namjae Jeon <[email protected]>님이 작성:

Quoted 13 lines

2022-08-19 13:35 GMT+09:00, Hyunchul Lee <[email protected]>:

Quoted 11 lines

if iterate_dir() returns non-negative value, caller has to treat it as normal and check there is any error while populating dentry information. ksmbd doesn't have to do anything because ksmbd already checks too small OutputBufferLength to store one file information.

And because ctx->pos is set to file->f_pos when iterative_dir is called, remove restart_ctx().

Quoted 6 lines
Quoted 5 lines
Quoted 2 lines

Shouldn't we get rid of the useless restart_ctx() ?

There is one place to call this function. We can replace that with ctx->pos = 0 and remove this function.

Why should we do ctx->pos = 0 there ?

restart_ctx has to be deleted. I misunderstood it,

Quoted 26 lines
Quoted 26 lines
Quoted 25 lines
Quoted 16 lines

This patch fixes some failure of SMB2_QUERY_DIRECTORY, which happens when ntfs3 is local filesystem.

---
 fs/ksmbd/smb2pdu.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
fs/ksmbd/smb2pdu.c +0 -0
index 53c91ab02be2..6716c4e3c16d 100644

fs/ksmbd/smb2pdu.c int smb2_query_dir(struct ksmbd_work *work) · line 3973

Quoted 7 lines
fs/ksmbd/smb2pdu.c +1 -3
@@ -3970,11 +3970,9 @@ int smb2_query_dir(struct ksmbd_work *work)
       */
      if (!d_info.out_buf_len && !d_info.num_entry)
              goto no_buf_len;
-     if (rc == 0)
-             restart_ctx(&dir_fp->readdir_data.ctx);
-     if (rc == -ENOSPC)
+     if (rc > 0 || rc == -ENOSPC)

Do you know why -ENOSPC error is ignored ?

Quoted 4 lines
Quoted 2 lines

I don't know why and can't find the commit history for this.

After checking if -ENOSPC error is returned, there is no need to leave it if it is not needed.

In most cases, -ENOSPC is not returned. Because the value is set to the return value from filesystems' iterate or iterate_share, and most file systems don't allocate disk space for this operation.

Quoted 6 lines

But we cannot guarantee this. So how about changing handling iterate_dir like gendents system call. Even if an error code is returned by iterate_dir,
it treats as normal if several child files are iterated and the buffer is filled with
information about those.

Quoted 6 lines

Among the errors of the smb2 query directory in the specification, there is a file corruption error response type(STATUS_FILE_CORRUPT_ERROR).
Can you check when smb server return that error response for smb2 query directory?

According to MS-REREF, it means "The file or directory is corrupt and unreadable.
Run the chkdsk utility". And there is no function to return the error in Samba.

Quoted 27 lines
Quoted 27 lines
Quoted 16 lines
Quoted 16 lines
Quoted 13 lines

Thanks.

Quoted 10 lines
fs/ksmbd/smb2pdu.c +1 -2
              rc = 0;
-     if (rc)
+     else if (rc)
              goto err_out;
 
      d_info.wptr = d_info.rptr;
--

2.17.1

Quoted 4 lines
Quoted 4 lines

--
Thanks,
Hyunchul

--
Thanks,
Hyunchul

Signature · 2 lines
Thanks,
Hyunchul
maintainer
#7 lore raw
Quoted 39 lines
Quoted 32 lines
Quoted 25 lines
Quoted 16 lines
Quoted 16 lines
Quoted 15 lines

fs/ksmbd/smb2pdu.c int smb2_query_dir(struct ksmbd_work · line 3974

Quoted 13 lines
fs/ksmbd/smb2pdu.c +1 -3
index 53c91ab02be2..6716c4e3c16d 100644
@@ -3970,11 +3970,9 @@ int smb2_query_dir(struct ksmbd_work
 *work)
       */
      if (!d_info.out_buf_len && !d_info.num_entry)
              goto no_buf_len;
-     if (rc == 0)
-             restart_ctx(&dir_fp->readdir_data.ctx);
-     if (rc == -ENOSPC)
+     if (rc > 0 || rc == -ENOSPC)

Do you know why -ENOSPC error is ignored ?

Quoted 4 lines
Quoted 2 lines

I don't know why and can't find the commit history for this.

After checking if -ENOSPC error is returned, there is no need to leave it if it is not needed.

In most cases, -ENOSPC is not returned. Because the value is set to the return value from filesystems' iterate or iterate_share, and most file systems don't allocate disk space for this operation.

Quoted 7 lines

But we cannot guarantee this. So how about changing handling iterate_dir
like gendents system call. Even if an error code is returned by iterate_dir,
it treats as normal if several child files are iterated and the buffer is filled with
information about those.

Quoted 6 lines

Among the errors of the smb2 query directory in the specification, there is a file corruption error response type(STATUS_FILE_CORRUPT_ERROR).
Can you check when smb server return that error response for smb2 query directory?

Quoted 4 lines

According to MS-REREF, it means "The file or directory is corrupt and unreadable.
Run the chkdsk utility". And there is no function to return the error in Samba.

Is samba not able to know corruption errors using getdents syscall as you said? There is no reason to follow it. I think that ksmbd is able to return this error.

#8 lore raw

2022년 8월 23일 (화) 오전 11:45, Namjae Jeon <[email protected]>님이 작성:

Quoted 40 lines
Quoted 40 lines
Quoted 39 lines
Quoted 26 lines
Quoted 17 lines
Quoted 17 lines
Quoted 16 lines
Quoted 6 lines
fs/ksmbd/smb2pdu.c +0 -0
index 53c91ab02be2..6716c4e3c16d 100644

fs/ksmbd/smb2pdu.c int smb2_query_dir(struct ksmbd_work · line 3974

Quoted 8 lines
fs/ksmbd/smb2pdu.c +1 -3
@@ -3970,11 +3970,9 @@ int smb2_query_dir(struct ksmbd_work
 *work)
       */
      if (!d_info.out_buf_len && !d_info.num_entry)
              goto no_buf_len;
-     if (rc == 0)
-             restart_ctx(&dir_fp->readdir_data.ctx);
-     if (rc == -ENOSPC)
+     if (rc > 0 || rc == -ENOSPC)

Do you know why -ENOSPC error is ignored ?

Quoted 4 lines
Quoted 2 lines

I don't know why and can't find the commit history for this.

After checking if -ENOSPC error is returned, there is no need to leave it if it is not needed.

In most cases, -ENOSPC is not returned. Because the value is set to the return value from filesystems' iterate or iterate_share, and most file systems don't allocate disk space for this operation.

Quoted 7 lines

But we cannot guarantee this. So how about changing handling iterate_dir
like gendents system call. Even if an error code is returned by iterate_dir,
it treats as normal if several child files are iterated and the buffer is filled with
information about those.

Among the errors of the smb2 query directory in the specification, there is a file corruption error response type(STATUS_FILE_CORRUPT_ERROR).
Can you check when smb server return that error response for smb2 query directory?

Quoted 5 lines
Quoted 4 lines

According to MS-REREF, it means "The file or directory is corrupt and unreadable.
Run the chkdsk utility". And there is no function to return the error in Samba.

Is samba not able to know corruption errors using getdents syscall as you said?

If iterate_dir returns an error and there are files iterated, getdents syscall will succeed.
But if a client requests SMB2_QUERY_DIR again due to STATUS_NO_MORE_FILES absence of the last response, iterate_dir returns an error again and there are no
files iterated, getdents syscall will fail. Samba can send a response with an error.

Quoted 2 lines

There is no reason to follow it. I think that ksmbd is able to return this error.

Can we determine we should return a response with STATUS_FILE_CORRUPT_ERROR if iterate_dir returns -EIO?

Signature · 2 lines
Thanks,
Hyunchul
maintainer
#9 lore raw

2022-08-23 17:26 GMT+09:00, Hyunchul Lee <[email protected]>:

Quoted 52 lines

2022년 8월 23일 (화) 오전 11:45, Namjae Jeon <[email protected]>님이 작성:

Quoted 43 lines
Quoted 43 lines
Quoted 42 lines
Quoted 28 lines
Quoted 17 lines
Quoted 17 lines
Quoted 16 lines
Quoted 6 lines
fs/ksmbd/smb2pdu.c +0 -0
index 53c91ab02be2..6716c4e3c16d 100644

fs/ksmbd/smb2pdu.c int smb2_query_dir(struct ksmbd_work · line 3974

Quoted 8 lines
fs/ksmbd/smb2pdu.c +1 -3
@@ -3970,11 +3970,9 @@ int smb2_query_dir(struct ksmbd_work
 *work)
       */
      if (!d_info.out_buf_len && !d_info.num_entry)
              goto no_buf_len;
-     if (rc == 0)
-             restart_ctx(&dir_fp->readdir_data.ctx);
-     if (rc == -ENOSPC)
+     if (rc > 0 || rc == -ENOSPC)

Do you know why -ENOSPC error is ignored ?

Quoted 5 lines
Quoted 2 lines

I don't know why and can't find the commit history for this.

After checking if -ENOSPC error is returned, there is no need to leave
it if it is not needed.

In most cases, -ENOSPC is not returned. Because the value is set to the return value from filesystems' iterate or iterate_share,
and most file systems don't allocate disk space for this operation.

Quoted 8 lines

But we cannot guarantee this. So how about changing handling iterate_dir
like gendents system call. Even if an error code is returned by iterate_dir,
it treats as normal if several child files are iterated and the buffer
is filled with
information about those.

Among the errors of the smb2 query directory in the specification, there is a file corruption error response type(STATUS_FILE_CORRUPT_ERROR).
Can you check when smb server return that error response for smb2 query directory?

Quoted 7 lines
Quoted 5 lines

According to MS-REREF, it means "The file or directory is corrupt and unreadable.
Run the chkdsk utility". And there is no function to return the error in
Samba.

Is samba not able to know corruption errors using getdents syscall as you said?

Quoted 7 lines

If iterate_dir returns an error and there are files iterated, getdents syscall will succeed.
But if a client requests SMB2_QUERY_DIR again due to STATUS_NO_MORE_FILES absence of the last response, iterate_dir returns an error again and there are no
files iterated, getdents syscall will fail. Samba can send a response with an error.

Sorry, can't understand. What error ?

Quoted 6 lines
Quoted 3 lines

There is no reason to follow it. I think that ksmbd is able to return this error.

Can we determine we should return a response with STATUS_FILE_CORRUPT_ERROR if iterate_dir returns -EIO?

STATUS_FILE_CORRUPT_ERROR is still not cleared. want to know how windows server handle it.

Quoted 5 lines

--
Thanks,
Hyunchul

#10 lore raw

2022년 8월 24일 (수) 오전 9:10, Namjae Jeon <[email protected]>님이 작성:

Quoted 54 lines

2022-08-23 17:26 GMT+09:00, Hyunchul Lee <[email protected]>:

Quoted 52 lines

2022년 8월 23일 (화) 오전 11:45, Namjae Jeon <[email protected]>님이 작성:

Quoted 50 lines
Quoted 43 lines
Quoted 36 lines
Quoted 28 lines
Quoted 17 lines
Quoted 17 lines
Quoted 16 lines
Quoted 6 lines
fs/ksmbd/smb2pdu.c +0 -0
index 53c91ab02be2..6716c4e3c16d 100644

fs/ksmbd/smb2pdu.c int smb2_query_dir(struct ksmbd_work · line 3974

Quoted 8 lines
fs/ksmbd/smb2pdu.c +1 -3
@@ -3970,11 +3970,9 @@ int smb2_query_dir(struct ksmbd_work
 *work)
       */
      if (!d_info.out_buf_len && !d_info.num_entry)
              goto no_buf_len;
-     if (rc == 0)
-             restart_ctx(&dir_fp->readdir_data.ctx);
-     if (rc == -ENOSPC)
+     if (rc > 0 || rc == -ENOSPC)

Do you know why -ENOSPC error is ignored ?

Quoted 5 lines
Quoted 2 lines

I don't know why and can't find the commit history for this.

After checking if -ENOSPC error is returned, there is no need to leave
it if it is not needed.

In most cases, -ENOSPC is not returned. Because the value is set to the return value from filesystems' iterate or iterate_share,
and most file systems don't allocate disk space for this operation.

Quoted 8 lines

But we cannot guarantee this. So how about changing handling iterate_dir
like gendents system call. Even if an error code is returned by iterate_dir,
it treats as normal if several child files are iterated and the buffer
is filled with
information about those.

Quoted 6 lines

Among the errors of the smb2 query directory in the specification, there is a file corruption error response type(STATUS_FILE_CORRUPT_ERROR).
Can you check when smb server return that error response for smb2 query directory?

Quoted 5 lines

According to MS-REREF, it means "The file or directory is corrupt and unreadable.
Run the chkdsk utility". And there is no function to return the error in
Samba.

Is samba not able to know corruption errors using getdents syscall as you said?

Quoted 8 lines
Quoted 7 lines

If iterate_dir returns an error and there are files iterated, getdents syscall will succeed.
But if a client requests SMB2_QUERY_DIR again due to STATUS_NO_MORE_FILES absence of the last response, iterate_dir returns an error again and there are no
files iterated, getdents syscall will fail. Samba can send a response with an error.

Sorry, can't understand. What error ?

When I set the last entry of directory FAT chain to be invalid value in exFAT, the last getdents returns -EIO, but Samba sends responses without an error

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

There is no reason to follow it. I think that ksmbd is able to return this error.

Can we determine we should return a response with STATUS_FILE_CORRUPT_ERROR if iterate_dir returns -EIO?

STATUS_FILE_CORRUPT_ERROR is still not cleared. want to know how windows server handle it.

In the above example, Windows server sends an empty SMB2_QUERY_DIRECTORY response with STATUS_FILE_CORRUPT_ERROR.

And when executing "dir <directory>" in Windows terminal for the local exFAT filesystem,
there are no files iterated and DirIOError is generated.

Quoted 5 lines
Quoted 5 lines

--
Thanks,
Hyunchul

--
Thanks,
Hyunchul

maintainer
#11 lore raw
Quoted 4 lines

When I set the last entry of directory FAT chain to be invalid value in exFAT,
the last getdents returns -EIO, but Samba sends responses without an error

There seems to be an attempt to improve this in Samba as well.
https://bugzilla.samba.org/show_bug.cgi?id=13718

Quoted 11 lines
Quoted 10 lines
Quoted 8 lines
Quoted 4 lines

There is no reason to follow it. I think that ksmbd is able to return this error.

Can we determine we should return a response with
STATUS_FILE_CORRUPT_ERROR
if iterate_dir returns -EIO?

STATUS_FILE_CORRUPT_ERROR is still not cleared. want to know how windows server handle it.

Quoted 6 lines

In the above example, Windows server sends an empty SMB2_QUERY_DIRECTORY response with STATUS_FILE_CORRUPT_ERROR.

And when executing "dir <directory>" in Windows terminal for the local exFAT filesystem,
there are no files iterated and DirIOError is generated.

This is the behavior I was expecting. ksmbd can handle this as well.

Thanks.

Quoted 14 lines
Quoted 7 lines
Quoted 7 lines

--
Thanks,
Hyunchul

--
Thanks,
Hyunchul