lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [day] [month] [year] [list]
Message-Id: <20250911033154.2397610-1-zhouyuhang1010@163.com>
Date: Thu, 11 Sep 2025 11:31:54 +0800
From: zhouyuhang <zhouyuhang1010@....com>
To: shuah@...nel.org,
	jlayton@...nel.org
Cc: linux-kselftest@...r.kernel.org,
	linux-kernel@...r.kernel.org,
	Zhou Yuhang <zhouyuhang@...inos.cn>
Subject: [PATCH v2] selftests: filelock: Initialize the flock to zero

From: Zhou Yuhang <zhouyuhang@...inos.cn>

On x86_64, the size of struct flock is 32 bytes,
and the layout of this structure may be as follows:

 +------------+  offset 0
 | l_type     |  2 bytes
 +------------+  offset 2
 | l_whence   |  2 bytes
 +------------+  offset 4
 | padding    |  4 bytes
 +------------+  offset 8
 | l_start    |  8 bytes
 +------------+  offset 16
 | l_len      |  8 bytes
 +------------+  offset 24
 | l_pid      |  4 bytes
 +------------+  offset 28
 | padding    |  4 bytes
 +------------+  offset 32

Flock fl and fl2 are not initialized after definition.
The padding bytes in the structure may contain random values,
which could cause memcmp() to return a non-zero value,
potentially leading to test failure. The output is as follows:

 # [INFO] opened fds 3 4
 # [SUCCESS] set OFD read lock on first fd
 # [SUCCESS] read and write locks conflicted
 # [SUCCESS] F_UNLCK test returns: locked, type 0 pid -1 len 3
 # [FAIL] F_UNLCK test returns: locked, type 0 pid -1 len 3

Initialize them to zero to solve this problem.

Signed-off-by: Zhou Yuhang <zhouyuhang@...inos.cn>
---
changes in v2:
	- Add a description of the struct flock layout to the commit message.
---
 tools/testing/selftests/filelock/ofdlocks.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/tools/testing/selftests/filelock/ofdlocks.c b/tools/testing/selftests/filelock/ofdlocks.c
index a55b79810ab2..84e25505bebb 100644
--- a/tools/testing/selftests/filelock/ofdlocks.c
+++ b/tools/testing/selftests/filelock/ofdlocks.c
@@ -36,6 +36,8 @@ int main(void)
 {
 	int rc;
 	struct flock fl, fl2;
+	memset(&fl, 0, sizeof(fl));
+	memset(&fl2, 0, sizeof(fl2));
 	int fd = open("/tmp/aa", O_RDWR | O_CREAT | O_EXCL, 0600);
 	int fd2 = open("/tmp/aa", O_RDONLY);
 
-- 
2.33.0


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ