afs: fix a dereference on pointer cell before cell is null checked
Subsystems (2)
PATCH 1/1 afs: fix a dereference on pointer cell before cell is null checked
From: Colin Ian King <[email protected]>
Currently the assignment of debug_id dereferences pointer cell before cell has been null checked. Fix this by removing debug_id and use cell->debug_id after cell has been null checked.
Addresses-Coverity: ("Dereference before null check")
--- fs/afs/cell.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
fs/afs/cell.c +1 -2
@@ -589,7 +589,6 @@ struct afs_cell *afs_use_cell(struct afs_cell *cell, enum afs_cell_trace reason)*/ void afs_unuse_cell (struct afs_net *net,struct afs_cell *cell,enum afs_cell_trace reason) { -unsigned int debug_id = cell->debug_id;time64_t now, expire_delay;int u, a;
@@ -606,7 +605,7 @@ void afs_unuse_cell(struct afs_net *net, struct afs_cell *cell, enum afs_cell_tr u =atomic_read (&cell->ref); a =atomic_dec_return (&cell->active); -trace_afs_cell (debug_id, u, a, reason); +trace_afs_cell (cell->debug_id, u, a, reason);WARN_ON (a =0 );if (a =1 )/* 'cell' may now be garbage collected. */
Signature · 1 line
2.27.0
David Howells
maintainerfs/afs/cell.c void afs_unuse_cell(struct afs_net *net, struct afs_cell *cell, enum afs_cell_tr · line 608
Quoted 6 lines · Colin King
fs/afs/cell.c +1
-1@@ -606,7 +605,7 @@ void afs_unuse_cell(struct afs_net *net, struct afs_cell *cell, enum afs_cell_tr u =atomic_read (&cell->ref); a =atomic_dec_return (&cell->active); -trace_afs_cell (debug_id, u, a, reason); +trace_afs_cell (cell->debug_id, u, a, reason);
It's probably better to read cell->debug_id before calling atomic_dec_return().
I have a patch for this based on a report by Dan Carpenter, so no need to send a revised patch.
Thanks,
David
Quoted 12 lines · David Howells
fs/afs/cell.c void afs_unuse_cell(struct afs_net *net, struct afs_cell *cell, enum afs_cell_tr · line 608
Quoted 6 lines · Colin King
fs/afs/cell.c +1
-1@@ -606,7 +605,7 @@ void afs_unuse_cell(struct afs_net *net, struct afs_cell *cell, enum afs_cell_tr u =atomic_read (&cell->ref); a =atomic_dec_return (&cell->active); -trace_afs_cell (debug_id, u, a, reason); +trace_afs_cell (cell->debug_id, u, a, reason);It's probably better to read
cell->debug_idbefore callingatomic_dec_return().
Quoted 2 lines
I have a patch for this based on a report by Dan Carpenter, so no need to send a revised patch.
OK - thanks David
Quoted 4 lines
Thanks,
David