* [bug report] fs/ntfs3: inconsistent NULL checks in mi_read()
@ 2021-08-25 7:44 Dan Carpenter
0 siblings, 0 replies; only message in thread
From: Dan Carpenter @ 2021-08-25 7:44 UTC (permalink / raw)
To: almaz.alexandrovich; +Cc: ntfs3
Hello Konstantin Komarov,
The patch 4342306f0f0d: "fs/ntfs3: Add file operations and
implementation" from Aug 13, 2021, leads to the following
Smatch static checker warning:
fs/ntfs3/record.c:158 mi_read()
warn: potential NULL parameter dereference 'mft_ni'
fs/ntfs3/record.c
122 int mi_read(struct mft_inode *mi, bool is_mft)
123 {
124 int err;
125 struct MFT_REC *rec = mi->mrec;
126 struct ntfs_sb_info *sbi = mi->sbi;
127 u32 bpr = sbi->record_size;
128 u64 vbo = (u64)mi->rno << sbi->record_bits;
129 struct ntfs_inode *mft_ni = sbi->mft.ni;
130 struct runs_tree *run = mft_ni ? &mft_ni->file.run : NULL;
^^^^^^
Can mft_ni be NULL?
131 struct rw_semaphore *rw_lock = NULL;
132
133 if (is_mounted(sbi)) {
134 if (!is_mft) {
135 rw_lock = &mft_ni->file.run_lock;
136 down_read(rw_lock);
137 }
138 }
139
140 err = ntfs_read_bh(sbi, run, vbo, &rec->rhdr, bpr, &mi->nb);
141 if (rw_lock)
142 up_read(rw_lock);
143 if (!err)
144 goto ok;
145
146 if (err == -E_NTFS_FIXUP) {
147 mi->dirty = true;
148 goto ok;
149 }
150
151 if (err != -ENOENT)
152 goto out;
153
154 if (rw_lock) {
155 ni_lock(mft_ni);
156 down_write(rw_lock);
157 }
--> 158 err = attr_load_runs_vcn(mft_ni, ATTR_DATA, NULL, 0, &mft_ni->file.run,
^^^^^^
Unchecked dereference inside the function.
159 vbo >> sbi->cluster_bits);
160 if (rw_lock) {
161 up_write(rw_lock);
162 ni_unlock(mft_ni);
163 }
164 if (err)
165 goto out;
166
167 if (rw_lock)
168 down_read(rw_lock);
169 err = ntfs_read_bh(sbi, run, vbo, &rec->rhdr, bpr, &mi->nb);
170 if (rw_lock)
171 up_read(rw_lock);
172
173 if (err == -E_NTFS_FIXUP) {
174 mi->dirty = true;
175 goto ok;
176 }
177 if (err)
178 goto out;
179
180 ok:
181 /* check field 'total' only here */
182 if (le32_to_cpu(rec->total) != bpr) {
183 err = -EINVAL;
184 goto out;
185 }
186
187 return 0;
188
189 out:
190 return err;
191 }
regards,
dan carpenter
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2021-08-25 7:44 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-25 7:44 [bug report] fs/ntfs3: inconsistent NULL checks in mi_read() Dan Carpenter
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).