[Devel] [PATCH vz10] selftests/filelock: zero-initialize struct flock
Eva Kurchatova
eva.kurchatova at virtuozzo.com
Thu Jun 25 01:42:45 MSK 2026
The ofdlocks test installs an OFD read lock at offset 5..7 and then
issues two F_OFD_GETLK queries (one starting at offset 5 with length 1,
one starting at offset 0 with length 0) expecting them to report the
same lock. It then compares the two struct flock results with memcmp().
Because 'fl' and 'fl2' live on the stack and are only partially
initialized by the caller (l_type, l_whence, l_start, l_len, l_pid),
the implicit padding bytes that 'struct flock' has on x86_64 are left
with whatever happens to be on the stack. The kernel does not touch
those padding bytes on the F_OFD_GETLK return path, so memcmp() of the
full sizeof(struct flock) compares uninitialized padding from two
different stack frames and intermittently reports them as different:
[SUCCESS] F_UNLCK test returns: locked, type 0 pid -1 len 3
[FAIL] F_UNLCK test returns: locked, type 0 pid -1 len 3
i.e. the printed fields are identical but memcmp() still fails.
Zero-initialize both structs at declaration so the padding is
deterministic and the comparison is meaningful.
Signed-off-by: Eva Kurchatova <eva.kurchatova at virtuozzo.com>
https://virtuozzo.atlassian.net/browse/VSTOR-134203
Feature: fix selftests
---
tools/testing/selftests/filelock/ofdlocks.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/testing/selftests/filelock/ofdlocks.c b/tools/testing/selftests/filelock/ofdlocks.c
index a55b79810ab2..45dc417dae89 100644
--- a/tools/testing/selftests/filelock/ofdlocks.c
+++ b/tools/testing/selftests/filelock/ofdlocks.c
@@ -35,7 +35,7 @@ static int lock_get(int fd, struct flock *fl)
int main(void)
{
int rc;
- struct flock fl, fl2;
+ struct flock fl = {0}, fl2 = {0};
int fd = open("/tmp/aa", O_RDWR | O_CREAT | O_EXCL, 0600);
int fd2 = open("/tmp/aa", O_RDONLY);
--
2.47.3
More information about the Devel
mailing list