Skip to content

client: fix d_reclen for readdir#56776

Merged
batrick merged 1 commit intoceph:mainfrom
xhernandez:fix-readdir
Sep 25, 2024
Merged

client: fix d_reclen for readdir#56776
batrick merged 1 commit intoceph:mainfrom
xhernandez:fix-readdir

Conversation

@xhernandez
Copy link
Contributor

@xhernandez xhernandez commented Apr 9, 2024

Based on the man page of readdir(3), the d_reclen field should contain the total size of the record, which varies depending on the length of the returned name. However, the previous implementation was returning a hardcoded '1' in all cases.

This patch computes the right size of the record and returns it.

Fixes: https://tracker.ceph.com/issues/65389

Contribution Guidelines

  • To sign and title your commits, please refer to Submitting Patches to Ceph.

  • If you are submitting a fix for a stable branch (e.g. "quincy"), please refer to Submitting Patches to Ceph - Backports for the proper workflow.

  • When filling out the below checklist, you may click boxes directly in the GitHub web UI. When entering or editing the entire PR message in the GitHub web UI editor, you may also select a checklist item by adding an x between the brackets: [x]. Spaces and capitalization matter when checking off items this way.

Checklist

  • Tracker (select at least one)
    • References tracker ticket
    • Very recent bug; references commit where it was introduced
    • New feature (ticket optional)
    • Doc update (no ticket needed)
    • Code cleanup (no ticket needed)
  • Component impact
    • Affects Dashboard, opened tracker ticket
    • Affects Orchestrator, opened tracker ticket
    • No impact that needs to be tracked
  • Documentation (select at least one)
    • Updates relevant documentation
    • No doc update is appropriate
  • Tests (select at least one)
Show available Jenkins commands
  • jenkins retest this please
  • jenkins test classic perf
  • jenkins test crimson perf
  • jenkins test signed
  • jenkins test make check
  • jenkins test make check arm64
  • jenkins test submodules
  • jenkins test dashboard
  • jenkins test dashboard cephadm
  • jenkins test api
  • jenkins test docs
  • jenkins render docs
  • jenkins test ceph-volume all
  • jenkins test ceph-volume tox
  • jenkins test windows
  • jenkins test rook e2e

@github-actions github-actions bot added the cephfs Ceph File System label Apr 9, 2024
@chrisphoffman chrisphoffman requested a review from a team April 12, 2024 14:01
de->d_off = next_off;
#endif
de->d_reclen = 1;
de->d_reclen = (uintptr_t)last - (uintptr_t)de + 1;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. Just FYI - I had discussed this with @xhernandez over chat and the issue cropped up when developing proxy b/w samba and libcephfs where d_reclen was relied on.

@xhernandez xhernandez force-pushed the fix-readdir branch 2 times, most recently from 75ef6f4 to 7c93093 Compare April 16, 2024 10:27
Comment on lines 9246 to 9249
int len = strlen(name);
if (len > 255) {
len = 255;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
int len = strlen(name);
if (len > 255) {
len = 255;
}
size_t len = strlen(name);
len = min(len, (size_t)255);

int could get prone to overflow, therefore switched to using size_t (memcpy()'s len arg is indeed of type size_t too) and using min() looks a bit cleaner.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's very unlikely that it will overflow, but anyway size_t is better. I'll change this.

@xhernandez
Copy link
Contributor Author

jenkins test make check

@xhernandez xhernandez force-pushed the fix-readdir branch 2 times, most recently from 6e0420e to 6cd297a Compare April 16, 2024 16:08
size_t len = strlen(name);
len = std::min(len, (size_t)255);
memcpy(de->d_name, name, len);
de->d_name[len] = 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so now it's switched from string termination char to int 0?

@github-actions github-actions bot added stale and removed stale labels Jul 28, 2024
@ceph ceph deleted a comment from github-actions bot Aug 13, 2024
Based on the man page of readdir(3), the d_reclen field should contain
the total size of the record, which varies depending on the length of
the returned name. However, the previous implementation was returning a
hardcoded '1' in all cases.

This patch computes the right size of the record and returns it.

Fixes: https://tracker.ceph.com/issues/65389
Signed-off-by: Xavi Hernandez <[email protected]>
@batrick
Copy link
Member

batrick commented Sep 3, 2024

jenkins test make check

@batrick
Copy link
Member

batrick commented Sep 3, 2024

jenkins test make check arm64

@batrick
Copy link
Member

batrick commented Sep 16, 2024

jenkins test make check arm64

@batrick
Copy link
Member

batrick commented Sep 16, 2024

@batrick
Copy link
Member

batrick commented Sep 17, 2024

jenkins test make check arm64

1 similar comment
@batrick
Copy link
Member

batrick commented Sep 17, 2024

jenkins test make check arm64

@batrick
Copy link
Member

batrick commented Sep 20, 2024

@batrick
Copy link
Member

batrick commented Sep 25, 2024

@batrick batrick merged commit cfac7ef into ceph:main Sep 25, 2024
@xhernandez xhernandez deleted the fix-readdir branch September 26, 2024 08:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants