From: Sasha Levin <sashal@kernel.org>
To: patches@lists.linux.dev, stable@vger.kernel.org
Cc: Rong Zhang <ulin0208@gmail.com>,
Konstantin Komarov <almaz.alexandrovich@paragon-software.com>,
Sasha Levin <sashal@kernel.org>,
ntfs3@lists.linux.dev
Subject: [PATCH AUTOSEL 6.6 18/23] fs/ntfs3: correctly create symlink for relative path
Date: Sun, 3 Aug 2025 17:20:25 -0400 [thread overview]
Message-ID: <20250803212031.3547641-18-sashal@kernel.org> (raw)
In-Reply-To: <20250803212031.3547641-1-sashal@kernel.org>
From: Rong Zhang <ulin0208@gmail.com>
[ Upstream commit b1e9d89408f402858c00103f9831b25ffa0994d3 ]
After applying this patch, could correctly create symlink:
ln -s "relative/path/to/file" symlink
Signed-off-by: Rong Zhang <ulin0208@gmail.com>
[almaz.alexandrovich@paragon-software.com: added cpu_to_le32 macro to
rs->Flags assignment]
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
LLM Generated explanations, may be completely bogus:
**Backport Status: YES**
This commit should be backported to stable kernel trees for the
following reasons:
1. **Bug Fix for User-Facing Functionality**: The commit fixes a
specific bug where creating relative symlinks in NTFS3 filesystems
would fail. The commit message clearly states it fixes the ability to
run `ln -s "relative/path/to/file" symlink`, which is a basic
filesystem operation that users expect to work correctly.
2. **Small and Contained Change**: The fix is relatively small and well-
contained within the NTFS3 symlink creation code. The changes are
limited to:
- Adding an `is_absolute` parameter to `ntfs_reparse_bytes()`
function
- Modifying buffer size calculations based on whether the path is
absolute or relative
- Setting the `SYMLINK_FLAG_RELATIVE` flag correctly in `rs->Flags`
- Conditionally adding the Windows path decoration (`\??\`) only for
absolute paths
3. **Clear Root Cause**: The original code always treated symlinks as
absolute paths by:
- Always setting `rs->Flags = 0` (line 1125 in original), which means
absolute path
- Always adding 4 extra characters for the `\??\` prefix in buffer
calculations
- Always decorating paths with `\??\` prefix regardless of path type
4. **Minimal Risk of Regression**: The changes are straightforward:
- The fix correctly identifies absolute paths by checking if the
second character is ':' (Windows drive letter format)
- It properly sets `SYMLINK_FLAG_RELATIVE` (value 1) for relative
paths using `cpu_to_le32()` for endianness
- Buffer calculations and path decorations are adjusted accordingly
5. **No Architectural Changes**: This is purely a bug fix that corrects
the handling of relative symlinks. It doesn't introduce new features
or change any fundamental behavior of the filesystem.
6. **Important for Interoperability**: NTFS3 is used for compatibility
with Windows filesystems. Having broken relative symlink support
impacts users who need to share filesystems between Linux and
Windows, making this an important functionality fix.
The commit follows stable kernel rules by being a clear bug fix with
minimal changes and low risk of introducing new issues. The fact that
the maintainer added the proper endianness conversion (`cpu_to_le32`)
shows careful attention to correctness.
fs/ntfs3/inode.c | 31 ++++++++++++++++++-------------
1 file changed, 18 insertions(+), 13 deletions(-)
diff --git a/fs/ntfs3/inode.c b/fs/ntfs3/inode.c
index af7c0cbba74e..0150a2210209 100644
--- a/fs/ntfs3/inode.c
+++ b/fs/ntfs3/inode.c
@@ -1130,10 +1130,10 @@ int inode_write_data(struct inode *inode, const void *data, size_t bytes)
* Number of bytes for REPARSE_DATA_BUFFER(IO_REPARSE_TAG_SYMLINK)
* for unicode string of @uni_len length.
*/
-static inline u32 ntfs_reparse_bytes(u32 uni_len)
+static inline u32 ntfs_reparse_bytes(u32 uni_len, bool is_absolute)
{
/* Header + unicode string + decorated unicode string. */
- return sizeof(short) * (2 * uni_len + 4) +
+ return sizeof(short) * (2 * uni_len + (is_absolute ? 4 : 0)) +
offsetof(struct REPARSE_DATA_BUFFER,
SymbolicLinkReparseBuffer.PathBuffer);
}
@@ -1146,8 +1146,11 @@ ntfs_create_reparse_buffer(struct ntfs_sb_info *sbi, const char *symname,
struct REPARSE_DATA_BUFFER *rp;
__le16 *rp_name;
typeof(rp->SymbolicLinkReparseBuffer) *rs;
+ bool is_absolute;
- rp = kzalloc(ntfs_reparse_bytes(2 * size + 2), GFP_NOFS);
+ is_absolute = (strlen(symname) > 1 && symname[1] == ':');
+
+ rp = kzalloc(ntfs_reparse_bytes(2 * size + 2, is_absolute), GFP_NOFS);
if (!rp)
return ERR_PTR(-ENOMEM);
@@ -1162,7 +1165,7 @@ ntfs_create_reparse_buffer(struct ntfs_sb_info *sbi, const char *symname,
goto out;
/* err = the length of unicode name of symlink. */
- *nsize = ntfs_reparse_bytes(err);
+ *nsize = ntfs_reparse_bytes(err, is_absolute);
if (*nsize > sbi->reparse.max_size) {
err = -EFBIG;
@@ -1182,7 +1185,7 @@ ntfs_create_reparse_buffer(struct ntfs_sb_info *sbi, const char *symname,
/* PrintName + SubstituteName. */
rs->SubstituteNameOffset = cpu_to_le16(sizeof(short) * err);
- rs->SubstituteNameLength = cpu_to_le16(sizeof(short) * err + 8);
+ rs->SubstituteNameLength = cpu_to_le16(sizeof(short) * err + (is_absolute ? 8 : 0));
rs->PrintNameLength = rs->SubstituteNameOffset;
/*
@@ -1190,16 +1193,18 @@ ntfs_create_reparse_buffer(struct ntfs_sb_info *sbi, const char *symname,
* parse this path.
* 0-absolute path 1- relative path (SYMLINK_FLAG_RELATIVE).
*/
- rs->Flags = 0;
+ rs->Flags = cpu_to_le32(is_absolute ? 0 : SYMLINK_FLAG_RELATIVE);
- memmove(rp_name + err + 4, rp_name, sizeof(short) * err);
+ memmove(rp_name + err + (is_absolute ? 4 : 0), rp_name, sizeof(short) * err);
- /* Decorate SubstituteName. */
- rp_name += err;
- rp_name[0] = cpu_to_le16('\\');
- rp_name[1] = cpu_to_le16('?');
- rp_name[2] = cpu_to_le16('?');
- rp_name[3] = cpu_to_le16('\\');
+ if (is_absolute) {
+ /* Decorate SubstituteName. */
+ rp_name += err;
+ rp_name[0] = cpu_to_le16('\\');
+ rp_name[1] = cpu_to_le16('?');
+ rp_name[2] = cpu_to_le16('?');
+ rp_name[3] = cpu_to_le16('\\');
+ }
return rp;
out:
--
2.39.5
next prev parent reply other threads:[~2025-08-03 21:21 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-03 21:20 [PATCH AUTOSEL 6.6 01/23] hfs: fix general protection fault in hfs_find_init() Sasha Levin
2025-08-03 21:20 ` [PATCH AUTOSEL 6.6 02/23] hfs: fix slab-out-of-bounds in hfs_bnode_read() Sasha Levin
2025-08-03 21:20 ` [PATCH AUTOSEL 6.6 03/23] hfsplus: fix slab-out-of-bounds in hfsplus_bnode_read() Sasha Levin
2025-08-03 21:20 ` [PATCH AUTOSEL 6.6 04/23] hfsplus: fix slab-out-of-bounds read in hfsplus_uni2asc() Sasha Levin
2025-08-03 21:20 ` [PATCH AUTOSEL 6.6 05/23] hfsplus: don't use BUG_ON() in hfsplus_create_attributes_file() Sasha Levin
2025-08-03 21:20 ` [PATCH AUTOSEL 6.6 06/23] arm64: Handle KCOV __init vs inline mismatches Sasha Levin
2025-08-03 21:20 ` [PATCH AUTOSEL 6.6 07/23] smb/server: avoid deadlock when linking with ReplaceIfExists Sasha Levin
2025-08-03 21:20 ` [PATCH AUTOSEL 6.6 08/23] nvme-pci: try function level reset on init failure Sasha Levin
2025-08-03 21:20 ` [PATCH AUTOSEL 6.6 09/23] gfs2: Set .migrate_folio in gfs2_{rgrp,meta}_aops Sasha Levin
2025-08-03 21:20 ` [PATCH AUTOSEL 6.6 10/23] md: call del_gendisk in control path Sasha Levin
2025-08-03 21:20 ` [PATCH AUTOSEL 6.6 11/23] loop: Avoid updating block size under exclusive owner Sasha Levin
2025-08-03 21:20 ` [PATCH AUTOSEL 6.6 12/23] udf: Verify partition map count Sasha Levin
2025-08-03 21:20 ` [PATCH AUTOSEL 6.6 13/23] drbd: add missing kref_get in handle_write_conflicts Sasha Levin
2025-08-03 21:20 ` [PATCH AUTOSEL 6.6 14/23] hfs: fix not erasing deleted b-tree node issue Sasha Levin
2025-08-03 21:20 ` [PATCH AUTOSEL 6.6 15/23] better lockdep annotations for simple_recursive_removal() Sasha Levin
2025-08-03 21:20 ` [PATCH AUTOSEL 6.6 16/23] ata: libata-sata: Disallow changing LPM state if not supported Sasha Levin
2025-08-03 21:20 ` [PATCH AUTOSEL 6.6 17/23] fs/ntfs3: Add sanity check for file name Sasha Levin
2025-08-03 21:20 ` Sasha Levin [this message]
2025-08-03 21:20 ` [PATCH AUTOSEL 6.6 19/23] md: Don't clear MD_CLOSING until mddev is freed Sasha Levin
2025-08-03 21:20 ` [PATCH AUTOSEL 6.6 20/23] ext2: Handle fiemap on empty files to prevent EINVAL Sasha Levin
2025-08-03 21:20 ` [PATCH AUTOSEL 6.6 21/23] fix locking in efi_secret_unlink() Sasha Levin
2025-08-03 21:20 ` [PATCH AUTOSEL 6.6 22/23] securityfs: don't pin dentries twice, once is enough Sasha Levin
2025-08-03 21:20 ` [PATCH AUTOSEL 6.6 23/23] tracefs: Add d_delete to remove negative dentries 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=20250803212031.3547641-18-sashal@kernel.org \
--to=sashal@kernel.org \
--cc=almaz.alexandrovich@paragon-software.com \
--cc=ntfs3@lists.linux.dev \
--cc=patches@lists.linux.dev \
--cc=stable@vger.kernel.org \
--cc=ulin0208@gmail.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