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>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20250831123602.14037-19-pali@kernel.org>
Date: Sun, 31 Aug 2025 14:35:45 +0200
From: Pali Rohár <pali@...nel.org>
To: Steve French <sfrench@...ba.org>,
	Paulo Alcantara <pc@...guebit.com>,
	ronnie sahlberg <ronniesahlberg@...il.com>
Cc: linux-cifs@...r.kernel.org,
	linux-kernel@...r.kernel.org
Subject: [PATCH 18/35] cifs: Do not set NumberOfLinks to 1 from open or query calls

Current code already interprets zero value as unknown number of links and
sets the CIFS_FATTR_UNKNOWN_NLINK flag to handle this situation.

Setting NumberOfLinks to 1 prevents the CIFS_FATTR_UNKNOWN_NLINK indicator.
So set the NumberOfLinks to 0 when it is unknown.

Signed-off-by: Pali Rohár <pali@...nel.org>
---
 fs/smb/client/cifssmb.c   | 4 ++--
 fs/smb/client/smb1ops.c   | 2 +-
 fs/smb/client/smb2inode.c | 6 ++++--
 fs/smb/client/smb2pdu.c   | 2 +-
 4 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/fs/smb/client/cifssmb.c b/fs/smb/client/cifssmb.c
index 2427752bc224..2a83fbc65395 100644
--- a/fs/smb/client/cifssmb.c
+++ b/fs/smb/client/cifssmb.c
@@ -1163,7 +1163,7 @@ SMBLegacyOpen(const unsigned int xid, struct cifs_tcon *tcon,
 			pfile_info->AllocationSize =
 				cpu_to_le64(le32_to_cpu(pSMBr->EndOfFile));
 			pfile_info->EndOfFile = pfile_info->AllocationSize;
-			pfile_info->NumberOfLinks = cpu_to_le32(1);
+			pfile_info->NumberOfLinks = cpu_to_le32(0); /* CIFS_FATTR_UNKNOWN_NLINK */
 			pfile_info->DeletePending = 0; /* successful open = not delete pending */
 		}
 	}
@@ -1288,7 +1288,7 @@ CIFS_open(const unsigned int xid, struct cifs_open_parms *oparms, int *oplock,
 		/* the file_info buf is endian converted by caller */
 		buf->AllocationSize = rsp->AllocationSize;
 		buf->EndOfFile = rsp->EndOfFile;
-		buf->NumberOfLinks = cpu_to_le32(1);
+		buf->NumberOfLinks = cpu_to_le32(0); /* trigger CIFS_FATTR_UNKNOWN_NLINK */
 		buf->DeletePending = 0; /* successful open = not delete pending */
 	}
 
diff --git a/fs/smb/client/smb1ops.c b/fs/smb/client/smb1ops.c
index 618470db6444..6e928e90d72b 100644
--- a/fs/smb/client/smb1ops.c
+++ b/fs/smb/client/smb1ops.c
@@ -627,7 +627,7 @@ static int cifs_query_path_info(const unsigned int xid,
 				fi.EndOfFile = di->EndOfFile;
 				fi.EASize = di->EaSize;
 			}
-			fi.NumberOfLinks = cpu_to_le32(1);
+			fi.NumberOfLinks = cpu_to_le32(0); /* trigger CIFS_FATTR_UNKNOWN_NLINK */
 			/*
 			 * Do not change fi.DeletePending as it is set by the above
 			 * CIFSSMBQPathInfo() call even on error. By default it is
diff --git a/fs/smb/client/smb2inode.c b/fs/smb/client/smb2inode.c
index 6c9da150a402..c8b0e9b2438f 100644
--- a/fs/smb/client/smb2inode.c
+++ b/fs/smb/client/smb2inode.c
@@ -696,8 +696,10 @@ static int smb2_compound_op(const unsigned int xid, struct cifs_tcon *tcon,
 		idata->fi.Attributes = create_rsp->FileAttributes;
 		idata->fi.AllocationSize = create_rsp->AllocationSize;
 		idata->fi.EndOfFile = create_rsp->EndofFile;
-		if (le32_to_cpu(idata->fi.NumberOfLinks) == 0)
-			idata->fi.NumberOfLinks = cpu_to_le32(1); /* dummy value */
+		/*
+		 * Do not change idata->fi.NumberOfLinks to correctly
+		 * trigger the CIFS_FATTR_UNKNOWN_NLINK flag.
+		 */
 		idata->fi.DeletePending = 0; /* successful open = not delete pending */
 		idata->fi.Directory = !!(le32_to_cpu(create_rsp->FileAttributes) & ATTR_DIRECTORY);
 
diff --git a/fs/smb/client/smb2pdu.c b/fs/smb/client/smb2pdu.c
index 58800490142e..bf588ec99618 100644
--- a/fs/smb/client/smb2pdu.c
+++ b/fs/smb/client/smb2pdu.c
@@ -3276,7 +3276,7 @@ SMB2_open(const unsigned int xid, struct cifs_open_parms *oparms, __le16 *path,
 		buf->AllocationSize = rsp->AllocationSize;
 		buf->EndOfFile = rsp->EndofFile;
 		buf->Attributes = rsp->FileAttributes;
-		buf->NumberOfLinks = cpu_to_le32(1);
+		buf->NumberOfLinks = cpu_to_le32(0); /* trigger CIFS_FATTR_UNKNOWN_NLINK */
 		buf->DeletePending = 0; /* successful open = not delete pending */
 	}
 
-- 
2.20.1


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ