Skip to content

Commit 97498cd

Browse files
Jia-Ju Baiaalexandrovich
authored andcommitted
fs: ntfs3: Fix possible null-pointer dereferences in mi_read()
In a previous commit 2681631 ("fs/ntfs3: Add null pointer check to attr_load_runs_vcn"), ni can be NULL in attr_load_runs_vcn(), and thus it should be checked before being used. However, in the call stack of this commit, mft_ni in mi_read() is aliased with ni in attr_load_runs_vcn(), and it is also used in mi_read() at two places: mi_read() rw_lock = &mft_ni->file.run_lock -> No check attr_load_runs_vcn(mft_ni, ...) ni (namely mft_ni) is checked in the previous commit attr_load_runs_vcn(..., &mft_ni->file.run) -> No check Thus, to avoid possible null-pointer dereferences, the related checks should be added. These bugs are reported by a static analysis tool implemented by myself, and they are found by extending a known bug fixed in the previous commit. Thus, they could be theoretical bugs. Signed-off-by: Jia-Ju Bai <[email protected]> Signed-off-by: Konstantin Komarov <[email protected]>
1 parent c9db0ff commit 97498cd

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

fs/ntfs3/record.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ int mi_read(struct mft_inode *mi, bool is_mft)
124124
struct rw_semaphore *rw_lock = NULL;
125125

126126
if (is_mounted(sbi)) {
127-
if (!is_mft) {
127+
if (!is_mft && mft_ni) {
128128
rw_lock = &mft_ni->file.run_lock;
129129
down_read(rw_lock);
130130
}
@@ -148,7 +148,7 @@ int mi_read(struct mft_inode *mi, bool is_mft)
148148
ni_lock(mft_ni);
149149
down_write(rw_lock);
150150
}
151-
err = attr_load_runs_vcn(mft_ni, ATTR_DATA, NULL, 0, &mft_ni->file.run,
151+
err = attr_load_runs_vcn(mft_ni, ATTR_DATA, NULL, 0, run,
152152
vbo >> sbi->cluster_bits);
153153
if (rw_lock) {
154154
up_write(rw_lock);

0 commit comments

Comments
 (0)