From patchwork Sun Sep 29 18:50:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Pali_Roh=C3=A1r?= X-Patchwork-Id: 1990641 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=lrlzMV1j; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=147.75.199.223; helo=ny.mirrors.kernel.org; envelope-from=linux-cifs+bounces-2971-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org [147.75.199.223]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XGtZj6SCZz1xt9 for ; Mon, 30 Sep 2024 04:51:09 +1000 (AEST) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 1328C1C20A29 for ; Sun, 29 Sep 2024 18:51:08 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 685404D8BC; Sun, 29 Sep 2024 18:51:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="lrlzMV1j" X-Original-To: linux-cifs@vger.kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3FEC72C1A2; Sun, 29 Sep 2024 18:51:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727635864; cv=none; b=onGYeNlYQDoQDxO4LUEl+p1kkWUuFv53UQXuJW0E6zqaH8QioKf9DdZqDpYnJlJMgHyvMhUAc8ypuH+/+ZyD4GT7ff3r4ZaGwUJL6l2TKiR6iLYFAnU9LVwSFqwG2jjrTS0pcdXnzlLBgXSm+B/d0ZyxXPp9wmwoeP/3ZpbLuqA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727635864; c=relaxed/simple; bh=Sgx5ATycMHh6UDLNYypmUE89xviImR+y+zjObqc7AmM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=bp74dYCiN9xfJ2Ob6Pj1cKIjv+k0wcr5TR8iChajSpDZExCYjNXwH5nC0mJKSzajv63pVs3d0AvfhQbu9drZdwMzSfkR4BValUk9SSaeQ+PazYylxFcs9GX+y1MGMlc+JBXlRMnoLU48ZDWhLpo1/NL/YkGQ8xG1xAK3vYsWBFI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=lrlzMV1j; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id B81C6C4CEC7; Sun, 29 Sep 2024 18:51:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727635863; bh=Sgx5ATycMHh6UDLNYypmUE89xviImR+y+zjObqc7AmM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lrlzMV1jfHCrGOhketOZnVgaRScBje/HypPk4qyjgUWtoWSQtFE0KSUebmWGI4hyQ iYIymUc6hnIpTr4Llc74ZhC+yuN21B/ABpLrtdLC/4+SfiPayBiyB56Br98B1aJH9y xl4ViaOmVYW0NUK/+wyroo4zYuaCB+rljr21lXIlQYstkSUdh+j8bnV277ExTWsd/Q E2AiKVcpSoiLI4yu7NLrTjUOEHABHTfZJjWsENH/zdmc8iXcRWO6XLE72j2k9cdDCN BA8LEUVTsyEWgUp7YIjPODhMP6uKeYYpSx/jIorZjVpRs/Q9mlzGKR63ap+h+9KODW 4lTXSP3HQDn/Q== Received: by pali.im (Postfix) id 52E10B9A; Sun, 29 Sep 2024 20:50:57 +0200 (CEST) From: =?utf-8?q?Pali_Roh=C3=A1r?= To: Steve French , Paulo Alcantara , Ronnie Sahlberg Cc: linux-cifs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/7] cifs: Fix creating native symlinks pointing to current or parent directory Date: Sun, 29 Sep 2024 20:50:49 +0200 Message-Id: <20240929185053.10554-4-pali@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20240929185053.10554-1-pali@kernel.org> References: <20240929185053.10554-1-pali@kernel.org> Precedence: bulk X-Mailing-List: linux-cifs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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. Signed-off-by: Pali Rohár --- 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 79d99a913944..4cc6e0896fad 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;