Skip to content

Fix user-space data write with incorrect offset #67

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions file.c
Original file line number Diff line number Diff line change
Expand Up @@ -413,8 +413,8 @@ static ssize_t simplefs_write(struct file *file,
size_t bytes_to_write =
min_t(size_t, len, SIMPLEFS_BLOCK_SIZE - pos % SIMPLEFS_BLOCK_SIZE);

if (copy_from_user(bh_data->b_data + pos % SIMPLEFS_BLOCK_SIZE, buf,
bytes_to_write)) {
if (copy_from_user(bh_data->b_data + pos % SIMPLEFS_BLOCK_SIZE,
buf + bytes_write, bytes_to_write)) {
brelse(bh_data);
bytes_write = -EFAULT;
break;
Expand Down
12 changes: 12 additions & 0 deletions script/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,18 @@ test_op 'dd if=/dev/zero of=file bs=1M count=12 status=none'
filesize=$(sudo ls -lR | grep -e "$F_MOD 2".*file | awk '{print $5}')
test $filesize -le $MAXFILESIZE || echo "Failed, file size over the limit"

# Write the file size larger than BLOCK_SIZE
# test serial to write
test_op 'printf \"%.0s123456789\" {1..1600} > file.txt'
count=$(awk '{count += gsub(/123456789/, "")} END {print count}' "file.txt")
echo "test $count"
test "$count" -eq 1600 || echo "Failed, file size not matching"
# test block to write
test_op 'cat file.txt > checkfile.txt'
count=$(awk '{count += gsub(/123456789/, "")} END {print count}' "checkfile.txt")
echo "test $count"
test "$count" -eq 1600 || echo "Failed, file size not matching"

# test remove symbolic link
test_op 'ln -s file symlink_fake'
test_op 'rm -f symlink_fake'
Expand Down