Project

General

Profile

Actions

Bug #48202

closed

libcephfs allows calling ftruncate on a file open read-only

Added by John Mulligan over 3 years ago. Updated about 3 years ago.

Status:
Resolved
Priority:
Normal
Category:
Correctness/Safety
Target version:
% Done:

0%

Source:
Community (dev)
Tags:
Backport:
octopus,nautilus
Regression:
No
Severity:
3 - minor
Reviewed:
Affected Versions:
ceph-qa-suite:
Component(FS):
Client
Labels (FS):
Pull request ID:
Crash signature (v1):
Crash signature (v2):

Description

When calling ceph_ftruncate on an "fd" open read only, using the O_RDONLY flag, libcephfs does not return and error and instead truncates the file. Compare this to the typical libc/linux ftruncate call which will return an error when the fd is not open for writing.

To reproduce I am attaching a simple c file that first "touches" the file (to ensure it exists) and then opens it read only and then demonstrates that truncate "succeeds" but a subsequent write fails. In comparison I attach a c file with system calls that demonstrates that ftruncate fails before reaching the write call.

I originally discovered this issue while wrapping APIs for go-ceph, but wrote the C versions to ensure this issue was, in fact, present in the libcephs layer.

Please let me know if I can provide any other information.


Files

cephfs_ftruncate.c (2.14 KB) cephfs_ftruncate.c Reproduer John Mulligan, 11/11/2020 06:47 PM
just_ftruncate.c (1.24 KB) just_ftruncate.c Comparision John Mulligan, 11/11/2020 06:47 PM

Related issues 2 (0 open2 closed)

Copied to CephFS - Backport #48375: octopus: libcephfs allows calling ftruncate on a file open read-onlyResolvedNathan CutlerActions
Copied to CephFS - Backport #48376: nautilus: libcephfs allows calling ftruncate on a file open read-onlyResolvedNathan CutlerActions
Actions

Also available in: Atom PDF