diff options
| author | DaeMyung Kang <charsyam@gmail.com> | 2026-05-30 17:35:10 +0300 |
|---|---|---|
| committer | Namjae Jeon <linkinjeon@kernel.org> | 2026-06-05 18:20:33 +0300 |
| commit | 40d88020d0797f96a93edd2e8edc413c2e2d8f84 (patch) | |
| tree | da7e13c808668f03d71e70945cfbf2ff0dd5bd13 | |
| parent | d5803e3345dae9c6470bb61869885236276b9a35 (diff) | |
| download | linux-40d88020d0797f96a93edd2e8edc413c2e2d8f84.tar.xz | |
ntfs: do not replace volume name after lookup errors
ntfs_write_volume_label() removes an existing $VOLUME_NAME attribute and
then adds the replacement. The old code only distinguished lookup success
from all other results, so any lookup error was treated like an absent
label and the add path still ran.
That is unsafe once lookup-time validation rejects corrupt $VOLUME_NAME
records with -EIO: the corrupt record would remain in place and a second
$VOLUME_NAME record could be appended next to it.
Only add the replacement after the old label was removed successfully or
after lookup returned -ENOENT. Propagate all other lookup errors, and
also stop if removing the old attribute fails.
Cc: stable@vger.kernel.org # v7.1
Signed-off-by: DaeMyung Kang <charsyam@gmail.com>
Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
| -rw-r--r-- | fs/ntfs/super.c | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/fs/ntfs/super.c b/fs/ntfs/super.c index 34d0040b385a..081a29583868 100644 --- a/fs/ntfs/super.c +++ b/fs/ntfs/super.c @@ -444,10 +444,15 @@ int ntfs_write_volume_label(struct ntfs_volume *vol, char *label) goto out; } - if (!ntfs_attr_lookup(AT_VOLUME_NAME, NULL, 0, 0, 0, NULL, 0, - ctx)) - ntfs_attr_record_rm(ctx); + ret = ntfs_attr_lookup(AT_VOLUME_NAME, NULL, 0, 0, 0, NULL, 0, + ctx); + if (!ret) + ret = ntfs_attr_record_rm(ctx); + else if (ret == -ENOENT) + ret = 0; ntfs_attr_put_search_ctx(ctx); + if (ret) + goto out; ret = ntfs_resident_attr_record_add(vol_ni, AT_VOLUME_NAME, AT_UNNAMED, 0, (u8 *)uname, uname_len * sizeof(__le16), 0); |
