integer wrap in ntfs load_attribute_list_mount() can cause buffer overflow
In this code in fs/ntfs/inode.c load_attribute_list_mount():
rl_byte_off = ntfs_cluster_to_bytes(vol, lcn);
rl_byte_len = ntfs_cluster_to_bytes(vol, rl->length);
if (al + rl_byte_len > al_end)
rl_byte_len = al_end - al;
err = ntfs_bdev_read(sb->s_bdev, al, rl_byte_off,
round_up(rl_byte_len, SECTOR_SIZE));rl->length is read from the NTFS disk image. If it is large enough, then "al + ll_byte_len" will wrap around to a small value, and the "if" statement won't prevent ntfs_bdev_read() from reading more data than there is space in al.
Robert Morris
[email protected]
Quoted 11 lines · 在 2026/9/20 04:22, [email protected] 写道:
In this code in
fs/ntfs/inode.cload_attribute_list_mount():rl_byte_off = ntfs_cluster_to_bytes(vol, lcn); rl_byte_len = ntfs_cluster_to_bytes(vol, rl->length); if (al + rl_byte_len > al_end) rl_byte_len = al_end - al; err = ntfs_bdev_read(sb->s_bdev, al, rl_byte_off, round_up(rl_byte_len, SECTOR_SIZE));
Quoted 7 lines
rl->lengthis read from the NTFS disk image. If it is large enough, then "al +ll_byte_len" will wrap around to a small value, and the "if" statement won't preventntfs_bdev_read()from reading more data than there is space in al.Robert Morris
[email protected]
Hi Robert,
Thanks for reporting this. You're right: the pointer addition can
wrap around and bypass the bounds check.
I think we could fix this by comparing the run length against the
remaining buffer space, like this:
- if (al + rl_byte_len > al_end) + if (rl_byte_len > al_end - al) rl_byte_len = al_end - al;
Does this approach look reasonable to you?
If so, would you be interested in submitting a patch? If you don't
have time, I can arrange for an engineer on our team to submit it and credit you with a Reported-by tag.
I look forward to hearing your thoughts and discussing this further.
Thanks,
Baolin.
Baolin,
rl_byte_len is signed, so I worry that if it's possible for a corrupt image to cause the high bit to be set, it would not be > al_end - al. ntfs_bdev_read()'s size argument is unsigned, so it might then try to read a huge size.
Robert
Quoted 36 lines · 在 2026/9/20 04:22, [email protected] 写道:
Quoted 7 lines
In this code in
fs/ntfs/inode.cload_attribute_list_mount():rl_byte_off = ntfs_cluster_to_bytes(vol, lcn); rl_byte_len = ntfs_cluster_to_bytes(vol, rl->length); if (al + rl_byte_len > al_end) rl_byte_len = al_end - al; err = ntfs_bdev_read(sb->s_bdev, al, rl_byte_off, round_up(rl_byte_len, SECTOR_SIZE));Quoted 6 lines
rl->lengthis read from the NTFS disk image. If it is large enough, then "al +ll_byte_len" will wrap around to a small value, and the "if" statement won't preventntfs_bdev_read()from reading more data than there is space in al.
Robert Morris
[email protected]Hi Robert,
Thanks for reporting this. You're right: the pointer addition can wrap around and bypass the bounds check.I think we could fix this by comparing the run length against the remaining buffer space, like this:
- if (al + rl_byte_len > al_end) + if (rl_byte_len > al_end - al) rl_byte_len = al_end - al;Does this approach look reasonable to you?
If so, would you be interested in submitting a patch? If you don't have time, I can arrange for an engineer on our team to submit it and credit you with a Reported-by tag.I look forward to hearing your thoughts and discussing this further.
Thanks,
Baolin.
Quoted 8 lines · 在 2026/9/20 19:57, [email protected] 写道:
Baolin,
rl_byte_lenis signed, so I worry that if it's possible for a corrupt image to cause the high bit to be set, it would not be >al_end- al. ntfs_bdev_read()'s size argument is unsigned, so it might then try to read a huge size.Robert
Hi Robert,
Regarding your concern that rl_byte_len could become negative and
then be converted to a huge unsigned read size, I reviewed the latest ntfs-next tree I pulled, at commit 018344e6f555 ("ntfs: fix directory lookup on large-page systems"). My understanding is that the existing checks prevent rl_byte_len from becoming negative on this path,for the following reasons.
1. The run length in clusters cannot be negative.
Before calling load_attribute_list_mount(), ntfs_read_inode_mount() calls ntfs_mapping_pairs_decompress() and aborts if it fails. The decompressor rejects a negative decoded run length:
if (unlikely(deltaxcn < 0)) {
...
goto err_out;
}
rl[rlpos].length = deltaxcn;2. The run length in clusters also has an upper bound. For a data run with a non-negative LCN, the decompressor checks both addition overflow and whether the run extends beyond the volume boundary (logging omitted):
if (lcn >= 0) {
s64 run_end;
if (check_add_overflow(lcn, rl[rlpos].length,
&run_end))
goto err_out;
if (run_end > (s64)vol->nr_clusters)
goto err_out;
}This ensures that:
rl->length <= vol->nr_clusters - lcn
Boot-sector parsing also rejects a volume with 2^32 or more clusters:
ll = le64_to_cpu(b->number_of_sectors) >>
sectors_per_cluster_bits;
if (ll >= 1ULL << 32) {
...
return false;
}
vol->nr_clusters = ll; Therefore, the data run length must be less than 2^32 clusters. Sparse or unmapped runs cannot bypass this constraint to reach the byte-length calculation, because load_attribute_list_mount() rejects a negative LCN before that calculation.
3. Converting this bounded cluster count to bytes cannot make rl_byte_len negative.
The conversion helper takes and returns u64:
static inline u64 ntfs_cluster_to_bytes(
const struct ntfs_volume *vol, u64 clusters)
{
return clusters << vol->cluster_size_bits;
}Its result is assigned to a signed 64-bit variable:
loff_t rl_byte_len;
rl_byte_len = ntfs_cluster_to_bytes(vol, rl->length); The shift converts the cluster count to bytes. For example, with
4096-byte clusters, cluster_size_bits is 12, so shifting left by 12 multiplies the cluster count by 4096.
The relevant question is whether this multiplication can produce a
value too large for the signed rl_byte_len.
The boot-sector checks and decoding allow at most 4096 bytes per
sector and 4096 sectors per cluster. Thus, cluster_size_bits cannot exceed 24. Combined with the cluster-count bound above:
clusters < 2^32
cluster_size_bits <= 24the byte length satisfies:
clusters << cluster_size_bits < 2^32 * 2^24 = 2^56
This is below 2^63, so it fits in the non-negative range of a signed
64-bit integer. In terms of bit positions, the cluster count can use at most bit 31; shifting it left by at most 24 positions can use at most bit 55. It cannot reach the sign bit, bit 63.
Consequently, rl_byte_len cannot be negative on this path in the
ntfs-next revision discussed above.
Please let me know if I have missed a path around this validation.
Thanks,
Baolin.
Quoted 37 lines
Quoted 37 lines · 在 2026/9/20 04:22, [email protected] 写道:
Quoted 7 lines
In this code in
fs/ntfs/inode.cload_attribute_list_mount():rl_byte_off = ntfs_cluster_to_bytes(vol, lcn); rl_byte_len = ntfs_cluster_to_bytes(vol, rl->length); if (al + rl_byte_len > al_end) rl_byte_len = al_end - al; err = ntfs_bdev_read(sb->s_bdev, al, rl_byte_off, round_up(rl_byte_len, SECTOR_SIZE));Quoted 6 lines
rl->lengthis read from the NTFS disk image. If it is large enough, then "al +ll_byte_len" will wrap around to a small value, and the "if" statement won't preventntfs_bdev_read()from reading more data than there is space in al.
Robert Morris
[email protected]Hi Robert,
Thanks for reporting this. You're right: the pointer addition can wrap around and bypass the bounds check.I think we could fix this by comparing the run length against the remaining buffer space, like this:
- if (al + rl_byte_len > al_end) + if (rl_byte_len > al_end - al) rl_byte_len = al_end - al;Does this approach look reasonable to you?
If so, would you be interested in submitting a patch? If you don't have time, I can arrange for an engineer on our team to submit it and credit you with a Reported-by tag.I look forward to hearing your thoughts and discussing this further.
Thanks,
Baolin.
Baolin,
I am convinced! I withdraw my objection.
Robert
Quoted 169 lines
Date: Mon, 21 Sep 2026 11:03:21 +0800
Subject: Re: integer wrap in ntfsload_attribute_list_mount()can cause buffer
overflow
To: [email protected]
Cc: Namjae Jeon <[email protected]>, Hyunchul Lee <[email protected]>,
[email protected]
From: liubaolin <[email protected]>
X-CM-TRANSID: PygvCgBHgUp5nrBqwZMoAg--.6659S2
X-Coremail-Antispam: 1Uf129KBjvJXoWxCFy5Ww1DKr4UXFWfAFyDGFg_yoWrtw4rpFWDKa43tr4ftr1qy3yayFs5XFyagrWxGw15t34UJry7uanxKFn3WFsrKa90va4kuwn7Jr1q qa1jg343uF98ZFJanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07UjFAXUUUUU=X-CM-SenderInfo: xolxutxrol0iasrtmqqrwthudrp/xtbC6huMV2qwnnvLTwAA3R
Quoted 6 lines · 在 2026/9/20 19:57, [email protected] 写道:
Baolin,
rl_byte_lenis signed, so I worry that if it's possible for a corrupt image to cause the high bit to be set, it would not be >al_end- al. ntfs_bdev_read()'s size argument is unsigned, so it might then try to read a huge size. RobertHi Robert,
Regarding your concern thatrl_byte_lencould become negative and then be converted to a huge unsigned read size, I reviewed the latest ntfs-next tree I pulled, at commit018344e6f555("ntfs: fix directory lookup on large-page systems"). My understanding is that the existing checks preventrl_byte_lenfrom becoming negative on this path,for the following reasons.1. The run length in clusters cannot be negative.
Before callingload_attribute_list_mount(),ntfs_read_inode_mount()callsntfs_mapping_pairs_decompress()and aborts if it fails. The decompressor rejects a negative decoded run length:if (unlikely(deltaxcn < 0)) { ... goto err_out; } rl[rlpos].length = deltaxcn;2. The run length in clusters also has an upper bound. For a data run with a non-negative LCN, the decompressor checks both addition overflow and whether the run extends beyond the volume boundary (logging omitted):
if (lcn >= 0) { s64 run_end; if (check_add_overflow(lcn, rl[rlpos].length, &run_end)) goto err_out; if (run_end > (s64)vol->nr_clusters) goto err_out; }This ensures that:
rl->length <= vol->nr_clusters - lcnBoot-sector parsing also rejects a volume with 2^32 or more clusters:
ll = le64_to_cpu(b->number_of_sectors) >> sectors_per_cluster_bits; if (ll >= 1ULL << 32) { ... return false; } vol->nr_clusters = ll;Therefore, the data run length must be less than 2^32 clusters. Sparse or unmapped runs cannot bypass this constraint to reach the byte-length calculation, because
load_attribute_list_mount()rejects a negative LCN before that calculation.3. Converting this bounded cluster count to bytes cannot make
rl_byte_lennegative.
The conversion helper takes and returns u64:static inline u64 ntfs_cluster_to_bytes( const struct ntfs_volume *vol, u64 clusters) { return clusters << vol->cluster_size_bits; }Its result is assigned to a signed 64-bit variable:
loff_t rl_byte_len; rl_byte_len = ntfs_cluster_to_bytes(vol, rl->length);The shift converts the cluster count to bytes. For example, with 4096-byte clusters,
cluster_size_bitsis 12, so shifting left by 12 multiplies the cluster count by 4096.The relevant question is whether this multiplication can produce a value too large for the signed
rl_byte_len.The boot-sector checks and decoding allow at most 4096 bytes per sector and 4096 sectors per cluster. Thus,
cluster_size_bitscannot exceed 24. Combined with the cluster-count bound above:clusters < 2^32 cluster_size_bits <= 24the byte length satisfies:
clusters << cluster_size_bits < 2^32 * 2^24 = 2^56This is below 2^63, so it fits in the non-negative range of a signed 64-bit integer. In terms of bit positions, the cluster count can use at most bit 31; shifting it left by at most 24 positions can use at most bit 55. It cannot reach the sign bit, bit 63.
Consequently,
rl_byte_lencannot be negative on this path in the ntfs-next revision discussed above.
Please let me know if I have missed a path around this validation.Thanks,
Baolin.Quoted 37 lines
Quoted 37 lines · 在 2026/9/20 04:22, [email protected] 写道:
Quoted 7 lines
In this code in
fs/ntfs/inode.cload_attribute_list_mount():rl_byte_off = ntfs_cluster_to_bytes(vol, lcn); rl_byte_len = ntfs_cluster_to_bytes(vol, rl->length); if (al + rl_byte_len > al_end) rl_byte_len = al_end - al; err = ntfs_bdev_read(sb->s_bdev, al, rl_byte_off, round_up(rl_byte_len, SECTOR_SIZE));Quoted 6 lines
rl->lengthis read from the NTFS disk image. If it is large enough, then "al +ll_byte_len" will wrap around to a small value, and the "if" statement won't preventntfs_bdev_read()from reading more data than there is space in al.
Robert Morris
[email protected]Hi Robert,
Thanks for reporting this. You're right: the pointer addition can wrap around and bypass the bounds check.I think we could fix this by comparing the run length against the remaining buffer space, like this:
- if (al + rl_byte_len > al_end) + if (rl_byte_len > al_end - al) rl_byte_len = al_end - al;Does this approach look reasonable to you?
If so, would you be interested in submitting a patch? If you don't have time, I can arrange for an engineer on our team to submit it and credit you with a Reported-by tag.I look forward to hearing your thoughts and discussing this further.
Thanks,
Baolin.