mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: "Pali Rohár" <pali@kernel.org>,
	"Steve French" <stfrench@microsoft.com>,
	"Sasha Levin" <sashal@kernel.org>,
	sfrench@samba.org, linux-cifs@vger.kernel.org,
	samba-technical@lists.samba.org
Subject: [PATCH AUTOSEL 6.11 13/20] cifs: Fix creating native symlinks pointing to current or parent directory
Date: Sun, 13 Oct 2024 23:57:15 -0400	[thread overview]
Message-ID: <20241014035731.2246632-13-sashal@kernel.org> (raw)
In-Reply-To: <20241014035731.2246632-1-sashal@kernel.org>

From: Pali Rohár <pali@kernel.org>

[ Upstream commit 63271b7d569fbe924bccc7dadc17d3d07a4e5f7a ]

Calling 'ln -s . symlink' or 'ln -s .. symlink' creates symlink pointing to
some object name which ends with U+F029 unicode codepoint. This is because
trailing dot in the object name is replaced by non-ASCII unicode codepoint.

So Linux SMB client currently is not able to create native symlink pointing
to current or parent directory on Windows SMB server which can be read by
either on local Windows server or by any other SMB client which does not
implement compatible-reverse character replacement.

Fix this problem in cifsConvertToUTF16() function which is doing that
character replacement. Function comment already says that it does not need
to handle special cases '.' and '..', but after introduction of native
symlinks in reparse point form, this handling is needed.

Note that this change depends on the previous change
"cifs: Improve creating native symlinks pointing to directory".

Signed-off-by: Pali Rohár <pali@kernel.org>
Signed-off-by: Steve French <stfrench@microsoft.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 fs/smb/client/cifs_unicode.c | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/fs/smb/client/cifs_unicode.c b/fs/smb/client/cifs_unicode.c
index 79d99a9139441..4cc6e0896fad3 100644
--- a/fs/smb/client/cifs_unicode.c
+++ b/fs/smb/client/cifs_unicode.c
@@ -484,10 +484,21 @@ cifsConvertToUTF16(__le16 *target, const char *source, int srclen,
 			/**
 			 * Remap spaces and periods found at the end of every
 			 * component of the path. The special cases of '.' and
-			 * '..' do not need to be dealt with explicitly because
-			 * they are addressed in namei.c:link_path_walk().
+			 * '..' are need to be handled because of symlinks.
+			 * They are treated as non-end-of-string to avoid
+			 * remapping and breaking symlinks pointing to . or ..
 			 **/
-			if ((i == srclen - 1) || (source[i+1] == '\\'))
+			if ((i == 0 || source[i-1] == '\\') &&
+			    source[i] == '.' &&
+			    (i == srclen-1 || source[i+1] == '\\'))
+				end_of_string = false; /* "." case */
+			else if (i >= 1 &&
+				 (i == 1 || source[i-2] == '\\') &&
+				 source[i-1] == '.' &&
+				 source[i] == '.' &&
+				 (i == srclen-1 || source[i+1] == '\\'))
+				end_of_string = false; /* ".." case */
+			else if ((i == srclen - 1) || (source[i+1] == '\\'))
 				end_of_string = true;
 			else
 				end_of_string = false;
-- 
2.43.0


  parent reply	other threads:[~2024-10-14  3:57 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-14  3:57 [PATCH AUTOSEL 6.11 01/20] ntfs3: Add bounds checking to mi_enum_attr() Sasha Levin
2024-10-14  3:57 ` [PATCH AUTOSEL 6.11 02/20] fs/ntfs3: Check if more than chunk-size bytes are written Sasha Levin
2024-10-14  3:57 ` [PATCH AUTOSEL 6.11 03/20] fs/ntfs3: Fix warning possible deadlock in ntfs_set_state Sasha Levin
2024-10-14  3:57 ` [PATCH AUTOSEL 6.11 04/20] fs/ntfs3: Stale inode instead of bad Sasha Levin
2024-10-14  3:57 ` [PATCH AUTOSEL 6.11 05/20] fs/ntfs3: Add rough attr alloc_size check Sasha Levin
2024-10-14  3:57 ` [PATCH AUTOSEL 6.11 06/20] fs/ntfs3: Fix possible deadlock in mi_read Sasha Levin
2024-10-14  3:57 ` [PATCH AUTOSEL 6.11 07/20] fs/ntfs3: Additional check in ni_clear() Sasha Levin
2024-10-14  3:57 ` [PATCH AUTOSEL 6.11 08/20] fs/ntfs3: Fix general protection fault in run_is_mapped_full Sasha Levin
2024-10-14  3:57 ` [PATCH AUTOSEL 6.11 09/20] fs/ntfs3: Additional check in ntfs_file_release Sasha Levin
2024-10-14  3:57 ` [PATCH AUTOSEL 6.11 10/20] rust: device: change the from_raw() function Sasha Levin
2024-10-14  3:57 ` [PATCH AUTOSEL 6.11 11/20] scsi: scsi_transport_fc: Allow setting rport state to current state Sasha Levin
2024-10-14  3:57 ` [PATCH AUTOSEL 6.11 12/20] cifs: Improve creating native symlinks pointing to directory Sasha Levin
2024-10-14  3:57 ` Sasha Levin [this message]
2024-10-14  3:57 ` [PATCH AUTOSEL 6.11 14/20] ACPI: resource: Fold Asus Vivobook Pro N6506M* DMI quirks together Sasha Levin
2024-10-14  3:57 ` [PATCH AUTOSEL 6.11 15/20] powercap: intel_rapl_msr: Add PL4 support for Arrowlake-U Sasha Levin
2024-10-14  3:57 ` [PATCH AUTOSEL 6.11 16/20] thermal: intel: int340x: processor: Remove MMIO RAPL CPU hotplug support Sasha Levin
2024-10-14  3:57 ` [PATCH AUTOSEL 6.11 17/20] thermal: intel: int340x: processor: Add MMIO RAPL PL4 support Sasha Levin
2024-10-14  3:57 ` [PATCH AUTOSEL 6.11 18/20] net: amd: mvme147: Fix probe banner message Sasha Levin
2024-10-14  3:57 ` [PATCH AUTOSEL 6.11 19/20] NFS: remove revoked delegation from server's delegation list Sasha Levin
2024-10-14  3:57 ` [PATCH AUTOSEL 6.11 20/20] misc: sgi-gru: Don't disable preemption in GRU driver Sasha Levin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20241014035731.2246632-13-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=linux-cifs@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pali@kernel.org \
    --cc=samba-technical@lists.samba.org \
    --cc=sfrench@samba.org \
    --cc=stable@vger.kernel.org \
    --cc=stfrench@microsoft.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®