Skip to content

Commit 6136bbb

Browse files
neosys007gregkh
authored andcommitted
fs/ntfs3: terminate the cached volume label after UTF-8 conversion
[ Upstream commit a6cd43f ] ntfs_fill_super() loads the on-disk volume label with utf16s_to_utf8s() and stores the result in sbi->volume.label. The converted label is later exposed through ntfs3_label_show() using %s, but utf16s_to_utf8s() only returns the number of bytes written and does not add a trailing NUL. If the converted label fills the entire fixed buffer, ntfs3_label_show() can read past the end of sbi->volume.label while looking for a terminator. Terminate the cached label explicitly after a successful conversion and clamp the exact-full case to the last byte of the buffer. Fixes: 82cae26 ("fs/ntfs3: Add initialization of super block") Signed-off-by: Pengpeng Hou <pengpeng@iscas.ac.cn> Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent c44ad02 commit 6136bbb

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

fs/ntfs3/super.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1277,8 +1277,13 @@ static int ntfs_fill_super(struct super_block *sb, struct fs_context *fc)
12771277
le32_to_cpu(attr->res.data_size) >> 1,
12781278
UTF16_LITTLE_ENDIAN, sbi->volume.label,
12791279
sizeof(sbi->volume.label));
1280-
if (err < 0)
1280+
if (err < 0) {
12811281
sbi->volume.label[0] = 0;
1282+
} else if (err >= sizeof(sbi->volume.label)) {
1283+
sbi->volume.label[sizeof(sbi->volume.label) - 1] = 0;
1284+
} else {
1285+
sbi->volume.label[err] = 0;
1286+
}
12821287
} else {
12831288
/* Should we break mounting here? */
12841289
//err = -EINVAL;

0 commit comments

Comments
 (0)